From 1389bba4596d8dc062b7b058907d3bd294c85040 Mon Sep 17 00:00:00 2001 From: Michiel Dethmers Date: Thu, 21 Dec 2023 12:09:12 +0000 Subject: [PATCH] keycloak_user: avoid error when trying to delete a non-existing user (#7696) * avoid error when trying to delete a non-existing user when force is set, but the user doesn't exist yet, this fails. * 7696-avoid-attempt-to-delete-non-existing-user add changelog entry * rename changelog file * Update changelogs/fragments/7696-avoid-attempt-to-delete-non-existing-user.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- .../7696-avoid-attempt-to-delete-non-existing-user.yml | 2 ++ plugins/modules/keycloak_user.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/7696-avoid-attempt-to-delete-non-existing-user.yml diff --git a/changelogs/fragments/7696-avoid-attempt-to-delete-non-existing-user.yml b/changelogs/fragments/7696-avoid-attempt-to-delete-non-existing-user.yml new file mode 100644 index 0000000000..db57d68233 --- /dev/null +++ b/changelogs/fragments/7696-avoid-attempt-to-delete-non-existing-user.yml @@ -0,0 +1,2 @@ +bugfixes: + - keycloak_user - when ``force`` is set, but user does not exist, do not try to delete it (https://github.com/ansible-collections/community.general/pull/7696). diff --git a/plugins/modules/keycloak_user.py b/plugins/modules/keycloak_user.py index 61be26e5e2..1aeff0da5f 100644 --- a/plugins/modules/keycloak_user.py +++ b/plugins/modules/keycloak_user.py @@ -481,7 +481,7 @@ def main(): else: after_user = {} - if force: # If the force option is set to true + if force and before_user: # If the force option is set to true # Delete the existing user kc.delete_user(user_id=before_user["id"], realm=realm)