From 731169d45253afa87719a92796147f464994cec2 Mon Sep 17 00:00:00 2001 From: Stefan Krempel Date: Tue, 3 Nov 2026 21:02:25 +0100 Subject: [PATCH] keycloak_organization: keep unmanaged domain fields when comparing Keycloak 26.8 added an autoRedirect field to the organization domain representation. The module compared its own {name, verified} domain list with the server's {autoRedirect, name, verified} list, so on 26.8 it reported changed on every run, re-sent the organization each time and reset an autoRedirect value set outside the module. Overlay the requested domain settings on the domains returned by the server before comparing. Fields the module does not manage are now kept as they are, both for the comparison and for the update request. Behaviour against Keycloak 26.7 and earlier is unchanged. --- plugins/modules/keycloak_organization.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/modules/keycloak_organization.py b/plugins/modules/keycloak_organization.py index 067d9e1..2ceb3c9 100644 --- a/plugins/modules/keycloak_organization.py +++ b/plugins/modules/keycloak_organization.py @@ -249,6 +249,21 @@ def normalise_org(org): return org +def merge_domains(desired_domains, current_domains): + """Overlay the requested domain settings on the existing domain representations. + Keys the module does not manage (for example autoRedirect, added in Keycloak 26.8) + are kept as returned by the server, so they neither break the comparison nor get + reset on update. + """ + current_by_name = {d.get("name"): d for d in current_domains or []} + merged = [] + for domain in desired_domains: + merged_domain = dict(current_by_name.get(domain["name"], {})) + merged_domain.update(domain) + merged.append(merged_domain) + return sorted(merged, key=lambda d: d.get("name", "")) + + def main(): argument_spec = keycloak_argument_spec() @@ -334,6 +349,8 @@ def main(): ) continue old_value = before_org.get(camel(param)) + if param == "domains": + new_param_value = merge_domains(new_param_value, old_value) if new_param_value != old_value: changeset[camel(param)] = new_param_value