Skip to content

Commit 7c40c6b

Browse files
desand01Andre Desrosiersfelixfontein
authored
Keycloak role fix changed status (#10829)
* Exclude aliases before comparison * add test * fragment * Update changelogs/fragments/10829-fix-keycloak-role-changed-status.yml Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: Andre Desrosiers <[email protected]> Co-authored-by: Felix Fontein <[email protected]>
1 parent 2bf8ae8 commit 7c40c6b

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- keycloak_role - fixes an issue where the module incorrectly returns ``changed=true`` when using the alias ``clientId`` in composite roles (https://github.com/ansible-collections/community.general/pull/10829).

plugins/modules/keycloak_role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def main():
361361

362362
else:
363363
if state == 'present':
364-
compare_exclude = []
364+
compare_exclude = ['clientId']
365365
if 'composites' in desired_role and isinstance(desired_role['composites'], list) and len(desired_role['composites']) > 0:
366366
composites = kc.get_role_composites(rolerep=before_role, clientid=clientid, realm=realm)
367367
before_role['composites'] = []

tests/integration/targets/keycloak_role/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Source Ansible env-setup from ansible github repository
1313

1414
Run integration tests:
1515

16-
ansible-test integration keycloak_role --python 3.10 --allow-unsupported
16+
ansible-test integration -v keycloak_role --allow-unsupported --docker fedora35 --docker-network host
1717

1818
Cleanup:
1919

tests/integration/targets/keycloak_role/tasks/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
44
# SPDX-License-Identifier: GPL-3.0-or-later
55

6+
- name: Delete realm if exists
7+
community.general.keycloak_realm:
8+
auth_keycloak_url: "{{ url }}"
9+
auth_realm: "{{ admin_realm }}"
10+
auth_username: "{{ admin_user }}"
11+
auth_password: "{{ admin_password }}"
12+
realm: "{{ realm }}"
13+
state: absent
14+
615
- name: Create realm
716
community.general.keycloak_realm:
817
auth_keycloak_url: "{{ url }}"
@@ -297,6 +306,29 @@
297306
- result is not changed
298307
- result.end_state.composites | length == 3
299308

309+
- name: Change realm role with composites using aliases no change
310+
community.general.keycloak_role:
311+
auth_keycloak_url: "{{ url }}"
312+
auth_realm: "{{ admin_realm }}"
313+
auth_username: "{{ admin_user }}"
314+
auth_password: "{{ admin_password }}"
315+
name: "{{ keycloak_role_name }}"
316+
realm: "{{ realm }}"
317+
description: "{{ keycloak_role_description }}"
318+
composite: "{{ keycloak_role_composite }}"
319+
composites: "{{ keycloak_role_composites_with_aliases }}"
320+
state: present
321+
register: result
322+
323+
- name: Debug
324+
debug:
325+
var: result
326+
327+
- name: Assert realm role with composites using aliases have not changed
328+
assert:
329+
that:
330+
- result is not changed
331+
300332
- name: Remove composite from realm role with composites
301333
community.general.keycloak_role:
302334
auth_keycloak_url: "{{ url }}"

tests/integration/targets/keycloak_role/vars/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ keycloak_role_composites:
2525
state: present
2626
- name: offline_access
2727
state: present
28+
keycloak_role_composites_with_aliases:
29+
- name: view-clients
30+
clientId: "realm-management"
31+
state: present
32+
- name: query-clients
33+
clientId: "realm-management"
34+
state: present
35+
- name: offline_access
36+
state: present
2837
keycloak_client_id: test-client
2938
keycloak_client_name: test-client
3039
keycloak_client_description: This is a client for testing purpose

0 commit comments

Comments
 (0)