| @@ -10,6 +10,7 @@ Use the following playbook configuration: | |||||
| matrix_mautrix_wsproxy_enabled: true | matrix_mautrix_wsproxy_enabled: true | ||||
| matrix_mautrix_wsproxy_appservice_token: 'random string' | matrix_mautrix_wsproxy_appservice_token: 'random string' | ||||
| matrix_mautrix_wsproxy_homeserver_token: 'random string' | matrix_mautrix_wsproxy_homeserver_token: 'random string' | ||||
| matrix_mautrix_wsproxy_syncproxy_shared_secret: 'random string' | |||||
| ``` | ``` | ||||
| @@ -1848,6 +1848,12 @@ matrix_postgres_additional_databases: | | |||||
| 'password': matrix_mautrix_signal_database_password, | 'password': matrix_mautrix_signal_database_password, | ||||
| }] if (matrix_mautrix_signal_enabled and matrix_mautrix_signal_database_engine == 'postgres' and matrix_mautrix_signal_database_hostname == 'matrix-postgres') else []) | }] if (matrix_mautrix_signal_enabled and matrix_mautrix_signal_database_engine == 'postgres' and matrix_mautrix_signal_database_hostname == 'matrix-postgres') else []) | ||||
| + | + | ||||
| ([{ | |||||
| 'name': matrix_mautrix_wsproxy_syncproxy_database_name, | |||||
| 'username': matrix_mautrix_wsproxy_syncproxy_database_username, | |||||
| 'password': matrix_mautrix_wsproxy_syncproxy_database_password, | |||||
| }] if (matrix_mautrix_wsproxy_enabled and matrix_mautrix_wsproxy_syncproxy_database_engine == 'postgres' and matrix_mautrix_wsproxy_syncproxy_database_hostname == 'matrix-postgres') else []) | |||||
| + | |||||
| ([{ | ([{ | ||||
| 'name': matrix_mautrix_telegram_database_name, | 'name': matrix_mautrix_telegram_database_name, | ||||
| 'username': matrix_mautrix_telegram_database_username, | 'username': matrix_mautrix_telegram_database_username, | ||||
| @@ -33,7 +33,7 @@ matrix_mautrix_wsproxy_systemd_wanted_services_list: [] | |||||
| matrix_mautrix_wsproxy_appservice_token: '' | matrix_mautrix_wsproxy_appservice_token: '' | ||||
| matrix_mautrix_wsproxy_homeserver_token: '' | matrix_mautrix_wsproxy_homeserver_token: '' | ||||
| matrix_mautrix_wsproxy_appservice_bot_username: imessagebot | |||||
| matrix_mautrix_wsproxy_appservice_bot_username: androidsmsbot | |||||
| # Default mautrix-wsproxy configuration template which covers the generic use case. | # Default mautrix-wsproxy configuration template which covers the generic use case. | ||||
| # You can customize it by controlling the various variables inside it. | # You can customize it by controlling the various variables inside it. | ||||
| @@ -58,7 +58,7 @@ matrix_mautrix_wsproxy_configuration_extension: "{{ matrix_mautrix_wsproxy_confi | |||||
| matrix_mautrix_wsproxy_configuration: "{{ matrix_mautrix_wsproxy_configuration_yaml|from_yaml|combine(matrix_mautrix_wsproxy_configuration_extension, recursive=True) }}" | matrix_mautrix_wsproxy_configuration: "{{ matrix_mautrix_wsproxy_configuration_yaml|from_yaml|combine(matrix_mautrix_wsproxy_configuration_extension, recursive=True) }}" | ||||
| matrix_mautrix_wsproxy_registration_yaml: | | matrix_mautrix_wsproxy_registration_yaml: | | ||||
| id: imessage | |||||
| id: androidsms | |||||
| url: {{ matrix_mautrix_wsproxy_appservice_address }} | url: {{ matrix_mautrix_wsproxy_appservice_address }} | ||||
| as_token: "{{ matrix_mautrix_wsproxy_appservice_token }}" | as_token: "{{ matrix_mautrix_wsproxy_appservice_token }}" | ||||
| hs_token: "{{ matrix_mautrix_wsproxy_homeserver_token }}" | hs_token: "{{ matrix_mautrix_wsproxy_homeserver_token }}" | ||||
| @@ -66,9 +66,37 @@ matrix_mautrix_wsproxy_registration_yaml: | | |||||
| rate_limited: false | rate_limited: false | ||||
| namespaces: | namespaces: | ||||
| users: | users: | ||||
| - regex: '@imessage_.+:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' | |||||
| - regex: '@androidsms_.+:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' | |||||
| exclusive: true | exclusive: true | ||||
| - exclusive: true | - exclusive: true | ||||
| regex: '^@{{ matrix_mautrix_wsproxy_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' | regex: '^@{{ matrix_mautrix_wsproxy_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' | ||||
| matrix_mautrix_wsproxy_registration: "{{ matrix_mautrix_wsproxy_registration_yaml|from_yaml }}" | matrix_mautrix_wsproxy_registration: "{{ matrix_mautrix_wsproxy_registration_yaml|from_yaml }}" | ||||
| # Syncproxy-related configuration fields | |||||
| matrix_mautrix_wsproxy_syncproxy_version: latest | |||||
| # See: https://mau.dev/mautrix/wsproxy/container_registry | |||||
| matrix_mautrix_wsproxy_syncproxy_docker_image: "dock.mau.dev/mautrix/syncproxy:{{ matrix_mautrix_wsproxy_syncproxy_version }}" | |||||
| matrix_mautrix_wsproxy_syncproxy_docker_image_force_pull: "{{ matrix_mautrix_wsproxy_syncproxy_docker_image.endswith(':latest') }}" | |||||
| matrix_mautrix_wsproxy_syncproxy_container_extra_arguments: [] | |||||
| matrix_mautrix_wsproxy_syncproxy_systemd_required_services_list: ['docker.service', 'matrix-mautrix-wsproxy.service'] | |||||
| matrix_mautrix_wsproxy_syncproxy_systemd_wanted_services_list: [] | |||||
| matrix_mautrix_wsproxy_syncproxy_shared_secret: '' | |||||
| matrix_mautrix_wsproxy_syncproxy_port: 29332 | |||||
| matrix_mautrix_wsproxy_syncproxy_appservice_address: "http://matrix-mautrix-wsproxy-syncproxy:{{ matrix_mautrix_wsproxy_syncproxy_port }}" | |||||
| # Database-related configuration fields | |||||
| # | |||||
| # This bridge supports Postgres and SQLite. | |||||
| # | |||||
| matrix_mautrix_wsproxy_syncproxy_database_engine: 'postgres' | |||||
| matrix_mautrix_wsproxy_syncproxy_database_username: 'matrix_mautrix_wsproxy_syncproxy' | |||||
| matrix_mautrix_wsproxy_syncproxy_database_password: 'some-password' | |||||
| matrix_mautrix_wsproxy_syncproxy_database_hostname: 'matrix-postgres' | |||||
| matrix_mautrix_wsproxy_syncproxy_database_port: 5432 | |||||
| matrix_mautrix_wsproxy_syncproxy_database_name: 'matrix_mautrix_wsproxy_syncproxy' | |||||
| matrix_mautrix_signal_wsproxy_syncproxy_connection_string: 'postgres://{{ matrix_mautrix_wsproxy_syncproxy_database_username }}:{{ matrix_mautrix_wsproxy_syncproxy_database_password }}@{{ matrix_mautrix_wsproxy_syncproxy_database_hostname }}:{{ matrix_mautrix_wsproxy_syncproxy_database_port }}/{{ matrix_mautrix_wsproxy_syncproxy_database_name }}' | |||||
| @@ -11,6 +11,9 @@ | |||||
| - ansible.builtin.set_fact: | - ansible.builtin.set_fact: | ||||
| matrix_mautrix_wsproxy_requires_restart: false | matrix_mautrix_wsproxy_requires_restart: false | ||||
| - ansible.builtin.set_fact: | |||||
| matrix_mautrix_wsproxy_syncproxy_requires_restart: false | |||||
| - name: Ensure Mautrix wsproxy image is pulled | - name: Ensure Mautrix wsproxy image is pulled | ||||
| docker_image: | docker_image: | ||||
| name: "{{ matrix_mautrix_wsproxy_docker_image }}" | name: "{{ matrix_mautrix_wsproxy_docker_image }}" | ||||
| @@ -18,6 +21,13 @@ | |||||
| force_source: "{{ matrix_mautrix_wsproxy_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" | force_source: "{{ matrix_mautrix_wsproxy_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" | ||||
| force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_wsproxy_docker_image_force_pull }}" | force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_wsproxy_docker_image_force_pull }}" | ||||
| - name: Ensure Mautrix syncproxy image is pulled | |||||
| docker_image: | |||||
| name: "{{ matrix_mautrix_wsproxy_syncproxy_docker_image }}" | |||||
| source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" | |||||
| force_source: "{{ matrix_mautrix_wsproxy_syncproxy_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" | |||||
| force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_wsproxy_syncproxy_docker_image_force_pull }}" | |||||
| - name: Ensure Mautrix wsproxy paths exists | - name: Ensure Mautrix wsproxy paths exists | ||||
| ansible.builtin.file: | ansible.builtin.file: | ||||
| path: "{{ item }}" | path: "{{ item }}" | ||||
| @@ -68,3 +78,21 @@ | |||||
| name: "matrix-mautrix-wsproxy.service" | name: "matrix-mautrix-wsproxy.service" | ||||
| state: restarted | state: restarted | ||||
| when: "matrix_mautrix_wsproxy_requires_restart|bool" | when: "matrix_mautrix_wsproxy_requires_restart|bool" | ||||
| - name: Ensure matrix-mautrix-wsproxy-syncproxy.service installed | |||||
| ansible.builtin.template: | |||||
| src: "{{ role_path }}/templates/systemd/matrix-mautrix-wsproxy-syncproxy.service.j2" | |||||
| dest: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" | |||||
| mode: 0644 | |||||
| register: matrix_mautrix_wsproxy_syncproxy_systemd_service_result | |||||
| - name: Ensure systemd reloaded after matrix-mautrix-wsproxy-syncproxy.service installation | |||||
| ansible.builtin.service: | |||||
| daemon_reload: true | |||||
| when: "matrix_mautrix_wsproxy_syncproxy_systemd_service_result.changed" | |||||
| - name: Ensure matrix-mautrix-wsproxy-syncproxy.service restarted, if necessary | |||||
| ansible.builtin.service: | |||||
| name: "matrix-mautrix-wsproxy-syncproxy.service" | |||||
| state: restarted | |||||
| when: "matrix_mautrix_wsproxy_syncproxy_requires_restart|bool" | |||||
| @@ -22,3 +22,26 @@ | |||||
| ansible.builtin.service: | ansible.builtin.service: | ||||
| daemon_reload: true | daemon_reload: true | ||||
| when: "matrix_mautrix_wsproxy_service_stat.stat.exists" | when: "matrix_mautrix_wsproxy_service_stat.stat.exists" | ||||
| - name: Check existence of matrix-mautrix-wsproxy-syncproxy service | |||||
| ansible.builtin.stat: | |||||
| path: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy-syncproxy.service" | |||||
| register: matrix_mautrix_wsproxy_syncproxy_service_stat | |||||
| - name: Ensure matrix-mautrix-wsproxy-syncproxy is stopped | |||||
| ansible.builtin.service: | |||||
| name: matrix-mautrix-wsproxy-syncproxy | |||||
| state: stopped | |||||
| daemon_reload: true | |||||
| when: "matrix_mautrix_wsproxy_syncproxy_service_stat.stat.exists" | |||||
| - name: Ensure matrix-mautrix-wsproxy-syncproxy.service doesn't exist | |||||
| ansible.builtin.file: | |||||
| path: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy-syncproxy.service" | |||||
| state: absent | |||||
| when: "matrix_mautrix_wsproxy_syncproxy_service_stat.stat.exists" | |||||
| - name: Ensure systemd reloaded after matrix-mautrix-wsproxy-syncproxy.service removal | |||||
| ansible.builtin.service: | |||||
| daemon_reload: true | |||||
| when: "matrix_mautrix_wsproxy_syncproxy_service_stat.stat.exists" | |||||
| @@ -8,3 +8,4 @@ | |||||
| with_items: | with_items: | ||||
| - "matrix_mautrix_wsproxy_appservice_token" | - "matrix_mautrix_wsproxy_appservice_token" | ||||
| - "matrix_mautrix_wsproxy_homeserver_token" | - "matrix_mautrix_wsproxy_homeserver_token" | ||||
| - "matrix_mautrix_wsproxy_syncproxy_shared_secret" | |||||
| @@ -1,5 +1,11 @@ | |||||
| listen_address: 0.0.0.0:29331 | listen_address: 0.0.0.0:29331 | ||||
| appservices: | appservices: | ||||
| - id: imessage | |||||
| - id: androidsms | |||||
| as: "{{ matrix_mautrix_wsproxy_appservice_token }}" | as: "{{ matrix_mautrix_wsproxy_appservice_token }}" | ||||
| hs: "{{ matrix_mautrix_wsproxy_homeserver_token }}" | |||||
| hs: "{{ matrix_mautrix_wsproxy_homeserver_token }}" | |||||
| sync_proxy: | |||||
| # The URL that mautrix-wsproxy can use to reach mautrix-syncproxy | |||||
| url: "{{ matrix_mautrix_wsproxy_syncproxy_appservice_address }}" | |||||
| # The URL that mautrix-syncproxy can use to reach mautrix-wsproxy | |||||
| wsproxy_url: "{{ matrix_mautrix_wsproxy_appservice_address }}" | |||||
| shared_secret: "{{ matrix_mautrix_wsproxy_syncproxy_shared_secret }}" | |||||
| @@ -0,0 +1,43 @@ | |||||
| #jinja2: lstrip_blocks: "True" | |||||
| [Unit] | |||||
| Description=Matrix Mautrix wsproxy bridge | |||||
| {% for service in matrix_mautrix_wsproxy_syncproxy_systemd_required_services_list %} | |||||
| Requires={{ service }} | |||||
| After={{ service }} | |||||
| {% endfor %} | |||||
| {% for service in matrix_mautrix_wsproxy_syncproxy_systemd_wanted_services_list %} | |||||
| Wants={{ service }} | |||||
| {% endfor %} | |||||
| DefaultDependencies=no | |||||
| [Service] | |||||
| Type=simple | |||||
| Environment="HOME={{ matrix_systemd_unit_home_path }}" | |||||
| ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mautrix-wsproxy-syncproxy 2>/dev/null' | |||||
| ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mautrix-wsproxy-syncproxy 2>/dev/null' | |||||
| # Intentional delay, so that the homeserver (we likely depend on) can manage to start. | |||||
| ExecStartPre={{ matrix_host_command_sleep }} 5 | |||||
| ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-mautrix-wsproxy-syncproxy \ | |||||
| --log-driver=none \ | |||||
| --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ | |||||
| --cap-drop=ALL \ | |||||
| --network={{ matrix_docker_network }} \ | |||||
| -p {{ matrix_mautrix_wsproxy_syncproxy_port }}:29331 \ | |||||
| -e DATABASE_URL={{ matrix_mautrix_signal_wsproxy_syncproxy_connection_string }} | |||||
| -e HOMESERVER_URL={{ matrix_homeserver_container_url }} | |||||
| -e SHARED_SECRET={{ matrix_mautrix_wsproxy_syncproxy_shared_secret }} | |||||
| {% for arg in matrix_mautrix_wsproxy_syncproxy_container_extra_arguments %} | |||||
| {{ arg }} \ | |||||
| {% endfor %} | |||||
| {{ matrix_mautrix_wsproxy_syncproxy_docker_image }} | |||||
| ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mautrix-wsproxy-syncproxy 2>/dev/null' | |||||
| ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mautrix-wsproxy-syncproxy 2>/dev/null' | |||||
| Restart=always | |||||
| RestartSec=30 | |||||
| SyslogIdentifier=matrix-mautrix-wsproxy-syncproxy | |||||
| [Install] | |||||
| WantedBy=multi-user.target | |||||
| @@ -25,7 +25,7 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-mautrix-wsprox | |||||
| --cap-drop=ALL \ | --cap-drop=ALL \ | ||||
| --network={{ matrix_docker_network }} \ | --network={{ matrix_docker_network }} \ | ||||
| -v {{ matrix_mautrix_wsproxy_config_path }}:/data:z \ | -v {{ matrix_mautrix_wsproxy_config_path }}:/data:z \ | ||||
| -p 29331:29331 \ | |||||
| -p {{ matrix_mautrix_wsproxy_port }}:29331 \ | |||||
| {% for arg in matrix_mautrix_wsproxy_container_extra_arguments %} | {% for arg in matrix_mautrix_wsproxy_container_extra_arguments %} | ||||
| {{ arg }} \ | {{ arg }} \ | ||||
| {% endfor %} | {% endfor %} | ||||