From 214039a73374ff736484862d42bf35e9c1e9f5d8 Mon Sep 17 00:00:00 2001 From: Jan Sobczak Date: Thu, 4 Aug 2022 20:55:33 +0200 Subject: [PATCH 1/7] 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) From 3408b64c6bf3b77e6c213a6e9ba531d051eee2a5 Mon Sep 17 00:00:00 2001 From: Jan Sobczak <9196392+jansobczak@users.noreply.github.com> Date: Thu, 6 Apr 2023 09:08:34 +0200 Subject: [PATCH 2/7] Update plugins/modules/ipa_hostgroup.py Co-authored-by: Felix Fontein --- plugins/modules/ipa_hostgroup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ipa_hostgroup.py b/plugins/modules/ipa_hostgroup.py index c9b7c224d2f..9f565ed378c 100644 --- a/plugins/modules/ipa_hostgroup.py +++ b/plugins/modules/ipa_hostgroup.py @@ -24,7 +24,7 @@ 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 + default: false type: bool cn: description: From 852b150d79ec3f99e907c0f79b1cae57aed19f6c Mon Sep 17 00:00:00 2001 From: Jan Sobczak <9196392+jansobczak@users.noreply.github.com> Date: Thu, 20 Apr 2023 10:04:03 +0200 Subject: [PATCH 3/7] Update plugins/modules/ipa_hostgroup.py Co-authored-by: Felix Fontein --- plugins/modules/ipa_hostgroup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ipa_hostgroup.py b/plugins/modules/ipa_hostgroup.py index 9f565ed378c..386cdb12c82 100644 --- a/plugins/modules/ipa_hostgroup.py +++ b/plugins/modules/ipa_hostgroup.py @@ -22,8 +22,8 @@ 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. + - If C(true), add the listed I(host) to the I(hostgroup). + - If C(false), only the listed I(host) will be in I(hostgroup), removing any other hosts. default: false type: bool cn: From f3cd800c7cf4e325d78f22ac4a79dbf71c23f8ce Mon Sep 17 00:00:00 2001 From: Jan Sobczak Date: Thu, 20 Apr 2023 10:25:47 +0200 Subject: [PATCH 4/7] Add changelog fragment Signed-off-by: Jan Sobczak --- .../fragments/6203-add-append-option-to-ipa-hostgroup.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml diff --git a/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml b/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml new file mode 100644 index 00000000000..ed56e00c5e7 --- /dev/null +++ b/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml @@ -0,0 +1,2 @@ +minor_changes: + - ipa hostgroup - add ``append`` parameter for adding a new hosts to existing hostgroups without changing existing hostgroup members (https://github.com/ansible-collections/community.general/pull/6203). From b505982227693fd455ae677256024ec77e5dbd2a Mon Sep 17 00:00:00 2001 From: Jan Sobczak Date: Thu, 20 Apr 2023 10:30:33 +0200 Subject: [PATCH 5/7] Move choices argument to previous line Signed-off-by: Jan Sobczak --- plugins/modules/ipa_hostgroup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/ipa_hostgroup.py b/plugins/modules/ipa_hostgroup.py index 386cdb12c82..b8ecf77bc78 100644 --- a/plugins/modules/ipa_hostgroup.py +++ b/plugins/modules/ipa_hostgroup.py @@ -203,8 +203,7 @@ 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, From 5152d006129aa819f4b0d2a3b39dd7a82914b6e3 Mon Sep 17 00:00:00 2001 From: Jan Sobczak <9196392+jansobczak@users.noreply.github.com> Date: Thu, 20 Apr 2023 13:39:57 +0200 Subject: [PATCH 6/7] Update plugins/modules/ipa_hostgroup.py Co-authored-by: Felix Fontein --- plugins/modules/ipa_hostgroup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/ipa_hostgroup.py b/plugins/modules/ipa_hostgroup.py index b8ecf77bc78..12232de89cf 100644 --- a/plugins/modules/ipa_hostgroup.py +++ b/plugins/modules/ipa_hostgroup.py @@ -26,6 +26,7 @@ - If C(false), only the listed I(host) will be in I(hostgroup), removing any other hosts. default: false type: bool + version_added: 6.6.0 cn: description: - Name of host-group. From a783acdc34d4ff1683c2b33d3ed2d0102240c756 Mon Sep 17 00:00:00 2001 From: Jan Sobczak <9196392+jansobczak@users.noreply.github.com> Date: Thu, 20 Apr 2023 13:40:13 +0200 Subject: [PATCH 7/7] Update changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml Co-authored-by: Felix Fontein --- .../fragments/6203-add-append-option-to-ipa-hostgroup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml b/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml index ed56e00c5e7..1de6853efce 100644 --- a/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml +++ b/changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml @@ -1,2 +1,2 @@ minor_changes: - - ipa hostgroup - add ``append`` parameter for adding a new hosts to existing hostgroups without changing existing hostgroup members (https://github.com/ansible-collections/community.general/pull/6203). + - ipa_hostgroup - add ``append`` parameter for adding a new hosts to existing hostgroups without changing existing hostgroup members (https://github.com/ansible-collections/community.general/pull/6203).