diff --git a/changelogs/fragments/???-keycloak-clientscope-change-problem.yml b/changelogs/fragments/???-keycloak-clientscope-change-problem.yml new file mode 100644 index 0000000000..8d1feff08c --- /dev/null +++ b/changelogs/fragments/???-keycloak-clientscope-change-problem.yml @@ -0,0 +1,4 @@ +--- +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 hadn't actually changed. \ No newline at end of file diff --git a/plugins/modules/keycloak_clientscope.py b/plugins/modules/keycloak_clientscope.py index 61763886a9..b873f18f75 100644 --- a/plugins/modules/keycloak_clientscope.py +++ b/plugins/modules/keycloak_clientscope.py @@ -298,6 +298,21 @@ from ansible_collections.community.general.plugins.module_utils.identity.keycloa ) from ansible.module_utils.basic import AnsibleModule +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 @@ -319,6 +334,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)