olimp/roles/matrix/tasks/main.yml
Administrator 0b07f96e8e Update 3 files
- /roles/matrix/files/homeserver.yaml
- /roles/matrix/tasks/main.yml
- /roles/matrix/templates/docker-compose.yml.j2
2025-10-23 12:42:44 +00:00

131 lines
3.7 KiB
YAML

---
- name: Create Matrix directories
file:
path: "{{ item }}"
state: directory
mode: 0755
loop:
- "{{ matrix_base_dir }}"
- "{{ matrix_data_dir }}"
- "{{ matrix_config_dir }}"
- "{{ matrix_media_dir }}"
- "{{ matrix_postgres_dir }}"
- name: Generate Synapse configuration file
command: >
docker run --rm
-v {{ matrix_config_dir }}:/data
-e SYNAPSE_SERVER_NAME={{ matrix_server_name }}
-e SYNAPSE_REPORT_STATS={{ matrix_report_stats }}
matrixdotorg/synapse:latest
generate
args:
creates: "{{ matrix_config_dir }}/homeserver.yaml"
- name: Update homeserver.yaml with PostgreSQL configuration
blockinfile:
path: "{{ matrix_config_dir }}/homeserver.yaml"
marker: "# {mark} ANSIBLE MANAGED POSTGRES CONFIG"
block: |
database:
name: psycopg2
args:
user: {{ matrix_postgres_user }}
password: "{{ vault_matrix_postgres_password }}"
database: {{ matrix_postgres_db }}
host: matrix-postgres
cp_min: 5
cp_max: 10
sslmode: disable
- name: Update homeserver.yaml with media storage settings
blockinfile:
path: "{{ matrix_config_dir }}/homeserver.yaml"
marker: "# {mark} ANSIBLE MANAGED MEDIA CONFIG"
block: |
media_store_path: /data/media_store
uploads_path: /data/uploads
max_upload_size: "50M"
url_preview_enabled: true
- name: Update homeserver.yaml with registration settings
blockinfile:
path: "{{ matrix_config_dir }}/homeserver.yaml"
marker: "# {mark} ANSIBLE MANAGED REGISTRATION CONFIG"
block: |
enable_registration: {{ matrix_registration_enabled | bool | lower }}
registration_shared_secret: "{{ vault_matrix_synapse_secret }}"
- name: Update homeserver.yaml with additional settings
blockinfile:
path: "{{ matrix_config_dir }}/homeserver.yaml"
marker: "# {mark} ANSIBLE MANAGED ADDITIONAL CONFIG"
block: |
macaroon_secret_key: "{{ vault_matrix_macaroon_secret }}"
form_secret: "{{ vault_matrix_form_secret }}"
trusted_key_servers:
- server_name: "matrix.org"
- name: Set proper permissions on config files
file:
path: "{{ matrix_config_dir }}/homeserver.yaml"
owner: "991"
group: "991"
mode: "0644"
- name: Copy log.config to config directory
copy:
src: log.config
dest: "{{ matrix_config_dir }}/log.config"
mode: 0644
- name: Deploy Matrix docker-compose.yml
template:
src: "docker-compose.yml.j2"
dest: "{{ matrix_base_dir }}/docker-compose.yml"
mode: 0644
- name: Start Matrix services
shell: |
cd {{ matrix_base_dir }}
docker compose up -d
args:
executable: /bin/bash
- name: Wait for PostgreSQL to be ready
wait_for:
host: localhost
port: 5432
timeout: 60
delegate_to: localhost
- name: Wait for Synapse to start
pause:
seconds: 30
- name: Check Matrix container status
shell: |
docker ps --filter name=matrix-synapse
docker ps --filter name=matrix-postgres
register: matrix_status
changed_when: false
- name: Show Matrix status
debug:
var: matrix_status.stdout
- name: Register admin user (if enabled)
shell: |
cd {{ matrix_base_dir }}
docker exec matrix-synapse register_new_matrix_user http://localhost:8008 -c /data/homeserver.yaml -u admin -p "{{ vault_matrix_admin_password }}" --admin
when: matrix_registration_enabled
ignore_errors: true
become: no
- name: Show deployment info
debug:
msg: |
Matrix Synapse успешно развернут!
Сервер: {{ matrix_server_name }}
Порт: {{ matrix_port }}
PostgreSQL: matrix-postgres:5432