FreeIPA: Add support for nested hostgroups in FreeIPA (#14695)
This commit is contained in:
parent
f6437f1b6e
commit
f12d5b01c7
1 changed files with 10 additions and 4 deletions
|
@ -23,7 +23,7 @@ def initialize():
|
|||
|
||||
def list_groups(api):
|
||||
'''
|
||||
This function returns a list of all host groups. This function requires
|
||||
This function prints a list of all host groups. This function requires
|
||||
one argument, the FreeIPA/IPA API object.
|
||||
'''
|
||||
|
||||
|
@ -34,10 +34,16 @@ def list_groups(api):
|
|||
result = api.Command.hostgroup_find()['result']
|
||||
|
||||
for hostgroup in result:
|
||||
inventory[hostgroup['cn'][0]] = { 'hosts': [host for host in hostgroup['member_host']]}
|
||||
# Get direct and indirect members (nested hostgroups) of hostgroup
|
||||
members = []
|
||||
if 'member_host' in hostgroup:
|
||||
members = [host for host in hostgroup['member_host']]
|
||||
if 'memberindirect_host' in hostgroup:
|
||||
members += (host for host in hostgroup['memberindirect_host'])
|
||||
inventory[hostgroup['cn'][0]] = {'hosts': [host for host in members]}
|
||||
|
||||
for host in hostgroup['member_host']:
|
||||
hostvars[host] = {}
|
||||
for member in members:
|
||||
hostvars[member] = {}
|
||||
|
||||
inventory['_meta'] = {'hostvars': hostvars}
|
||||
inv_string = json.dumps(inventory, indent=1, sort_keys=True)
|
||||
|
|
Loading…
Reference in a new issue