2015-01-07 01:29:19 +01:00
|
|
|
#!/usr/bin/env python
|
2014-10-11 03:26:17 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|