--- - name: import a task hosts: containers gather_facts: false tasks: - debug: msg: "{{ item }}" loop: "{{ selected_containers | split(',') }}" when: inventory_hostname in groups['morefine-server'] - debug: msg: "{{ selected_host }}" when: inventory_hostname in groups['morefine-server']