- name: Dump hosts to json file command: cmd: ansible-inventory -i hosts.txt --list --output hosts.json delegate_to: localhost - name: Json file to variable include_vars: file: hosts.json name: hosts - debug: msg: "{{ item }}/path/file.txt" loop: "{{ hosts.queue_servers.children }}"