From 0bb7dfe344424e4e4ed99ea8d04d8980b3cd61b4 Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Sat, 16 Mar 2024 16:15:13 +0100 Subject: [PATCH 1/2] radosgw_user: parse system and admin as boolean The returned payload from rgw has them as a boolean. By having them as a string it would always report a change and try to modify the user. Signed-off-by: Seena Fallah --- library/radosgw_user.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/radosgw_user.py b/library/radosgw_user.py index 8e26bbb3bb..fddbf893b9 100644 --- a/library/radosgw_user.py +++ b/library/radosgw_user.py @@ -415,8 +415,8 @@ def run_module(): email = module.params.get('email') access_key = module.params.get('access_key') secret_key = module.params.get('secret_key') - system = str(module.params.get('system')).lower() - admin = str(module.params.get('admin')).lower() + system = module.params.get('system') + admin = module.params.get('admin') if module.check_mode: module.exit_json( @@ -441,8 +441,8 @@ def run_module(): user = json.loads(out) current = { 'display_name': user['display_name'], - 'system': user.get('system', 'false'), - 'admin': user.get('admin', 'false') + 'system': user.get('system', False), + 'admin': user.get('admin', False) } asked = { 'display_name': display_name, From 937d1f6380256d8ca9af8e395326a36d4edd80bc Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Sat, 16 Mar 2024 16:22:08 +0100 Subject: [PATCH 2/2] radosgw_user: add support check mode Signed-off-by: Seena Fallah --- library/radosgw_user.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/library/radosgw_user.py b/library/radosgw_user.py index fddbf893b9..2370a4ddd4 100644 --- a/library/radosgw_user.py +++ b/library/radosgw_user.py @@ -418,25 +418,14 @@ def run_module(): system = module.params.get('system') admin = module.params.get('admin') - 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_user(module, container_image=container_image)) # noqa: E501 if state == "present": - rc, cmd, out, err = exec_commands(module, get_user(module, container_image=container_image)) # noqa: E501 if rc == 0: user = json.loads(out) current = { @@ -452,32 +441,33 @@ def run_module(): if email: current['email'] = user['email'] asked['email'] = email - if access_key: - current['access_key'] = user['keys'][0]['access_key'] + + if access_key and secret_key: asked['access_key'] = access_key - if secret_key: - current['secret_key'] = user['keys'][0]['secret_key'] asked['secret_key'] = secret_key - - if current != asked: + for key in user['keys']: + if key['access_key'] == access_key and key['secret_key'] == secret_key: # noqa: E501 + del asked['access_key'] + del asked['secret_key'] + break + + changed = current != asked + if changed and not module.check_mode: rc, cmd, out, err = exec_commands(module, modify_user(module, container_image=container_image)) # noqa: E501 - changed = True else: - rc, cmd, out, err = exec_commands(module, create_user(module, container_image=container_image)) # noqa: E501 + if not module.check_mode: + rc, cmd, out, err = exec_commands(module, create_user(module, container_image=container_image)) # noqa: E501 changed = True elif state == "absent": - rc, cmd, out, err = exec_commands(module, get_user(module, container_image=container_image)) # noqa: E501 if rc == 0: - rc, cmd, out, err = exec_commands(module, remove_user(module, container_image=container_image)) # noqa: E501 + if not module.check_mode: + rc, cmd, out, err = exec_commands(module, remove_user(module, container_image=container_image)) # noqa: E501 changed = True else: rc = 0 out = "User {} doesn't exist".format(name) - elif state == "info": - rc, cmd, out, err = exec_commands(module, get_user(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