From 214039a73374ff736484862d42bf35e9c1e9f5d8 Mon Sep 17 00:00:00 2001 From: Jan Sobczak Date: Thu, 4 Aug 2022 20:55:33 +0200 Subject: [PATCH] Add append option to ipa_hostgroup module Signed-off-by: Jan Sobczak --- plugins/modules/ipa_hostgroup.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/modules/ipa_hostgroup.py b/plugins/modules/ipa_hostgroup.py index dcada0380c5..c9b7c224d2f 100644 --- a/plugins/modules/ipa_hostgroup.py +++ b/plugins/modules/ipa_hostgroup.py @@ -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. + default: no + type: bool cn: description: - Name of host-group. @@ -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']) @@ -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: @@ -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']), + append=dict(type='bool', default=False)) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)