mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-11-21 14:48:50 +00:00
Since the molecule jobs moved to self-hosted container runners, molecule talks to a Docker daemon that does not share the runner's filesystem or network namespace: - quarkus_ha*: drop the postgresql.conf bind mount (the workspace path does not exist on the daemon side) and pass listen_addresses via -c - quarkus, quarkus_devmode: fetch the openid configuration from the instance with ansible.builtin.uri instead of curl | jq on the runner, and drop the fixed host published_ports that are no longer needed - quarkus_nohost: add the missing roles symlink Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
149 lines
5.7 KiB
YAML
149 lines
5.7 KiB
YAML
---
|
|
- name: Verify
|
|
hosts: all
|
|
vars_files:
|
|
- ../group_vars/all/vars.yml
|
|
vars:
|
|
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
|
keycloak_quarkus_bootstrap_admin_user: "remembertochangeme"
|
|
tasks:
|
|
- name: Populate service facts
|
|
ansible.builtin.service_facts:
|
|
|
|
- name: Check if keycloak service started
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_facts.services["keycloak.service"]["state"] == "running"
|
|
- ansible_facts.services["keycloak.service"]["status"] == "enabled"
|
|
fail_msg: "Service not running"
|
|
|
|
- name: Read Keycloak sysconfig
|
|
ansible.builtin.slurp:
|
|
src: /etc/sysconfig/keycloak
|
|
register: keycloak_sysconfig
|
|
become: "{{ molecule_prepare_require_privilege_escalation | default(true) }}"
|
|
|
|
- name: Decode Keycloak sysconfig
|
|
ansible.builtin.set_fact:
|
|
keycloak_sysconfig_text: "{{ keycloak_sysconfig.content | ansible.builtin.b64decode(encoding='utf-8') }}"
|
|
|
|
- name: Assert sysconfig defers JAVA_OPTS to Keycloak kc.sh defaults
|
|
ansible.builtin.assert:
|
|
that:
|
|
- keycloak_sysconfig_text is search('JAVA_OPTS_KC_HEAP=')
|
|
- keycloak_sysconfig_text is search('JAVA_OPTS_APPEND=')
|
|
- keycloak_sysconfig_text is not search('(?m)^JAVA_OPTS=')
|
|
fail_msg: >-
|
|
Expected JAVA_OPTS_KC_HEAP and JAVA_OPTS_APPEND (not JAVA_OPTS) in sysconfig.
|
|
Got:
|
|
{{ keycloak_sysconfig_text }}
|
|
|
|
- name: Set internal envvar
|
|
ansible.builtin.set_fact:
|
|
hera_home: "{{ lookup('env', 'HERA_HOME') }}"
|
|
|
|
- name: Verify openid config
|
|
when:
|
|
- hera_home is defined
|
|
- hera_home | length == 0
|
|
block:
|
|
- name: Fetch openID config
|
|
ansible.builtin.uri:
|
|
url: https://localhost:8443/realms/master/.well-known/openid-configuration
|
|
headers:
|
|
Host: instance
|
|
validate_certs: false
|
|
register: openid_config
|
|
- name: Verify endpoint URLs
|
|
ansible.builtin.assert:
|
|
that:
|
|
- openid_config.json["backchannel_authentication_endpoint"] == 'https://instance:8443/realms/master/protocol/openid-connect/ext/ciba/auth'
|
|
- openid_config.json['issuer'] == 'https://instance:8443/realms/master'
|
|
- openid_config.json['authorization_endpoint'] == 'https://instance:8443/realms/master/protocol/openid-connect/auth'
|
|
- openid_config.json['token_endpoint'] == 'https://instance:8443/realms/master/protocol/openid-connect/token'
|
|
|
|
- name: Check log folder
|
|
ansible.builtin.stat:
|
|
path: /tmp/keycloak
|
|
register: keycloak_log_folder
|
|
|
|
- name: Check that keycloak log folder exists and is a link
|
|
ansible.builtin.assert:
|
|
that:
|
|
- keycloak_log_folder.stat.exists
|
|
- not keycloak_log_folder.stat.isdir
|
|
- keycloak_log_folder.stat.islnk
|
|
fail_msg: "Service log symlink not correctly created"
|
|
|
|
- name: Check log file
|
|
become: "{{ molecule_prepare_require_privilege_escalation | default(true) }}"
|
|
ansible.builtin.stat:
|
|
path: /tmp/keycloak/keycloak.log
|
|
register: keycloak_log_file
|
|
|
|
- name: Check if keycloak file exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- keycloak_log_file.stat.exists
|
|
- not keycloak_log_file.stat.isdir
|
|
|
|
- name: Check default log folder
|
|
become: "{{ molecule_prepare_require_privilege_escalation | default(true) }}"
|
|
ansible.builtin.stat:
|
|
path: /var/log/keycloak
|
|
register: keycloak_default_log_folder
|
|
failed_when: false
|
|
|
|
- name: Check that default keycloak log folder doesn't exist
|
|
ansible.builtin.assert:
|
|
that:
|
|
- not keycloak_default_log_folder.stat.exists
|
|
|
|
- name: Verify vault SPI in logfile
|
|
become: "{{ molecule_prepare_require_privilege_escalation | default(true) }}"
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
zgrep 'Configured KeystoreVaultProviderFactory with the keystore file' /opt/keycloak/keycloak-*/data/log/keycloak.log*zip
|
|
changed_when: false
|
|
failed_when: slurped_log.rc != 0
|
|
register: slurped_log
|
|
|
|
- name: Verify token api call
|
|
ansible.builtin.uri:
|
|
url: "https://instance:8443/realms/master/protocol/openid-connect/token"
|
|
method: POST
|
|
body: "client_id=admin-cli&username={{ keycloak_quarkus_bootstrap_admin_user }}&password={{ keycloak_quarkus_bootstrap_admin_password}}&grant_type=password"
|
|
validate_certs: no
|
|
register: keycloak_auth_response
|
|
until: keycloak_auth_response.status == 200
|
|
retries: 2
|
|
delay: 2
|
|
|
|
- name: "Get Clients"
|
|
ansible.builtin.uri:
|
|
url: "https://instance:8443/admin/realms/TestRealm/clients"
|
|
validate_certs: false
|
|
headers:
|
|
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
|
register: keycloak_clients
|
|
|
|
- name: Get client uuid
|
|
ansible.builtin.set_fact:
|
|
keycloak_client_uuid: "{{ ((keycloak_clients.json | selectattr('clientId', '==', 'TestClient')) | first).id }}"
|
|
|
|
- name: "Get Client {{ keycloak_client_uuid }}"
|
|
ansible.builtin.uri:
|
|
url: "https://instance:8443/admin/realms/TestRealm/clients/{{ keycloak_client_uuid }}"
|
|
validate_certs: false
|
|
headers:
|
|
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
|
register: keycloak_test_client
|
|
|
|
- name: "Get Client roles"
|
|
ansible.builtin.uri:
|
|
url: "https://instance:8443/admin/realms/TestRealm/clients/{{ keycloak_client_uuid }}/roles"
|
|
validate_certs: false
|
|
headers:
|
|
Authorization: "Bearer {{ keycloak_auth_response.json.access_token }}"
|
|
register: keycloak_test_client_roles
|