diff --git a/books/openstack_prod.yml b/books/openstack_prod.yml index a58be36..6ec95c7 100644 --- a/books/openstack_prod.yml +++ b/books/openstack_prod.yml @@ -1,13 +1,16 @@ --- - 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: echo "{{ groups }}" | ./utils/inventory.py prod + - 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() diff --git a/utils/inventory.py b/utils/inventory.py index 1ae273c..1fe69b2 100755 --- a/utils/inventory.py +++ b/utils/inventory.py @@ -1,19 +1,19 @@ #!/usr/bin/env python2 import json, sys FILE = 'hosts-%s' % sys.argv[1] JSON = json.loads(sys.stdin.read()) INVENTORY = '' groups = [i for i in JSON] for g in groups: INVENTORY += '[%s]\n' % g for h in JSON[g]: - INVENTORY += '%s host_name=%s private_ip=%s\n' % (h['addr'], h['hostname'], h['private_ip']) + INVENTORY += '%s host_name=%s\n' % (h['addr'], h['hostname']) INVENTORY += '\n' f = open(FILE, 'a') f.write(INVENTORY) f.close()