---
# include-gated: when: IS_COMPOSE_MODE
- name: "π§© load docker and db for {{ application_id }}"
include_role:
name: sys-stk-backend
vars:
compose_handlers_flush: false
- name: π include 02_create-and-seed-database.yml for multiple bridges
include_tasks: 02_create-and-seed-database.yml
vars:
database_password: "{{ bridge.database_password }}"
database_username: "{{ bridge.database_username }}"
database_name: "{{ bridge.database_name }}"
loop: "{{ MATRIX_BRIDGES }}"
loop_control:
loop_var: bridge
label: "{{ bridge.bridge_name }}"
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
- name: "π§Ή cleanup project folder"
file:
path: "{{ lookup('container', application_id, 'directories.instance') }}mautrix/"
state: absent
- name: "π create bridge folders"
file:
path: "{{ [ MATRIX_BRIDGE_SOURCE_DIR, item.bridge_name ] | path_join }}"
state: directory
mode: "0755"
loop: "{{ MATRIX_BRIDGES }}"
loop_control:
label: "{{ item.bridge_name }}"
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
- name: β add multiple mautrix bridge configuration
stack_host_template:
src: "flavor/compose/mautrix/{{ item.bridge_name }}.config.yml.j2"
dest: "{{ [ MATRIX_BRIDGE_SOURCE_DIR, item.bridge_name, 'config.yaml' ] | path_join }}"
loop: "{{ MATRIX_BRIDGES }}"
loop_control:
label: "{{ item.bridge_name }}"
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
notify: compose-up
- name: "β add the registration each bridge config implies"
stack_host_template:
src: "flavor/compose/mautrix/registration.yaml.j2"
dest: "{{ [ MATRIX_BRIDGE_SOURCE_DIR, item.bridge_name, 'registration.yaml' ] | path_join }}"
loop: "{{ MATRIX_BRIDGES }}"
loop_control:
label: "{{ item.bridge_name }}"
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
notify: compose-up
- name: β add element configuration
stack_host_template:
src: "flavor/compose/element.config.json.j2"
dest: "{{ MATRIX_ELEMENT_CONFIG_PATH_HOST }}"
notify: compose-up
- name: "π Render Synapse config files (local + swarm peers)"
ansible.builtin.include_tasks:
file: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/render_replicated_templates.yml') }}"
vars:
role_templates:
- src: "flavor/compose/synapse/homeserver.yaml.j2"
dest: "{{ MATRIX_SYNAPSE_CONFIG_PATH_HOST }}"
mode: "{{ MATRIX_SYNAPSE_BIND_MOUNT_MODE }}"
- src: "flavor/compose/synapse/log.config.j2"
dest: "{{ MATRIX_SYNAPSE_LOG_PATH_HOST }}"
mode: "{{ MATRIX_SYNAPSE_BIND_MOUNT_MODE }}"
- name: π§ set correct folder permissions
command:
cmd: "container run --rm --mount type=volume,src={{ MATRIX_SYNAPSE_VOLUME }},dst=/data,volume-label=com.docker.compose.project={{ application_id | entity_name
}} -e SYNAPSE_SERVER_NAME={{ MATRIX_SYNAPSE_DOMAIN }} -e SYNAPSE_REPORT_STATS=no --entrypoint /bin/sh {{ MATRIX_SYNAPSE_IMAGE }} -c 'chown -vR {{ MATRIX_SYNAPSE_UID
}}:{{ MATRIX_SYNAPSE_GID }} /data'"
- name: β add compose.yml
stack_host_template:
src: "compose.yml.j2"
dest: "{{ [ lookup('container', application_id, 'directories.instance'),'compose.yml' ] | path_join }}"
notify: compose-up
- name: "π³ compose-mode lifecycle (pull + up)"
include_tasks: 03_compose_pull_and_up.yml
when: IS_COMPOSE_MODE
- name: "πΏ Flush handlers so the stack deploys before the Synapse wait"
meta: flush_handlers
- name: β³ wait for Synapse client/versions endpoint
uri_retry:
url: "http://127.0.0.1:{{ lookup('config', application_id, 'services.synapse.ports.local.http') }}/_matrix/client/versions"
method: GET
status_code: 200
register: matrix_synapse_health
retries: 60
delay: 2
until: matrix_synapse_health.status == 200
- name: "π€ Do the stack-host-only part of the Matrix bring-up"
when: IS_STACK_HOST | bool
block:
- name: "β
Wait until Synapse reaches every bridge as ready"
ansible.builtin.shell:
cmd: >-
container exec {{ MATRIX_SYNAPSE_CONTAINER_ADDRESS }}
{{ 10 | curl(retries=0) }} --noproxy '*' -fS
http://mautrix-{{ item.bridge_name }}:{{ item.appservice_port }}/_matrix/mau/ready
executable: /bin/bash
loop: "{{ MATRIX_BRIDGES }}"
loop_control:
label: "{{ item.bridge_name }}"
register: matrix_bridge_ready
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
retries: 60
delay: 10
until: matrix_bridge_ready.rc == 0
changed_when: false
- name: "π€ Provision what only the stack host owns (accounts, bridge token, compose)"
ansible.builtin.include_tasks: utils/stack_host_provisioning.yml
- name: "π Flush all handlers after docker setup so they don't intervine with openresty"
meta: flush_handlers