- name: validate input fail: msg: package must be a list or a string when: (package is not defined) or (package is mapping) or (package is not iterable) and (package is not string) - block: - name: determine distribution setup: gather_subset: - min - name: fail if distribution is not yet defined fail: msg: distribution is not yet defined, using fallback when: ansible_distribution is not defined rescue: - name: set fallback distribution set_fact: ansible_distribution: 'Alpine' ansible_system: "{{ 'Win32NT' if (is_windows | d(false) == true) else 'Linux' }}" when: ansible_distribution is not defined - name: loop over packages include_tasks: tasks/includes/package.yml loop: "{%- if package is string -%}{{ [ package ] }}\ {%- else -%}{{ package }}\ {%- endif -%}" loop_control: loop_var: package_inner - name: undefine temporary facts set_fact: this_package: "{{ None }}" when: this_package | d(None) != None