2022-04-07 12:07:08 +00:00
|
|
|
---
|
|
|
|
- name: Validate parameters
|
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
|
|
|
- keycloak.home is defined
|
|
|
|
- keycloak_quarkus_service_user is defined
|
|
|
|
- keycloak_quarkus_dest is defined
|
|
|
|
- keycloak_quarkus_archive is defined
|
|
|
|
- keycloak_quarkus_download_url is defined
|
|
|
|
- keycloak_quarkus_version is defined
|
|
|
|
quiet: true
|
|
|
|
|
|
|
|
- name: Check for an existing deployment
|
|
|
|
become: yes
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: "{{ keycloak.home }}"
|
|
|
|
register: existing_deploy
|
|
|
|
|
|
|
|
- name: "Create {{ keycloak.service_name }} service user/group"
|
|
|
|
become: yes
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ keycloak.service_user }}"
|
|
|
|
home: /opt/keycloak
|
|
|
|
system: yes
|
|
|
|
create_home: no
|
|
|
|
|
|
|
|
- name: "Create {{ keycloak.service_name }} install location"
|
|
|
|
become: yes
|
|
|
|
ansible.builtin.file:
|
|
|
|
dest: "{{ keycloak_quarkus_dest }}"
|
|
|
|
state: directory
|
|
|
|
owner: "{{ keycloak.service_user }}"
|
|
|
|
group: "{{ keycloak.service_group }}"
|
|
|
|
mode: 0750
|
|
|
|
|
|
|
|
## check remote archive
|
|
|
|
- name: Set download archive path
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
archive: "{{ keycloak_quarkus_dest }}/{{ keycloak.bundle }}"
|
|
|
|
|
|
|
|
- name: Check download archive path
|
|
|
|
become: yes
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: "{{ archive }}"
|
|
|
|
register: archive_path
|
|
|
|
|
|
|
|
## download to controller
|
|
|
|
- name: Check local download archive path
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: "{{ lookup('env', 'PWD') }}"
|
|
|
|
register: local_path
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Download keycloak archive
|
2022-04-28 09:58:29 +00:00
|
|
|
ansible.builtin.get_url: # noqa risky-file-permissions delegated, uses controller host user
|
2022-04-07 12:07:08 +00:00
|
|
|
url: "{{ keycloak_quarkus_download_url }}"
|
|
|
|
dest: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
2022-04-28 09:58:29 +00:00
|
|
|
mode: 0640
|
2022-04-07 12:07:08 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
when:
|
|
|
|
- archive_path is defined
|
|
|
|
- archive_path.stat is defined
|
|
|
|
- not archive_path.stat.exists
|
|
|
|
- not keycloak.offline_install
|
|
|
|
|
|
|
|
- name: Check downloaded archive
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
|
|
|
register: local_archive_path
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
## copy and unpack
|
|
|
|
- name: Copy archive to target nodes
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "{{ local_path.stat.path }}/{{ keycloak.bundle }}"
|
|
|
|
dest: "{{ archive }}"
|
|
|
|
owner: "{{ keycloak.service_user }}"
|
|
|
|
group: "{{ keycloak.service_group }}"
|
|
|
|
mode: 0750
|
|
|
|
register: new_version_downloaded
|
|
|
|
when:
|
|
|
|
- not archive_path.stat.exists
|
|
|
|
- local_archive_path.stat is defined
|
|
|
|
- local_archive_path.stat.exists
|
|
|
|
become: yes
|
|
|
|
|
2022-05-31 17:07:18 +00:00
|
|
|
- name: "Check target directory: {{ keycloak.home }}/bin/"
|
2022-04-07 12:07:08 +00:00
|
|
|
ansible.builtin.stat:
|
2022-05-31 17:07:18 +00:00
|
|
|
path: "{{ keycloak.home }}/bin/"
|
2022-04-07 12:07:08 +00:00
|
|
|
register: path_to_workdir
|
|
|
|
become: yes
|
|
|
|
|
|
|
|
- name: "Extract Keycloak archive on target"
|
|
|
|
ansible.builtin.unarchive:
|
|
|
|
remote_src: yes
|
|
|
|
src: "{{ archive }}"
|
|
|
|
dest: "{{ keycloak_quarkus_dest }}"
|
2022-05-31 17:07:18 +00:00
|
|
|
creates: "{{ keycloak.home }}/bin/"
|
2022-04-07 12:07:08 +00:00
|
|
|
owner: "{{ keycloak.service_user }}"
|
|
|
|
group: "{{ keycloak.service_group }}"
|
|
|
|
become: yes
|
|
|
|
when:
|
2022-05-31 17:07:18 +00:00
|
|
|
- (not path_to_workdir.stat.exists) or new_version_downloaded.changed
|
2022-04-07 12:07:08 +00:00
|
|
|
notify:
|
|
|
|
- restart keycloak
|
|
|
|
|
|
|
|
- name: Inform decompression was not executed
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ keycloak.home }} already exists and version unchanged, skipping decompression"
|
|
|
|
when:
|
2022-05-31 17:07:18 +00:00
|
|
|
- (not new_version_downloaded.changed) and path_to_workdir.stat.exists
|