-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb46948
commit 22ccef1
Showing
6 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
keycloak_version: "24.0.4" | ||
kc_db: "postgres" | ||
kc_db_url: "jdbc:postgresql://postgres:5432/keycloak" | ||
kc_db_username: "user" | ||
kc_db_password: "password" | ||
kc_hostname: "localhost" | ||
kc_log_level: "INFO" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Restart service keycloak | ||
systemd: | ||
name: 'keycloak' | ||
state: restarted | ||
daemon_reload: true | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
- name: Install prerequisites for Keycloak | ||
ansible.builtin.apt: | ||
name: | ||
- openjdk-17-jdk | ||
- unzip | ||
state: present | ||
|
||
- name: Download Keycloak | ||
ansible.builtin.get_url: | ||
url: "https://github.com/keycloak/keycloak/releases/download/{{ keycloak_version }}/keycloak-{{ keycloak_version }}.zip" | ||
dest: "/tmp/keycloak-{{ keycloak_version }}.zip" | ||
mode: '0755' | ||
|
||
- name: Extract Keycloak | ||
ansible.builtin.unarchive: | ||
src: "/tmp/keycloak-{{ keycloak_version }}.zip" | ||
dest: "/opt/" | ||
creates: "/opt/keycloak-{{ keycloak_version }}" | ||
remote_src: true | ||
|
||
- name: Create a symbolic link for Keycloak | ||
ansible.builtin.file: | ||
src: "/opt/keycloak-{{ keycloak_version }}" | ||
dest: "/opt/keycloak" | ||
state: link | ||
|
||
- name: Create keycloak user | ||
ansible.builtin.user: | ||
name: keycloak | ||
system: true | ||
shell: /bin/false | ||
|
||
- name: Ensure data directory exists and is owned by user keycloak | ||
ansible.builtin.file: | ||
path: /opt/keycloak/data | ||
state: directory | ||
owner: keycloak | ||
group: keycloak | ||
mode: '0750' | ||
|
||
- name: Make kc.sh executable | ||
ansible.builtin.file: | ||
path: /opt/keycloak/bin/kc.sh | ||
mode: '0755' | ||
owner: keycloak | ||
group: keycloak | ||
|
||
- name: Configure Keycloak service | ||
ansible.builtin.template: | ||
src: keycloak.conf.j2 | ||
dest: "/etc/systemd/system/keycloak.service" | ||
mode: '0644' | ||
notify: | ||
- restart service keycloak | ||
|
||
- name: Enable and start the Keycloak service | ||
ansible.builtin.systemd: | ||
name: keycloak | ||
enabled: true | ||
state: started |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[Unit] | ||
Description=Keycloak | ||
After=network.target | ||
|
||
[Service] | ||
Type=idle | ||
User=keycloak | ||
ExecStart=/opt/keycloak/bin/kc.sh start-dev | ||
Environment="KC_DB={{ kc_db }}" | ||
Environment="KC_DB_URL={{ kc_db_url }}" | ||
Environment="KC_DB_USERNAME={{ kc_db_username }}" | ||
Environment="KC_DB_PASSWORD={{ kc_db_password|replace('\\', '\\x5c')|replace('"', '\\x22')|replace('%', '%%') }}" | ||
Environment="KC_LOG_LEVEL={{ kc_log_level }}" | ||
Environment="KEYCLOAK_ADMIN={{ keycloak_admin_username }}" | ||
Environment="KEYCLOAK_ADMIN_PASSWORD={{ keycloak_admin_password|replace('\\', '\\x5c')|replace('"', '\\x22')|replace('%', '%%')}}" | ||
Environment="KC_HOSTNAME={{ kc_hostname }}" | ||
Environment="KC_HOSTNAME_STRICT=false" | ||
Environment="KC_HTTP_RELATIVE_PATH=/" | ||
Environment="KC_PROXY=edge" | ||
Environment="KC_LOG_LEVEL=DEBUG" | ||
|
||
Restart=on-failure | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters