diff options
author | Ryan Groten <rgroten@gmail.com> | 2016-11-18 06:41:38 -0700 |
---|---|---|
committer | René Moser <mail@renemoser.net> | 2016-11-18 14:41:38 +0100 |
commit | f12d5b01c70a50762c501799d5c6bff20ff90f46 (patch) | |
tree | e23bb55a4db9dc319f2e12c873389bc9ee7620be | |
parent | f6437f1b6e61358606a8c1e19f850e3b96e37481 (diff) | |
download | ansible-f12d5b01c70a50762c501799d5c6bff20ff90f46.tar.gz |
FreeIPA: Add support for nested hostgroups in FreeIPA (#14695)
-rwxr-xr-x | contrib/inventory/freeipa.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/contrib/inventory/freeipa.py b/contrib/inventory/freeipa.py index a2632621ca..377326c710 100755 --- a/contrib/inventory/freeipa.py +++ b/contrib/inventory/freeipa.py @@ -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']]} - - for host in hostgroup['member_host']: - hostvars[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 member in members: + hostvars[member] = {} inventory['_meta'] = {'hostvars': hostvars} inv_string = json.dumps(inventory, indent=1, sort_keys=True) |