Inventory Plugin to get hostgroups from FreeIPA

This commit is contained in:
Adam Young 2014-10-10 21:26:17 -04:00
parent fac414ea48
commit 428674cb90

19
plugins/inventory/freeipa.py Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/python
import json
from ipalib import api
api.bootstrap(context='cli')
api.finalize()
api.Backend.xmlclient.connect()
inventory = {}
hostvars={}
meta={}
result =api.Command.hostgroup_find()['result']
for hostgroup in result:
inventory[hostgroup['cn'][0]] = { 'hosts': [host for host in hostgroup['member_host']]}
for host in hostgroup['member_host']:
hostvars[host] = {}
inventory['_meta'] = {'hostvars': hostvars}
inv_string = json.dumps( inventory)
print inv_string