From 97ed64a38783f062c2dcd4f872ffbe4ad1bc7961 Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Sat, 16 Mar 2024 16:07:02 +0100 Subject: [PATCH 1/2] radosgw_zonegroup: parse master as boolean The returned payload from rgw has is_master as a boolean. By having master as a string it would always report a change and try to modify the zonegroup. Signed-off-by: Seena Fallah --- library/radosgw_zonegroup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/radosgw_zonegroup.py b/library/radosgw_zonegroup.py index 42075d45b6..dac9c17096 100644 --- a/library/radosgw_zonegroup.py +++ b/library/radosgw_zonegroup.py @@ -343,7 +343,7 @@ def run_module(): name = module.params.get('name') state = module.params.get('state') endpoints = module.params.get('endpoints') - master = str(module.params.get('master')).lower() + master = module.params.get('master') if module.check_mode: module.exit_json( @@ -372,7 +372,7 @@ def run_module(): realm = json.loads(_out) current = { 'endpoints': zonegroup['endpoints'], - 'master': zonegroup.get('is_master', 'false'), + 'master': zonegroup.get('is_master', False), 'realm_id': zonegroup['realm_id'] } asked = { From 63c123c9c2500ac86f107734b8d23ed8aa1df9fb Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Sat, 16 Mar 2024 16:08:17 +0100 Subject: [PATCH 2/2] radosgw_zonegroup: add support check mode Signed-off-by: Seena Fallah --- library/radosgw_zonegroup.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/library/radosgw_zonegroup.py b/library/radosgw_zonegroup.py index dac9c17096..533d58fa25 100644 --- a/library/radosgw_zonegroup.py +++ b/library/radosgw_zonegroup.py @@ -345,25 +345,14 @@ def run_module(): endpoints = module.params.get('endpoints') master = module.params.get('master') - if module.check_mode: - module.exit_json( - changed=False, - stdout='', - stderr='', - rc=0, - start='', - end='', - delta='', - ) - startd = datetime.datetime.now() changed = False # will return either the image name or None container_image = is_containerized() + rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501 if state == "present": - rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501 if rc == 0: zonegroup = json.loads(out) _rc, _cmd, _out, _err = exec_commands(module, get_realm(module, container_image=container_image)) # noqa: E501 @@ -380,25 +369,23 @@ def run_module(): 'master': master, 'realm_id': realm['id'] } - if current != asked: + changed = current != asked + if changed and not module.check_mode: rc, cmd, out, err = exec_commands(module, modify_zonegroup(module, container_image=container_image)) # noqa: E501 - changed = True else: - rc, cmd, out, err = exec_commands(module, create_zonegroup(module, container_image=container_image)) # noqa: E501 + if not module.check_mode: + rc, cmd, out, err = exec_commands(module, create_zonegroup(module, container_image=container_image)) # noqa: E501 changed = True elif state == "absent": - rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501 if rc == 0: - rc, cmd, out, err = exec_commands(module, remove_zonegroup(module, container_image=container_image)) # noqa: E501 + if not module.check_mode: + rc, cmd, out, err = exec_commands(module, remove_zonegroup(module, container_image=container_image)) # noqa: E501 changed = True else: rc = 0 out = "Zonegroup {} doesn't exist".format(name) - elif state == "info": - rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501 - exit_module(module=module, out=out, rc=rc, cmd=cmd, err=err, startd=startd, changed=changed) # noqa: E501