Last active
May 7, 2016 18:24
-
-
Save ccollicutt/5c087a3c7b9dca229c725d6e889117e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nova01 | |
keystone01 | |
mysql01 | |
neutron01 | |
nova-compute-ironic01 | |
nova-compute-kvm01 | |
glance01 | |
haproxy01 | |
horizon01 | |
rabbitmq01 | |
memcached01 | |
aptcache01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import os | |
import sys | |
import time | |
from pylxd import api | |
lxd = api.API() | |
inventory = {} | |
inventory['_meta'] = { 'hostvars': {} } | |
inventory['all'] = [] | |
for container in lxd.container_list(): | |
state = lxd.container_state(container)[1]['metadata'] | |
ip = state['network']['eth0']['addresses'][0]['address'] | |
inventory['all'].append(container) | |
# strip digits, eg. neutron01 becomes neutron | |
group = ''.join(i for i in container if not i.isdigit()) | |
try: | |
inventory[group].append(container) | |
except: | |
inventory[group] = [] | |
inventory[group].append(container) | |
inventory['_meta']['hostvars'][container] = {} | |
inventory['_meta']['hostvars'][container]['ansible_ssh_host'] = ip | |
print(json.dumps(inventory, indent=4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./inventory.py | |
{ | |
"haproxy": [ | |
"haproxy01" | |
], | |
"aptcache": [ | |
"aptcache01" | |
], | |
"all": [ | |
"aptcache01", | |
"glance01", | |
"glance02", | |
"haproxy01", | |
"horizon01", | |
"keystone01", | |
"memcached01", | |
"mysql01", | |
"neutron01", | |
"neutron02", | |
"nova-compute-ironic01", | |
"nova-compute-kvm01", | |
"nova01", | |
"rabbitmq01", | |
"t1" | |
], | |
"_meta": { | |
"hostvars": { | |
"mysql01": { | |
"ansible_ssh_host": "10.245.29.130" | |
}, | |
"nova-compute-kvm01": { | |
"ansible_ssh_host": "10.245.29.128" | |
}, | |
"memcached01": { | |
"ansible_ssh_host": "10.245.29.114" | |
}, | |
"neutron02": { | |
"ansible_ssh_host": "10.245.29.75" | |
}, | |
"haproxy01": { | |
"ansible_ssh_host": "10.245.29.46" | |
}, | |
"rabbitmq01": { | |
"ansible_ssh_host": "10.245.29.70" | |
}, | |
"nova01": { | |
"ansible_ssh_host": "10.245.29.126" | |
}, | |
"horizon01": { | |
"ansible_ssh_host": "10.245.29.152" | |
}, | |
"glance01": { | |
"ansible_ssh_host": "10.245.29.52" | |
}, | |
"glance02": { | |
"ansible_ssh_host": "10.245.29.23" | |
}, | |
"keystone01": { | |
"ansible_ssh_host": "10.245.29.166" | |
}, | |
"aptcache01": { | |
"ansible_ssh_host": "10.245.29.207" | |
}, | |
"neutron01": { | |
"ansible_ssh_host": "10.245.29.190" | |
}, | |
"t1": { | |
"ansible_ssh_host": "10.245.29.206" | |
}, | |
"nova-compute-ironic01": { | |
"ansible_ssh_host": "10.245.29.200" | |
} | |
} | |
}, | |
"nova": [ | |
"nova01" | |
], | |
"nova-compute-ironic": [ | |
"nova-compute-ironic01" | |
], | |
"keystone": [ | |
"keystone01" | |
], | |
"rabbitmq": [ | |
"rabbitmq01" | |
], | |
"horizon": [ | |
"horizon01" | |
], | |
"mysql": [ | |
"mysql01" | |
], | |
"glance": [ | |
"glance01", | |
"glance02" | |
], | |
"memcached": [ | |
"memcached01" | |
], | |
"nova-compute-kvm": [ | |
"nova-compute-kvm01" | |
], | |
"neutron": [ | |
"neutron01", | |
"neutron02" | |
], | |
"t": [ | |
"t1" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment