keycloak_group: fix subgroup lookup on Keycloak older than 25

The parents branch of get_group_by_name() queried
GET /admin/realms/{realm}/groups/{id}/children?search=&exact=true
unconditionally. That endpoint only accepts GET from Keycloak 23 on, so
older servers (RH-SSO 7.x included) failed with 405 Method Not Allowed,
and 23/24 ignore search/exact and return only the first 10 children, so
subgroups past the tenth were silently reported as absent.

The lookup now goes through get_subgroups(), which already detects the
server generation, and that helper takes an optional search argument so
the search optimization is kept where the server supports it.
This commit is contained in:
Yabk
2026-09-04 12:56:23 +02:00
parent 8d5526aeb6
commit 529b667321
3 changed files with 135 additions and 10 deletions
+56
View File
@@ -12,6 +12,7 @@
client: molecule-client
scope: molecule-scope
group: molecule-group
subgroup: molecule-subgroup
user: molecule-user
flow: molecule-flow
flow_v2: molecule-flow-v2
@@ -559,6 +560,61 @@
roles:
- name: "{{ client_role }}"
- name: keycloak_group — create subgroup below the parent group
middleware_automation.keycloak.keycloak_group:
realm: "{{ target_realm }}"
name: "{{ subgroup }}"
parents:
- name: "{{ group }}"
state: present
register: subgroup_result
- name: Assert subgroup was created below the parent group
ansible.builtin.assert:
that:
- subgroup_result is changed
- subgroup_result.end_state.path == '/' ~ group ~ '/' ~ subgroup
- name: keycloak_group — create enough siblings to exceed the children page size
middleware_automation.keycloak.keycloak_group:
realm: "{{ target_realm }}"
name: "{{ subgroup }}-{{ item }}"
parents:
- name: "{{ group }}"
state: present
loop: "{{ range(1, 13) | list }}"
- name: keycloak_group — look up a subgroup sorting past the children page size
middleware_automation.keycloak.keycloak_group:
realm: "{{ target_realm }}"
name: "{{ subgroup }}-9"
parents:
- name: "{{ group }}"
state: present
register: subgroup_paging_result
- name: Assert subgroup lookup is not limited to the first page of children
ansible.builtin.assert:
that:
- subgroup_paging_result is not changed
- subgroup_paging_result.end_state.path == '/' ~ group ~ '/' ~ subgroup ~ '-9'
- name: keycloak_realm_rolemapping — assign realm role to subgroup via parents
middleware_automation.keycloak.keycloak_realm_rolemapping:
realm: "{{ target_realm }}"
group_name: "{{ subgroup }}"
parents:
- name: "{{ group }}"
state: present
roles:
- name: "{{ role }}"
register: subgroup_rolemapping_result
- name: Assert realm role was mapped to the subgroup
ansible.builtin.assert:
that:
- subgroup_rolemapping_result is changed
- name: keycloak_client_rolescope — restrict realm role on client
middleware_automation.keycloak.keycloak_client_rolescope:
realm: "{{ target_realm }}"