keycloak_client: fix idempotency regression (#9976)

* add function to normalize kc responses

* add changelog fragment

* Update changelogs/fragments/9976-keycloak_client-fix-idempotency-regression.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* add newline to changelog fragment

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
gruenbauer@b1-systems.de 2025-04-14 22:35:50 +02:00 committed by GitHub
parent ab6e18b6cf
commit 0413774641
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- keycloak_client - fix the idempotency regression by normalizing the Keycloak response for ``after_client`` (https://github.com/ansible-collections/community.general/issues/9905, https://github.com/ansible-collections/community.general/pull/9976).

View file

@ -775,6 +775,13 @@ def normalise_cr(clientrep, remove_ids=False):
return clientrep return clientrep
def normalize_kc_resp(clientrep):
# kc drops the variable 'authorizationServicesEnabled' if set to false
# to minimize diff/changes we set it to false if not set by kc
if clientrep and 'authorizationServicesEnabled' not in clientrep:
clientrep['authorizationServicesEnabled'] = False
def sanitize_cr(clientrep): def sanitize_cr(clientrep):
""" Removes probably sensitive details from a client representation. """ Removes probably sensitive details from a client representation.
@ -966,10 +973,7 @@ def main():
else: else:
before_client = kc.get_client_by_id(cid, realm=realm) before_client = kc.get_client_by_id(cid, realm=realm)
# kc drops the variable 'authorizationServicesEnabled' if set to false normalize_kc_resp(before_client)
# to minimize diff/changes we set it to false if not set by kc
if before_client and 'authorizationServicesEnabled' not in before_client:
before_client['authorizationServicesEnabled'] = False
if before_client is None: if before_client is None:
before_client = {} before_client = {}
@ -1050,6 +1054,8 @@ def main():
kc.update_client(cid, desired_client, realm=realm) kc.update_client(cid, desired_client, realm=realm)
after_client = kc.get_client_by_id(cid, realm=realm) after_client = kc.get_client_by_id(cid, realm=realm)
normalize_kc_resp(after_client)
if before_client == after_client: if before_client == after_client:
result['changed'] = False result['changed'] = False
if module._diff: if module._diff: