From 24350903ed082f2a1ffd18d2dc41f830f2e902d7 Mon Sep 17 00:00:00 2001 From: Harsha Cherukuri Date: Thu, 3 Sep 2026 09:43:06 -0400 Subject: [PATCH] Fix issue #397 crash on first role assignment --- plugins/modules/keycloak_client_rolemapping.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/modules/keycloak_client_rolemapping.py b/plugins/modules/keycloak_client_rolemapping.py index 5a7e03a..89ab704 100644 --- a/plugins/modules/keycloak_client_rolemapping.py +++ b/plugins/modules/keycloak_client_rolemapping.py @@ -339,11 +339,10 @@ def main(): role["id"] = role_id else: module.fail_json(msg=f"Could not fetch role {role['name']}:") - # Fetch missing role_name - else: - role["name"] = kc.get_client_group_rolemapping_by_id(gid, cid, role["id"], realm=realm)["name"] - if role["name"] is None: - module.fail_json(msg=f"Could not fetch role {role['id']}") + # Fetch missing role_name from the client's roles, not from existing group mappings + elif role["name"] is None: + role_rep = kc.get_role_by_id(role["id"], realm=realm) + role["name"] = role_rep["name"] # Get effective client-level role mappings available_roles_before = kc.get_client_group_available_rolemappings(gid, cid, realm=realm)