ansible-keycloak/roles/keycloak/tasks/main.yml

51 lines
1.5 KiB
YAML
Raw Normal View History

---
# tasks file for keycloak
- name: Prerequisites
include_tasks: prereqs.yml
tags:
- prereqs
- name: Include install tasks
include_tasks: tasks/install.yml
- name: Include systemd tasks
include_tasks: tasks/systemd.yml
- name: Link default logs directory
file:
state: link
2022-01-27 13:23:11 +00:00
src: "{{ keycloak_jboss_home }}/standalone/log"
dest: /var/log/keycloak
2021-12-16 13:24:06 +00:00
- block:
- name: Check admin credentials by generating a token
uri:
url: "{{ keycloak_url }}/auth/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"
validate_certs: no
register: keycloak_auth_response
until: keycloak_auth_response.status == 200
retries: 2
delay: 2
rescue:
2022-01-27 13:23:11 +00:00
- name: "Create {{ keycloak.service_name }} admin user"
2021-12-16 13:24:06 +00:00
command:
args:
argv:
- "{{ keycloak_jboss_home }}/bin/add-user-keycloak.sh"
- "-rmaster"
- "-u{{ keycloak_admin_user }}"
- "-p{{ keycloak_admin_password }}"
2021-12-16 13:24:06 +00:00
become: yes
2022-01-27 13:23:11 +00:00
- name: "Restart {{ keycloak.service_name }}"
2021-12-16 13:24:06 +00:00
include_tasks: tasks/restart_keycloak.yml
2022-01-27 13:23:11 +00:00
- name: "Wait until {{ keycloak.service_name }} becomes active {{ keycloak.health_url }}"
uri:
2022-01-27 13:23:11 +00:00
url: "{{ keycloak.health_url }}"
register: keycloak_status
until: keycloak_status.status == 200
retries: 25
delay: 10