Skip to content

Commit

Permalink
Add append option to ipa_hostgroup module
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Sobczak <jan.sobczak@soit.com.pl>
  • Loading branch information
Jan Sobczak committed Mar 17, 2023
1 parent 4eb3540 commit 728930c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions plugins/modules/identity/ipa/ipa_hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
description:
- Add, modify and delete an IPA host-group using IPA API.
options:
append:
description:
- If C(yes), add the listed I(host) to the I(hostgroup).
- If C(no), only the listed I(host) will be in I(hostgroup), removing any other hosts.
default: no
type: bool
cn:
description:
- Name of host-group.
Expand Down Expand Up @@ -140,6 +146,7 @@ def ensure(module, client):
state = module.params['state']
host = module.params['host']
hostgroup = module.params['hostgroup']
append = module.params['append']

ipa_hostgroup = client.hostgroup_find(name=name)
module_hostgroup = get_hostgroup_dict(description=module.params['description'])
Expand All @@ -161,14 +168,18 @@ def ensure(module, client):
client.hostgroup_mod(name=name, item=data)

if host is not None:
changed = client.modify_if_diff(name, ipa_hostgroup.get('member_host', []), [item.lower() for item in host],
client.hostgroup_add_host, client.hostgroup_remove_host) or changed
changed = client.modify_if_diff(name, ipa_hostgroup.get('member_host', []),
[item.lower() for item in host],
client.hostgroup_add_host,
client.hostgroup_remove_host,
append=append) or changed

if hostgroup is not None:
changed = client.modify_if_diff(name, ipa_hostgroup.get('member_hostgroup', []),
[item.lower() for item in hostgroup],
client.hostgroup_add_hostgroup,
client.hostgroup_remove_hostgroup) or changed
client.hostgroup_remove_hostgroup,
append=append) or changed

else:
if ipa_hostgroup:
Expand All @@ -185,7 +196,9 @@ def main():
description=dict(type='str'),
host=dict(type='list', elements='str'),
hostgroup=dict(type='list', elements='str'),
state=dict(type='str', default='present', choices=['present', 'absent', 'enabled', 'disabled']))
state=dict(type='str', default='present',
choices=['present', 'absent', 'enabled', 'disabled']),
append=dict(type='bool', default=False))

module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
Expand Down

0 comments on commit 728930c

Please sign in to comment.