--- - name: Create Instances hosts: 127.0.0.1 connection: local gather_facts: false vars_files: - "../vars/main.yml" tasks: - include: ../tasks/create-security-groups.yml - include: ../tasks/create-instances.yml - include: ../tasks/create-volumes.yml - shell: "> hosts-prod" - shell: "echo '{ \"{{ item }}\": [{% for host in groups[item] %}{\"hostname\": \"{{ hostvars[host]['host_name'] }}\",\"addr\":\"{{ host }}\"}{% if not loop.last %},{% endif %}{% endfor %}] }' | ./utils/inventory.py prod" when: item not in ['all', 'ungrouped'] with_items: groups.keys()