From 428674cb90ead171f4cd352225d8ba089bb4afcc Mon Sep 17 00:00:00 2001 From: Adam Young Date: Fri, 10 Oct 2014 21:26:17 -0400 Subject: [PATCH] Inventory Plugin to get hostgroups from FreeIPA --- plugins/inventory/freeipa.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 plugins/inventory/freeipa.py diff --git a/plugins/inventory/freeipa.py b/plugins/inventory/freeipa.py new file mode 100755 index 0000000000..ae4ad59fd2 --- /dev/null +++ b/plugins/inventory/freeipa.py @@ -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 +