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