mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-08-01 04:14:48 +00:00
Fixing linting issues
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
---
|
||||
- name: Generate keycloak auth token
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/realms/master/protocol/openid-connect/token"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/realms/master/protocol/openid-connect/token"
|
||||
method: POST
|
||||
body: "client_id={{ keycloak_auth_client }}&username={{ keycloak_admin_user }}&password={{ keycloak_admin_password }}&grant_type=password"
|
||||
body: "client_id={{ keycloak_realm_auth_client }}&username={{ keycloak_realm_admin_user }}&password={{ keycloak_realm_admin_password }}&grant_type=password"
|
||||
validate_certs: false
|
||||
no_log: "{{ keycloak_no_log | default('True') }}"
|
||||
register: keycloak_auth_response
|
||||
until: keycloak_auth_response.status == 200
|
||||
no_log: "{{ keycloak_realm_no_log | default('True') }}"
|
||||
register: keycloak_realm_auth_response
|
||||
until: keycloak_realm_auth_response.status == 200
|
||||
retries: 5
|
||||
delay: 2
|
||||
|
||||
- name: "Determine if realm exists"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}"
|
||||
method: GET
|
||||
validate_certs: false
|
||||
status_code:
|
||||
@@ -21,38 +21,38 @@
|
||||
- 404
|
||||
headers:
|
||||
Accept: "application/json"
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_exists
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_realm_exists
|
||||
|
||||
- name: Create Realm
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms"
|
||||
method: POST
|
||||
body: "{{ lookup('template', 'realm.json.j2') }}"
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
status_code: 201
|
||||
when: keycloak_realm_exists.status == 404
|
||||
when: keycloak_realm_realm_exists.status == 404
|
||||
|
||||
- name: Create user federation
|
||||
middleware_automation.keycloak.keycloak_user_federation:
|
||||
auth_keycloak_url: "{{ keycloak_url }}{{ keycloak_context }}"
|
||||
auth_realm: "{{ keycloak_auth_realm }}"
|
||||
auth_username: "{{ keycloak_admin_user }}"
|
||||
auth_password: "{{ keycloak_admin_password }}"
|
||||
realm: "{{ item.realm | default(keycloak_realm) }}"
|
||||
auth_keycloak_url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}"
|
||||
auth_realm: "{{ keycloak_realm_auth_realm }}"
|
||||
auth_username: "{{ keycloak_realm_admin_user }}"
|
||||
auth_password: "{{ keycloak_realm_admin_password }}"
|
||||
realm: "{{ item.realm | default(keycloak_realm_realm) }}"
|
||||
name: "{{ item.name }}"
|
||||
state: present
|
||||
provider_id: "{{ item.provider_id }}"
|
||||
provider_type: "{{ item.provider_type | default('org.keycloak.storage.UserStorageProvider') }}"
|
||||
config: "{{ item.config }}"
|
||||
mappers: "{{ item.mappers | default(omit) }}"
|
||||
no_log: "{{ keycloak_no_log | default('True') }}"
|
||||
register: create_user_federation_result
|
||||
loop: "{{ keycloak_user_federation | flatten }}"
|
||||
when: keycloak_user_federation is defined
|
||||
no_log: "{{ keycloak_realm_no_log | default('True') }}"
|
||||
register: keycloak_realm_create_user_federation_result
|
||||
loop: "{{ keycloak_realm_user_federation | flatten }}"
|
||||
when: keycloak_realm_user_federation is defined
|
||||
|
||||
- name: Validate Keycloak clients
|
||||
ansible.builtin.assert:
|
||||
@@ -61,18 +61,18 @@
|
||||
- (item.client_id is defined and item.client_id | length > 0) or (item.id is defined and item.id | length > 0)
|
||||
fail_msg: "For each keycloak client, attributes `name` and either `id` or `client_id` is required"
|
||||
quiet: true
|
||||
loop: "{{ keycloak_clients | flatten }}"
|
||||
loop: "{{ keycloak_realm_clients | flatten }}"
|
||||
loop_control:
|
||||
label: "{{ item.name | default('unnamed client') }}"
|
||||
|
||||
- name: Create or update a Keycloak client
|
||||
middleware_automation.keycloak.keycloak_client:
|
||||
auth_client_id: "{{ keycloak_auth_client }}"
|
||||
auth_keycloak_url: "{{ keycloak_url }}{{ keycloak_context }}"
|
||||
auth_realm: "{{ keycloak_auth_realm }}"
|
||||
auth_username: "{{ keycloak_admin_user }}"
|
||||
auth_password: "{{ keycloak_admin_password }}"
|
||||
realm: "{{ item.realm | default(keycloak_realm) }}"
|
||||
auth_client_id: "{{ keycloak_realm_auth_client }}"
|
||||
auth_keycloak_url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}"
|
||||
auth_realm: "{{ keycloak_realm_auth_realm }}"
|
||||
auth_username: "{{ keycloak_realm_admin_user }}"
|
||||
auth_password: "{{ keycloak_realm_admin_password }}"
|
||||
realm: "{{ item.realm | default(keycloak_realm_realm) }}"
|
||||
default_roles: "{{ item.roles | default(omit) }}"
|
||||
client_id: "{{ item.client_id | default(omit) }}"
|
||||
id: "{{ item.id | default(omit) }}"
|
||||
@@ -94,21 +94,21 @@
|
||||
protocol: "{{ item.protocol | default(omit) }}"
|
||||
attributes: "{{ item.attributes | default(omit) }}"
|
||||
state: present
|
||||
no_log: "{{ keycloak_no_log | default('false') }}"
|
||||
register: create_client_result
|
||||
loop: "{{ keycloak_clients | flatten }}"
|
||||
no_log: "{{ keycloak_realm_no_log | default('false') }}"
|
||||
register: keycloak_realm_create_client_result
|
||||
loop: "{{ keycloak_realm_clients | flatten }}"
|
||||
when: (item.name is defined and item.client_id is defined) or (item.name is defined and item.id is defined)
|
||||
|
||||
- name: Create client roles
|
||||
ansible.builtin.include_tasks: manage_client_roles.yml
|
||||
loop: "{{ keycloak_clients | flatten }}"
|
||||
loop: "{{ keycloak_realm_clients | flatten }}"
|
||||
loop_control:
|
||||
loop_var: client
|
||||
when: "'roles' in client"
|
||||
|
||||
- name: Create client users
|
||||
ansible.builtin.include_tasks: manage_client_users.yml
|
||||
loop: "{{ keycloak_clients | flatten }}"
|
||||
loop: "{{ keycloak_realm_clients | flatten }}"
|
||||
loop_control:
|
||||
loop_var: client
|
||||
when: "'users' in client"
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
- name: Create client roles
|
||||
middleware_automation.keycloak.keycloak_role:
|
||||
name: "{{ item }}"
|
||||
realm: "{{ client.realm | default(keycloak_realm) }}"
|
||||
realm: "{{ client.realm | default(keycloak_realm_realm) }}"
|
||||
client_id: "{{ client.client_id }}"
|
||||
auth_client_id: "{{ keycloak_auth_client }}"
|
||||
auth_keycloak_url: "{{ keycloak_url }}{{ keycloak_context }}"
|
||||
auth_realm: "{{ keycloak_auth_realm }}"
|
||||
auth_username: "{{ keycloak_admin_user }}"
|
||||
auth_password: "{{ keycloak_admin_password }}"
|
||||
auth_client_id: "{{ keycloak_realm_auth_client }}"
|
||||
auth_keycloak_url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}"
|
||||
auth_realm: "{{ keycloak_realm_auth_realm }}"
|
||||
auth_username: "{{ keycloak_realm_admin_user }}"
|
||||
auth_password: "{{ keycloak_realm_admin_password }}"
|
||||
state: present
|
||||
loop: "{{ client.roles | flatten }}"
|
||||
no_log: "{{ keycloak_no_log | default('True') }}"
|
||||
no_log: "{{ keycloak_realm_no_log | default('True') }}"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
- name: "Update Access token lifespan"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}"
|
||||
method: PUT
|
||||
body:
|
||||
accessTokenLifespan: 300
|
||||
@@ -11,4 +11,4 @@
|
||||
- 200
|
||||
- 204
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
---
|
||||
- name: "Check if User Already Exists"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}/users?username={{ user.username }}"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}/users?username={{ user.username }}"
|
||||
validate_certs: false
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: keycloak_user_search_result
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_user_search_result
|
||||
|
||||
- name: "Create User"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}/users"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}/users"
|
||||
method: POST
|
||||
body:
|
||||
enabled: true
|
||||
@@ -21,21 +21,21 @@
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
status_code: 201
|
||||
when: keycloak_user_search_result.json | length == 0
|
||||
when: keycloak_realm_user_search_result.json | length == 0
|
||||
|
||||
- name: "Get User"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}/users?username={{ user.username }}"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}/users?username={{ user.username }}"
|
||||
validate_certs: false
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: keycloak_user
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_user
|
||||
|
||||
- name: "Update User Password"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}/users/{{ (keycloak_user.json | first).id }}/reset-password"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}/users/{{ (keycloak_realm_user.json | first).id }}/reset-password"
|
||||
method: PUT
|
||||
body:
|
||||
type: password
|
||||
@@ -47,5 +47,5 @@
|
||||
- 200
|
||||
- 204
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: keycloak_user
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_user
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
---
|
||||
- name: "Get Realm for role"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ client_role.realm | default(keycloak_realm) }}"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ client_role.realm | default(keycloak_realm_realm) }}"
|
||||
method: GET
|
||||
validate_certs: false
|
||||
status_code:
|
||||
- 200
|
||||
headers:
|
||||
Accept: "application/json"
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: client_role_realm
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_client_role_realm
|
||||
|
||||
- name: Check if Mapping is available
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ client_role.realm | \
|
||||
default(keycloak_realm) }}/users/{{ (keycloak_user.json | first).id }}/role-mappings/clients/{{ (create_client_result.results | \
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ client_role.realm | \
|
||||
default(keycloak_realm_realm) }}/users/{{ (keycloak_realm_user.json | first).id }}/role-mappings/clients/{{ (keycloak_realm_create_client_result.results | \
|
||||
selectattr('end_state.clientId', 'equalto', client_role.client) | list | first).end_state.id }}/available"
|
||||
method: GET
|
||||
validate_certs: false
|
||||
@@ -22,13 +22,13 @@
|
||||
- 200
|
||||
headers:
|
||||
Accept: "application/json"
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: client_role_user_available
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_client_role_user_available
|
||||
|
||||
- name: "Create Role Mapping"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ client_role.realm | \
|
||||
default(keycloak_realm) }}/users/{{ (keycloak_user.json | first).id }}/role-mappings/clients/{{ (create_client_result.results | \
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ client_role.realm | \
|
||||
default(keycloak_realm_realm) }}/users/{{ (keycloak_realm_user.json | first).id }}/role-mappings/clients/{{ (keycloak_realm_create_client_result.results | \
|
||||
selectattr('end_state.clientId', 'equalto', client_role.client) | list | first).end_state.id }}"
|
||||
method: POST
|
||||
body:
|
||||
@@ -40,7 +40,7 @@
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
headers:
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
status_code: 204
|
||||
loop: "{{ client_role_user_available.json | flatten }}"
|
||||
loop: "{{ keycloak_realm_client_role_user_available.json | flatten }}"
|
||||
when: item.name == client_role.role
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
---
|
||||
- name: "Get User {{ user.username }}"
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/admin/realms/{{ keycloak_realm }}/users?username={{ user.username }}"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/admin/realms/{{ keycloak_realm_realm }}/users?username={{ user.username }}"
|
||||
headers:
|
||||
validate_certs: false
|
||||
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
||||
register: keycloak_user
|
||||
Authorization: "Bearer {{ keycloak_realm_auth_response.json.access_token }}"
|
||||
register: keycloak_realm_user
|
||||
|
||||
- name: Refresh keycloak auth token
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_url }}{{ keycloak_context }}/realms/master/protocol/openid-connect/token"
|
||||
url: "{{ keycloak_realm_url }}{{ keycloak_realm_context }}/realms/master/protocol/openid-connect/token"
|
||||
method: POST
|
||||
body: "client_id={{ keycloak_auth_client }}&username={{ keycloak_admin_user }}&password={{ keycloak_admin_password }}&grant_type=password"
|
||||
body: "client_id={{ keycloak_realm_auth_client }}&username={{ keycloak_realm_admin_user }}&password={{ keycloak_realm_admin_password }}&grant_type=password"
|
||||
validate_certs: false
|
||||
register: keycloak_auth_response
|
||||
no_log: "{{ keycloak_no_log | default('True') }}"
|
||||
until: keycloak_auth_response.status == 200
|
||||
register: keycloak_realm_auth_response
|
||||
no_log: "{{ keycloak_realm_no_log | default('True') }}"
|
||||
until: keycloak_realm_auth_response.status == 200
|
||||
retries: 5
|
||||
delay: 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user