2021-12-14 10:26:42 +00:00
|
|
|
---
|
|
|
|
- name: "Get Realm for role"
|
2022-02-24 14:00:10 +00:00
|
|
|
ansible.builtin.uri:
|
2021-12-14 10:26:42 +00:00
|
|
|
url: "{{ keycloak_url }}/auth/admin/realms/{{ client_role.realm }}"
|
|
|
|
method: GET
|
|
|
|
status_code:
|
|
|
|
- 200
|
|
|
|
headers:
|
|
|
|
Accept: "application/json"
|
|
|
|
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
|
|
|
register: client_role_realm
|
|
|
|
|
|
|
|
- name: Check if Mapping is available
|
2022-02-24 14:00:10 +00:00
|
|
|
ansible.builtin.uri:
|
2021-12-14 10:26:42 +00:00
|
|
|
url: "{{ keycloak_url }}/auth/admin/realms/{{ client_role.realm }}/users/{{ (keycloak_user.json | first).id }}/role-mappings/clients/{{ (create_client_result.results | selectattr('end_state.clientId', 'equalto', client_role.client) | list | first).end_state.id }}/available"
|
|
|
|
method: GET
|
|
|
|
status_code:
|
|
|
|
- 200
|
|
|
|
headers:
|
|
|
|
Accept: "application/json"
|
|
|
|
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
|
|
|
register: client_role_user_available
|
|
|
|
|
|
|
|
- name: "Create Role Mapping"
|
2022-02-24 14:00:10 +00:00
|
|
|
ansible.builtin.uri:
|
2021-12-14 10:26:42 +00:00
|
|
|
url: "{{ keycloak_url }}/auth/admin/realms/{{ client_role.realm }}/users/{{ (keycloak_user.json | first).id }}/role-mappings/clients/{{ (create_client_result.results | selectattr('end_state.clientId', 'equalto', client_role.client) | list | first).end_state.id }}"
|
|
|
|
method: POST
|
|
|
|
body:
|
|
|
|
- id: "{{ item.id }}"
|
|
|
|
clientRole: "{{ item.clientRole }}"
|
|
|
|
containerId: "{{ item.containerId }}"
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
composite: "{{ item.composite }}"
|
|
|
|
validate_certs: False
|
|
|
|
body_format: json
|
|
|
|
headers:
|
|
|
|
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
|
|
|
status_code: 204
|
|
|
|
loop: "{{ client_role_user_available.json | flatten }}"
|
|
|
|
when: item.name == client_role.role
|