forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ansible#9312 from admiyo/freeipa
Inventory Plugin to get hostgroups from FreeIPA
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|