Kevin Veen-Birkenbach 4fa1c6cfbd
ansible: quote file modes; keycloak: robust LDAP bind update + config cleanup
Highlights
- Quote all file modes as strings ("0755"/"0770") across multiple roles to avoid YAML octal quirks and improve portability.
- Keycloak: introduce actions.{import_realm,update_ldap_bind} feature flags and wire them via vars/config.
- Implement idempotent LDAP bind updater (tasks/03_update-ldap-bind.yml):
  * kcadm login with no_log protection,
  * fetch LDAP UserStorage component by name,
  * compare current bindDn/bindCredential and update only when changed.
- Keycloak realm import template: keep providerId="ldap" and set name from keycloak_ldap_component_name.
- Centralize Keycloak readiness check in tasks/main.yml; remove duplicate waits from 02_update_client_redirects.yml and 04_ssh_public_key.yml.
- 01_import.yml: fix typo (keycloak), quote modes, tidy spacing, and replace Jinja-in-Jinja fileglob with concatenation.
- 02_update_client_redirects.yml: correct assert fail_msg filename; keep login-first flow.
- Minor template/vars tidy-ups (spacing, comments, consistent variable usage).

Files touched (excerpt)
- roles/*/*: replace 0755/0770 → "0755"/"0770"
- roles/web-app-keycloak/config/main.yml: add actions map
- roles/web-app-keycloak/vars/main.yml: unify Keycloak vars and feature flags
- roles/web-app-keycloak/tasks/{01_import,02_update_client_redirects,03_update-ldap-bind,04_ssh_public_key,main}.yml
- roles/web-app-keycloak/templates/{docker-compose.yml.j2,import/realm.json.j2}

https://chatgpt.com/share/689bda16-b138-800f-8258-e13f6d7d8239
2025-08-13 02:20:38 +02:00

156 lines
5.7 KiB
YAML

---
- name: Load bridges configuration
include_vars:
file: "bridges.yml"
- name: Filter enabled bridges and register as fact
set_fact:
bridges: "{{ bridges_configuration | filter_enabled_bridges(applications | get_app_conf(application_id, 'plugins', True)) }}"
changed_when: false
- name: "load docker and db for {{application_id}}"
include_role:
name: cmp-db-docker
- name: "include role for {{application_id}} to receive certs & do modification routines"
include_role:
name: srv-web-7-6-composer
vars:
domain: "{{domains[application_id].synapse}}"
http_port: "{{ports.localhost.http['web-app-matrix_synapse']}}"
- name: create {{well_known_directory}}
file:
path: "{{well_known_directory}}"
state: directory
mode: '0755'
- name: create {{well_known_directory}}server
template:
src: "well-known.j2"
dest: "{{well_known_directory}}server"
- name: create {{domains[application_id].synapse}}.conf
template:
src: "templates/nginx.conf.j2"
dest: "{{nginx.directories.http.servers}}{{domains[application_id].synapse}}.conf"
vars:
domain: "{{domains[application_id].synapse}}" # Didn't work in the past. May it works now. This does not seem to work @todo Check how to solve without declaring set_fact, seems a bug at templates
http_port: "{{ports.localhost.http['web-app-matrix_synapse']}}"
notify: restart openresty
- name: "include role srv-proxy-6-6-domain for {{application_id}}"
include_role:
name: srv-proxy-6-6-domain
vars:
domain: "{{domains[application_id].element}}"
http_port: "{{ports.localhost.http['web-app-matrix_element']}}"
- name: include create-and-seed-database.yml for multiple bridges
include_tasks: create-and-seed-database.yml
vars:
database_password: "{{ item.database_password }}"
database_username: "{{ item.database_username }}"
database_name: "{{ item.database_name }}"
loop: "{{ bridges }}"
# The following taks are necessary because a clean setup is necessary
- name: shut down docker compose project
command:
cmd: docker-compose -p "{{ matrix_project }}" down
chdir: "{{ docker_compose.directories.instance }}"
- name: "cleanup project folder"
file:
path: "{{docker_compose.directories.instance}}mautrix/"
state: absent
- name: "create bridge folders"
file:
path: "{{docker_compose.directories.instance}}mautrix/{{item.bridge_name}}"
state: directory
mode: "0755"
loop: "{{ bridges }}"
- name: add multiple mautrix bridge configuration
template:
src: "mautrix/{{item.bridge_name}}.config.yml.j2"
dest: "{{docker_compose.directories.instance}}mautrix/{{item.bridge_name}}/config.yaml"
loop: "{{ bridges }}"
notify: docker compose up
- name: add element configuration
template:
src: "element.config.json.j2"
dest: "{{docker_compose.directories.instance}}element-config.json"
notify: docker compose up
- name: add synapse homeserver configuration
template:
src: "synapse/homeserver.yaml.j2"
dest: "{{docker_compose.directories.instance}}homeserver.yaml"
notify: docker compose up
- name: add synapse log configuration
template:
src: "synapse/log.config.j2"
dest: "{{docker_compose.directories.instance}}{{domains[application_id].synapse}}.log.config"
notify: docker compose up
# https://github.com/matrix-org/synapse/issues/6303
- name: set correct folder permissions
command:
cmd: "docker run --rm --mount type=volume,src=matrix_synapse_data,dst=/data -e SYNAPSE_SERVER_NAME={{domains[application_id].synapse}} -e SYNAPSE_REPORT_STATS=no --entrypoint /bin/sh matrixdotorg/synapse:latest -c 'chown -vR 991:991 /data'"
- name: add docker-compose.yml
template:
src: "docker-compose.yml.j2"
dest: "{{docker_compose.directories.instance}}docker-compose.yml"
notify: docker compose up
# Pull image when update is wished.
# @todo This should be moved to update-docker
- name: docker compose pull
command:
cmd: docker-compose -p "{{ matrix_project }}" pull
chdir: "{{docker_compose.directories.instance}}"
when: mode_update | bool
- name: docker compose up
command:
cmd: "docker-compose -p {{ matrix_project }} up -d --remove-orphans"
chdir: "{{docker_compose.directories.instance}}"
environment:
COMPOSE_HTTP_TIMEOUT: 600
DOCKER_CLIENT_TIMEOUT: 600
register: result
until: result is succeeded
retries: 12
delay: 30
- name: wait for registration files
wait_for:
path: "{{docker_compose.directories.instance}}mautrix/{{item.bridge_name}}/registration.yaml"
state: present
timeout: 120
loop: "{{ bridges }}"
- name: "change file permissions"
file:
path: "{{docker_compose.directories.instance}}mautrix/{{item.bridge_name}}/registration.yaml"
mode: "0755"
loop: "{{ bridges }}"
- name: create admin account
command:
cmd: docker compose exec -it synapse register_new_matrix_user -u {{applications | get_app_conf(application_id, 'users.administrator.username', True)}} -p {{applications | get_app_conf(application_id, 'credentials.administrator_password', True)}} -a -c /data/homeserver.yaml http://localhost:8008
chdir: "{{ docker_compose.directories.instance }}"
ignore_errors: true
when: applications | get_app_conf(application_id, 'setup', True) | bool
- name: create chatgpt bot
command:
cmd: docker compose exec -it synapse register_new_matrix_user -u chatgptbot -p {{applications | get_app_conf(application_id, 'credentials.chatgpt_bridge_user_password', True)}} -a -c /data/homeserver.yaml http://localhost:8008
chdir: "{{ docker_compose.directories.instance }}"
ignore_errors: true
when: applications | get_app_conf(application_id, 'setup', True) | bool