diff --git a/changelogs/fragments/11296-keycloak-clientscope-change-problem.yml b/changelogs/fragments/11296-keycloak-clientscope-change-problem.yml new file mode 100644 index 0000000000..5f99d2e5c5 --- /dev/null +++ b/changelogs/fragments/11296-keycloak-clientscope-change-problem.yml @@ -0,0 +1,5 @@ +--- +bugfixes: +- keycloak_clientscope - fixed ``normalise_cr()`` to properly convert string ``"true"`` / ``"false"`` values to Python booleans. + Before boolean-like strings caused Ansible to always report ``changed=true`` even when the configuration had not actually changed + (https://github.com/ansible-collections/community.general/pull/11296). \ No newline at end of file diff --git a/plugins/modules/keycloak_clientscope.py b/plugins/modules/keycloak_clientscope.py index 585c9fc81c..433df6314b 100644 --- a/plugins/modules/keycloak_clientscope.py +++ b/plugins/modules/keycloak_clientscope.py @@ -300,6 +300,22 @@ from ansible_collections.community.general.plugins.module_utils.identity.keycloa ) +def normalise_boolean(obj): + """ + Recursive fonction to traverse the obj and unify the boolean values. + """ + if isinstance(obj, dict): + return {k: normalise_boolean(v) for k, v in obj.items()} + elif isinstance(obj, list): + return [normalise_boolean(v) for v in obj] + elif isinstance(obj, str): + if obj.lower() == "true": + return True + elif obj.lower() == "false": + return False + return obj + + def normalise_cr(clientscoperep, remove_ids=False): """Re-sorts any properties where the order so that diff's is minimised, and adds default values where appropriate so that the the change detection is more effective. @@ -320,6 +336,9 @@ def normalise_cr(clientscoperep, remove_ids=False): if remove_ids: mapper.pop("id", None) + for key, value in mapper.items(): + mapper[key] = normalise_boolean(value) + # Set to a default value. mapper["consentRequired"] = mapper.get("consentRequired", False)