corrected adding of admin user, permissions, missing module

This commit is contained in:
Alexander Gabriel 2021-06-06 22:32:58 +01:00
parent 82623e97c7
commit 3f3669c34c

View File

@ -16,12 +16,18 @@
createhome: yes createhome: yes
home: /opt/keycloak home: /opt/keycloak
- name: check if keycloak-dir exists
stat:
path: /opt/keycloak/keycloak-13.0.1
register: keycloak_exists
- name: Extract keycloak-13.0.1.tar.gz to /opt/keycloak - name: Extract keycloak-13.0.1.tar.gz to /opt/keycloak
unarchive: unarchive:
src: keycloak-13.0.1.tar.gz src: keycloak-13.0.1.tar.gz
dest: /opt/keycloak dest: /opt/keycloak
owner: keycloak owner: keycloak
group: keycloak group: keycloak
when: not keycloak_exists.stat.exists or redeploy is defined
- name: link /opt/keycloak/keycloak-13.0.1 to /opt/keycloak/current - name: link /opt/keycloak/keycloak-13.0.1 to /opt/keycloak/current
file: file:
@ -29,21 +35,6 @@
src: /opt/keycloak/keycloak-13.0.1 src: /opt/keycloak/keycloak-13.0.1
dest: /opt/keycloak/current dest: /opt/keycloak/current
- name: set permissions correct
file:
dest: /opt/keycloak
owner: keycloak
group: keycloak
recurse: yes
- name: set permissions correct 2
file:
dest: /opt/keycloak/current/standalone/deployments
owner: keycloak
group: keycloak
mode: "0644"
recurse: yes
- name: generate /etc/systemd/system/keycloak.service - name: generate /etc/systemd/system/keycloak.service
template: template:
src: keycloak.service.j2 src: keycloak.service.j2
@ -58,9 +49,6 @@
template: template:
src: standalone.xml.j2 src: standalone.xml.j2
dest: /opt/keycloak/current/standalone/configuration/standalone.xml dest: /opt/keycloak/current/standalone/configuration/standalone.xml
owner: keycloak
group: keycloak
mode: "0644"
notify: notify:
- restart keycloak - restart keycloak
@ -70,6 +58,14 @@
enabled: yes enabled: yes
masked: no masked: no
- name: set permissions correct
file:
dest: /opt/keycloak
owner: keycloak
group: keycloak
mode: "0770"
recurse: yes
- name: Flush handlers - name: Flush handlers
meta: flush_handlers meta: flush_handlers
@ -84,19 +80,41 @@
- name: Flush handlers - name: Flush handlers
meta: flush_handlers meta: flush_handlers
- name: check if /opt/keycloak/current/adminuseradded.txt exists
stat:
path: /opt/keycloak/current/standalone/configuration/keycloak-add-user.json
register: adminuseradded_exists
- name: check if /opt/keycloak/current/standalone/configuration/keycloak-add-user.json exists - name: check if /opt/keycloak/current/standalone/configuration/keycloak-add-user.json exists
stat: stat:
path: /opt/keycloak/current/standalone/configuration/keycloak-add-user.json path: /opt/keycloak/current/standalone/configuration/keycloak-add-user.json
register: file_exists when: not adminuseradded_exists.stat.exists
register: keycloak_add_user_exists
- name: check if user exists - name: check if user exists
shell: "grep username /opt/keycloak/current/standalone/configuration/keycloak-add-user.json | grep admin" shell: "grep username /opt/keycloak/current/standalone/configuration/keycloak-add-user.json | grep admin"
register: userexists register: userexists
when: file_exists.stat.exists when: not adminuseradded_exists.stat.exists and keycloak_add_user_exists.stat.exists
- name: create initial admin user - name: create initial admin user
command: /opt/keycloak/current/bin/add-user-keycloak.sh -u admin -p {{ keycloak_initial_admin_password }} -r master command: sudo -u keycloak /opt/keycloak/current/bin/add-user-keycloak.sh -u admin -p {{ keycloak_initial_admin_password }} -r master
when: file_exists.stat.exists and userexists.stdout == "" when: not keycloak_add_user_exists.stat.exists or userexists.stdout == ""
notify:
restart keycloak
- name: create initial admin user
command: sudo -u keycloak touch /opt/keycloak/current/adminuseradded.txt
when: not keycloak_add_user_exists.stat.exists or userexists.stdout == ""
notify:
restart keycloak
- name: set permissions correct again
file:
dest: /opt/keycloak
owner: keycloak
group: keycloak
mode: "0770"
recurse: yes
- name: enable apache module proxy - name: enable apache module proxy
command: a2enmod proxy command: a2enmod proxy
@ -140,6 +158,13 @@
notify: notify:
restart apache2 restart apache2
- name: enable apache module rewrite
command: a2enmod rewrite
args:
creates: /etc/apache2/mods-enabled/rewrite.load
notify:
restart apache2
- name: install acme.sh - name: install acme.sh
include_role: include_role:
name: acme.sh name: acme.sh
@ -166,6 +191,8 @@
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
notify:
- reload apache2
- name: generate /etc/apache2/sites-available/{{ inventory_hostname }}-ssl.conf - name: generate /etc/apache2/sites-available/{{ inventory_hostname }}-ssl.conf
template: template:
@ -174,6 +201,8 @@
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
notify:
- reload apache2
- name: activate /etc/apache2/sites-available/{{ inventory_hostname }}.conf - name: activate /etc/apache2/sites-available/{{ inventory_hostname }}.conf
file: file: