2021-12-14 11:26:42 +01:00
|
|
|
---
|
2022-01-27 14:24:10 +01:00
|
|
|
- name: Validate parameters
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.assert:
|
2021-12-14 11:26:42 +01:00
|
|
|
that:
|
|
|
|
- keycloak_jboss_home is defined
|
|
|
|
- keycloak_service_user is defined
|
|
|
|
- keycloak_dest is defined
|
|
|
|
- keycloak_archive is defined
|
|
|
|
- keycloak_download_url is defined
|
|
|
|
- keycloak_version is defined
|
|
|
|
quiet: true
|
|
|
|
|
2022-01-27 14:24:10 +01:00
|
|
|
- name: Check for an existing deployment
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.stat:
|
2021-12-14 11:26:42 +01:00
|
|
|
path: "{{ keycloak_jboss_home }}"
|
|
|
|
register: existing_deploy
|
|
|
|
|
2022-05-11 11:33:52 +02:00
|
|
|
- name: Stop and restart if existing deployment exists and install forced
|
|
|
|
block:
|
2022-03-17 10:45:55 +01:00
|
|
|
- name: "Stop the old {{ keycloak.service_name }} service"
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
|
|
|
ignore_errors: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.systemd:
|
2021-12-14 11:26:42 +01:00
|
|
|
name: keycloak
|
|
|
|
state: stopped
|
2022-03-17 10:45:55 +01:00
|
|
|
- name: "Remove the old {{ keycloak.service_name }} deployment"
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.file:
|
2021-12-14 11:26:42 +01:00
|
|
|
path: "{{ keycloak_jboss_home }}"
|
|
|
|
state: absent
|
|
|
|
when: existing_deploy.stat.exists and keycloak_force_install|bool
|
|
|
|
|
2022-03-11 15:08:53 +01:00
|
|
|
- name: Check for an existing deployment after possible forced removal
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.stat:
|
2021-12-14 11:26:42 +01:00
|
|
|
path: "{{ keycloak_jboss_home }}"
|
|
|
|
|
2022-03-17 10:45:55 +01:00
|
|
|
- name: "Create {{ keycloak.service_name }} service user/group"
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.user:
|
2021-12-14 11:26:42 +01:00
|
|
|
name: "{{ keycloak_service_user }}"
|
|
|
|
home: /opt/keycloak
|
|
|
|
system: yes
|
|
|
|
create_home: no
|
|
|
|
|
2022-03-17 10:45:55 +01:00
|
|
|
- name: "Create {{ keycloak.service_name }} install location"
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.file:
|
2021-12-14 11:26:42 +01:00
|
|
|
dest: "{{ keycloak_dest }}"
|
|
|
|
state: directory
|
|
|
|
owner: "{{ keycloak_service_user }}"
|
|
|
|
group: "{{ keycloak_service_group }}"
|
2021-12-14 11:34:41 +01:00
|
|
|
mode: 0750
|
2021-12-14 11:26:42 +01:00
|
|
|
|
2022-01-27 14:24:10 +01:00
|
|
|
## check remote archive
|
|
|
|
- name: Set download archive path
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.set_fact:
|
2022-01-27 14:24:10 +01:00
|
|
|
archive: "{{ keycloak_dest }}/{{ keycloak.bundle }}"
|
|
|
|
|
|
|
|
- name: Check download archive path
|
2022-03-17 10:45:55 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.stat:
|
2022-01-27 14:24:10 +01:00
|
|
|
path: "{{ archive }}"
|
|
|
|
register: archive_path
|
|
|
|
|
|
|
|
## download to controller
|
2022-02-15 10:14:44 +01:00
|
|
|
- name: Check local download archive path
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.stat:
|
2022-01-27 14:24:10 +01:00
|
|
|
path: "{{ lookup('env', 'PWD') }}"
|
|
|
|
register: local_path
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Download keycloak archive
|
2022-04-28 11:58:29 +02:00
|
|
|
ansible.builtin.get_url: # noqa risky-file-permissions delegated, uses controller host user
|
2022-01-27 14:24:10 +01:00
|
|
|
url: "{{ keycloak_download_url }}"
|
|
|
|
dest: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
2022-05-11 10:38:52 +02:00
|
|
|
mode: 0644
|
2022-01-27 14:24:10 +01:00
|
|
|
delegate_to: localhost
|
|
|
|
when:
|
|
|
|
- archive_path is defined
|
|
|
|
- archive_path.stat is defined
|
|
|
|
- not archive_path.stat.exists
|
2022-09-19 16:02:55 +02:00
|
|
|
- not sso_enable is defined or not sso_enable
|
2022-01-27 14:24:10 +01:00
|
|
|
- not keycloak_offline_install
|
|
|
|
|
2022-02-15 13:14:36 +01:00
|
|
|
- name: Perform download from RHN
|
2022-02-24 15:00:10 +01:00
|
|
|
middleware_automation.redhat_csp_download.redhat_csp_download:
|
2022-01-27 14:24:10 +01:00
|
|
|
url: "{{ keycloak_rhsso_download_url }}"
|
|
|
|
dest: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
|
|
|
username: "{{ rhn_username }}"
|
|
|
|
password: "{{ rhn_password }}"
|
|
|
|
no_log: "{{ omit_rhn_output | default(true) }}"
|
|
|
|
delegate_to: localhost
|
|
|
|
when:
|
|
|
|
- archive_path is defined
|
|
|
|
- archive_path.stat is defined
|
|
|
|
- not archive_path.stat.exists
|
2022-09-19 16:02:55 +02:00
|
|
|
- sso_enable is defined and sso_enable
|
2022-01-27 14:24:10 +01:00
|
|
|
- not keycloak_offline_install
|
2022-09-19 16:02:55 +02:00
|
|
|
- keycloak_rhn_url in keycloak_download_url
|
2022-01-27 14:24:10 +01:00
|
|
|
|
|
|
|
- name: Download rhsso archive from alternate location
|
2022-04-28 11:58:29 +02:00
|
|
|
ansible.builtin.get_url: # noqa risky-file-permissions delegated, uses controller host user
|
2022-01-27 14:24:10 +01:00
|
|
|
url: "{{ keycloak_rhsso_download_url }}"
|
|
|
|
dest: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
2022-05-11 10:38:52 +02:00
|
|
|
mode: 0644
|
2022-01-27 14:24:10 +01:00
|
|
|
delegate_to: localhost
|
|
|
|
when:
|
|
|
|
- archive_path is defined
|
|
|
|
- archive_path.stat is defined
|
|
|
|
- not archive_path.stat.exists
|
2022-09-19 16:02:55 +02:00
|
|
|
- sso_enable is defined and sso_enable
|
2022-01-27 14:24:10 +01:00
|
|
|
- not keycloak_offline_install
|
2022-09-19 16:02:55 +02:00
|
|
|
- not keycloak_rhn_url in keycloak_download_url
|
2022-01-27 14:24:10 +01:00
|
|
|
|
2022-02-09 15:06:40 +01:00
|
|
|
- name: Check downloaded archive
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.stat:
|
2022-02-09 15:06:40 +01:00
|
|
|
path: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
|
|
|
register: local_archive_path
|
|
|
|
delegate_to: localhost
|
|
|
|
|
2022-01-27 14:24:10 +01:00
|
|
|
## copy and unpack
|
|
|
|
- name: Copy archive to target nodes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.copy:
|
2022-01-27 14:24:10 +01:00
|
|
|
src: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
|
|
|
dest: "{{ archive }}"
|
|
|
|
owner: "{{ keycloak_service_user }}"
|
|
|
|
group: "{{ keycloak_service_group }}"
|
2022-05-11 10:38:52 +02:00
|
|
|
mode: 0640
|
2022-01-27 14:24:10 +01:00
|
|
|
register: new_version_downloaded
|
2022-02-09 15:06:40 +01:00
|
|
|
when:
|
|
|
|
- not archive_path.stat.exists
|
|
|
|
- local_archive_path.stat is defined
|
|
|
|
- local_archive_path.stat.exists
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
|
|
|
|
2022-01-28 15:18:49 +01:00
|
|
|
- name: "Check target directory: {{ keycloak.home }}"
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.stat:
|
2022-01-28 15:18:49 +01:00
|
|
|
path: "{{ keycloak.home }}"
|
2022-01-27 14:24:10 +01:00
|
|
|
register: path_to_workdir
|
|
|
|
become: yes
|
2021-12-14 11:26:42 +01:00
|
|
|
|
2022-09-19 16:02:55 +02:00
|
|
|
- name: "Extract {{ keycloak_service_desc }} archive on target"
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.unarchive:
|
2022-01-27 14:24:10 +01:00
|
|
|
remote_src: yes
|
|
|
|
src: "{{ archive }}"
|
|
|
|
dest: "{{ keycloak_dest }}"
|
|
|
|
creates: "{{ keycloak.home }}"
|
|
|
|
owner: "{{ keycloak_service_user }}"
|
|
|
|
group: "{{ keycloak_service_group }}"
|
|
|
|
become: yes
|
|
|
|
when:
|
|
|
|
- new_version_downloaded.changed or not path_to_workdir.stat.exists
|
|
|
|
notify:
|
|
|
|
- restart keycloak
|
|
|
|
|
|
|
|
- name: Inform decompression was not executed
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.debug:
|
2022-01-27 14:24:10 +01:00
|
|
|
msg: "{{ keycloak.home }} already exists and version unchanged, skipping decompression"
|
|
|
|
when:
|
|
|
|
- not new_version_downloaded.changed and path_to_workdir.stat.exists
|
|
|
|
|
|
|
|
- name: "Reown installation directory to {{ keycloak_service_user }}"
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.file:
|
2022-01-27 14:24:10 +01:00
|
|
|
path: "{{ keycloak.home }}"
|
|
|
|
owner: "{{ keycloak_service_user }}"
|
|
|
|
group: "{{ keycloak_service_group }}"
|
|
|
|
recurse: true
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-01-27 14:24:10 +01:00
|
|
|
changed_when: false
|
2021-12-14 11:26:42 +01:00
|
|
|
|
2022-01-27 14:24:10 +01:00
|
|
|
# driver and configuration
|
2021-12-17 14:56:28 +01:00
|
|
|
- name: "Install {{ keycloak_jdbc_engine }} driver"
|
2022-09-19 22:07:23 +02:00
|
|
|
ansible.builtin.include_tasks: jdbc_driver.yml
|
2021-12-17 14:56:28 +01:00
|
|
|
when: keycloak_jdbc[keycloak_jdbc_engine].enabled
|
2021-12-14 11:26:42 +01:00
|
|
|
|
2022-04-12 12:07:06 +02:00
|
|
|
- name: "Deploy {{ keycloak.service_name }} config to {{ keycloak_config_path_to_standalone_xml }} from {{ keycloak.config_template_source }}"
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.template:
|
2022-04-12 12:07:06 +02:00
|
|
|
src: "templates/{{ keycloak.config_template_source }}"
|
2021-12-30 16:22:41 +01:00
|
|
|
dest: "{{ keycloak_config_path_to_standalone_xml }}"
|
2021-12-14 11:34:41 +01:00
|
|
|
owner: "{{ keycloak_service_user }}"
|
|
|
|
group: "{{ keycloak_service_group }}"
|
|
|
|
mode: 0640
|
2021-12-14 11:26:42 +01:00
|
|
|
notify:
|
|
|
|
- restart keycloak
|
2022-04-12 12:07:06 +02:00
|
|
|
when: not keycloak_remotecache.enabled or keycloak_config_override_template|length > 0
|
2021-12-14 11:26:42 +01:00
|
|
|
|
2022-01-27 14:24:10 +01:00
|
|
|
- name: "Deploy {{ keycloak.service_name }} config with remote cache store to {{ keycloak_config_path_to_standalone_xml }}"
|
2021-12-14 11:26:42 +01:00
|
|
|
become: yes
|
2022-02-24 15:00:10 +01:00
|
|
|
ansible.builtin.template:
|
2022-01-14 10:09:10 +01:00
|
|
|
src: templates/standalone-infinispan.xml.j2
|
2021-12-30 16:22:41 +01:00
|
|
|
dest: "{{ keycloak_config_path_to_standalone_xml }}"
|
2021-12-14 11:34:41 +01:00
|
|
|
owner: "{{ keycloak_service_user }}"
|
|
|
|
group: "{{ keycloak_service_group }}"
|
|
|
|
mode: 0640
|
2021-12-14 11:26:42 +01:00
|
|
|
notify:
|
|
|
|
- restart keycloak
|
|
|
|
when: keycloak_remotecache.enabled
|