1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add append option to ipa_hostgroup module (#6203)

* Add append option to ipa_hostgroup module

Signed-off-by: Jan Sobczak <jan.sobczak@soit.com.pl>

* Update plugins/modules/ipa_hostgroup.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/ipa_hostgroup.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Add changelog fragment

Signed-off-by: Jan Sobczak <jan.sobczak@soit.com.pl>

* Move choices argument to previous line

Signed-off-by: Jan Sobczak <jan.sobczak@soit.com.pl>

* Update plugins/modules/ipa_hostgroup.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update changelogs/fragments/6203-add-append-option-to-ipa-hostgroup.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Signed-off-by: Jan Sobczak <jan.sobczak@soit.com.pl>
Co-authored-by: Jan Sobczak <jan.sobczak@soit.com.pl>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Jan Sobczak 2023-04-22 22:55:36 +02:00 committed by GitHub
parent 9b493d53a9
commit f4dd4d5ace
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -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).

View file

@ -20,6 +20,13 @@ attributes:
diff_mode: diff_mode:
support: none support: none
options: options:
append:
description:
- 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
version_added: 6.6.0
cn: cn:
description: description:
- Name of host-group. - Name of host-group.
@ -147,6 +154,7 @@ def ensure(module, client):
state = module.params['state'] state = module.params['state']
host = module.params['host'] host = module.params['host']
hostgroup = module.params['hostgroup'] hostgroup = module.params['hostgroup']
append = module.params['append']
ipa_hostgroup = client.hostgroup_find(name=name) ipa_hostgroup = client.hostgroup_find(name=name)
module_hostgroup = get_hostgroup_dict(description=module.params['description']) module_hostgroup = get_hostgroup_dict(description=module.params['description'])
@ -168,14 +176,18 @@ def ensure(module, client):
client.hostgroup_mod(name=name, item=data) client.hostgroup_mod(name=name, item=data)
if host is not None: if host is not None:
changed = client.modify_if_diff(name, ipa_hostgroup.get('member_host', []), [item.lower() for item in host], changed = client.modify_if_diff(name, ipa_hostgroup.get('member_host', []),
client.hostgroup_add_host, client.hostgroup_remove_host) or changed [item.lower() for item in host],
client.hostgroup_add_host,
client.hostgroup_remove_host,
append=append) or changed
if hostgroup is not None: if hostgroup is not None:
changed = client.modify_if_diff(name, ipa_hostgroup.get('member_hostgroup', []), changed = client.modify_if_diff(name, ipa_hostgroup.get('member_hostgroup', []),
[item.lower() for item in hostgroup], [item.lower() for item in hostgroup],
client.hostgroup_add_hostgroup, client.hostgroup_add_hostgroup,
client.hostgroup_remove_hostgroup) or changed client.hostgroup_remove_hostgroup,
append=append) or changed
else: else:
if ipa_hostgroup: if ipa_hostgroup:
@ -192,7 +204,8 @@ def main():
description=dict(type='str'), description=dict(type='str'),
host=dict(type='list', elements='str'), host=dict(type='list', elements='str'),
hostgroup=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, module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True) supports_check_mode=True)