Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add append option to ipa_hostgroup module #6203

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions plugins/modules/ipa_hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
diff_mode:
support: none
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.
jansobczak marked this conversation as resolved.
Show resolved Hide resolved
default: false
type: bool
jansobczak marked this conversation as resolved.
Show resolved Hide resolved
cn:
description:
- Name of host-group.
Expand Down Expand Up @@ -147,6 +153,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 @@ -168,14 +175,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 @@ -192,7 +203,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']),
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
append=dict(type='bool', default=False))

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