| @@ -1,3 +1,4 @@ | |||
| --- | |||
| # mautrix-wsproxy is a Matrix <-> websocket bridge | |||
| # See: https://github.com/mautrix/wsproxy | |||
| @@ -1,9 +1,10 @@ | |||
| - set_fact: | |||
| --- | |||
| - ansible.builtin.set_fact: | |||
| matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-wsproxy.service'] }}" | |||
| when: matrix_mautrix_wsproxy_enabled|bool | |||
| # If the matrix-synapse role is not used, these variables may not exist. | |||
| - set_fact: | |||
| - ansible.builtin.set_fact: | |||
| matrix_synapse_container_extra_arguments: > | |||
| {{ matrix_synapse_container_extra_arguments|default([]) }} | |||
| + | |||
| @@ -17,44 +18,44 @@ | |||
| - block: | |||
| - name: Fail if matrix-nginx-proxy role already executed | |||
| fail: | |||
| msg: >- | |||
| Trying to append Mautrix Wsproxy reverse-proxying configuration to matrix-nginx-proxy, | |||
| but it's pointless since the matrix-nginx-proxy role had already executed. | |||
| To fix this, please change the order of roles in your playbook, | |||
| so that the matrix-nginx-proxy role would run after the matrix-bridge-mautrix-wsproxy role. | |||
| when: matrix_nginx_proxy_role_executed|default(False)|bool | |||
| - name: Fail if matrix-nginx-proxy role already executed | |||
| ansible.builtin.fail: | |||
| msg: >- | |||
| Trying to append Mautrix Wsproxy reverse-proxying configuration to matrix-nginx-proxy, | |||
| but it's pointless since the matrix-nginx-proxy role had already executed. | |||
| To fix this, please change the order of roles in your playbook, | |||
| so that the matrix-nginx-proxy role would run after the matrix-bridge-mautrix-wsproxy role. | |||
| when: matrix_nginx_proxy_role_executed|default(False)|bool | |||
| - name: Generate Mautrix Wsproxy proxying configuration for matrix-nginx-proxy | |||
| set_fact: | |||
| matrix_mautrix_wsproxy_matrix_nginx_proxy_configuration: | | |||
| location ~ ^/(_matrix/wsproxy/.*) { | |||
| {% if matrix_nginx_proxy_enabled|default(False) %} | |||
| {# Use the embedded DNS resolver in Docker containers to discover the service #} | |||
| resolver 127.0.0.11 valid=5s; | |||
| set $backend "matrix-mautrix-wsproxy:{{ matrix_mautrix_wsproxy_port }}"; | |||
| proxy_pass http://$backend; | |||
| {% else %} | |||
| {# Generic configuration for use outside of our container setup #} | |||
| proxy_pass http://127.0.0.1:{{ matrix_mautrix_wsproxy_port }}; | |||
| {% endif %} | |||
| } | |||
| - name: Generate Mautrix Wsproxy proxying configuration for matrix-nginx-proxy | |||
| ansible.builtin.set_fact: | |||
| matrix_mautrix_wsproxy_matrix_nginx_proxy_configuration: | | |||
| location ~ ^/(_matrix/wsproxy/.*) { | |||
| {% if matrix_nginx_proxy_enabled|default(False) %} | |||
| {# Use the embedded DNS resolver in Docker containers to discover the service #} | |||
| resolver 127.0.0.11 valid=5s; | |||
| set $backend "matrix-mautrix-wsproxy:{{ matrix_mautrix_wsproxy_port }}"; | |||
| proxy_pass http://$backend; | |||
| {% else %} | |||
| {# Generic configuration for use outside of our container setup #} | |||
| proxy_pass http://127.0.0.1:{{ matrix_mautrix_wsproxy_port }}; | |||
| {% endif %} | |||
| } | |||
| - name: Register Mautrix Wsproxy proxying configuration with matrix-nginx-proxy | |||
| set_fact: | |||
| matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | | |||
| {{ | |||
| matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) | |||
| + | |||
| [matrix_mautrix_wsproxy_matrix_nginx_proxy_configuration] | |||
| }} | |||
| - name: Register Mautrix Wsproxy proxying configuration with matrix-nginx-proxy | |||
| ansible.builtin.set_fact: | |||
| matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | | |||
| {{ | |||
| matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) | |||
| + | |||
| [matrix_mautrix_wsproxy_matrix_nginx_proxy_configuration] | |||
| }} | |||
| tags: | |||
| - always | |||
| - always | |||
| when: matrix_mautrix_wsproxy_enabled|bool | |||
| - name: Warn about reverse-proxying if matrix-nginx-proxy not used | |||
| debug: | |||
| ansible.builtin.debug: | |||
| msg: >- | |||
| NOTE: You've enabled the Mautrix wsproxy bridge but are not using the matrix-nginx-proxy | |||
| reverse proxy. | |||
| @@ -62,4 +63,3 @@ | |||
| URL endpoint to the matrix-mautrix-wsproxy container. | |||
| You can expose the container's port using the `matrix_mautrix_wsproxy_container_http_host_bind_port` variable. | |||
| when: "matrix_mautrix_wsproxy_enabled|bool and matrix_nginx_proxy_enabled is not defined" | |||
| @@ -1,3 +1,4 @@ | |||
| --- | |||
| - import_tasks: "{{ role_path }}/tasks/init.yml" | |||
| tags: | |||
| - always | |||
| @@ -3,12 +3,12 @@ | |||
| # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. | |||
| # We don't want to fail in such cases. | |||
| - name: Fail if matrix-synapse role already executed | |||
| fail: | |||
| ansible.builtin.fail: | |||
| msg: >- | |||
| The matrix-bridge-mautrix-wsproxy role needs to execute before the matrix-synapse role. | |||
| when: "matrix_synapse_role_executed|default(False)" | |||
| - set_fact: | |||
| - ansible.builtin.set_fact: | |||
| matrix_mautrix_wsproxy_requires_restart: false | |||
| - name: Ensure Mautrix wsproxy image is pulled | |||
| @@ -19,7 +19,7 @@ | |||
| force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_wsproxy_docker_image_force_pull }}" | |||
| - name: Ensure Mautrix wsproxy paths exists | |||
| file: | |||
| ansible.builtin.file: | |||
| path: "{{ item }}" | |||
| state: directory | |||
| mode: 0750 | |||
| @@ -31,12 +31,12 @@ | |||
| - "{{ matrix_mautrix_wsproxy_data_path }}" | |||
| - name: Check if an old matrix state file exists | |||
| stat: | |||
| ansible.builtin.stat: | |||
| path: "{{ matrix_mautrix_wsproxy_base_path }}/mx-state.json" | |||
| register: matrix_mautrix_wsproxy_stat_mx_state | |||
| - name: Ensure mautrix-wsproxy config.yaml installed | |||
| copy: | |||
| ansible.builtin.copy: | |||
| content: "{{ matrix_mautrix_wsproxy_configuration|to_nice_yaml }}" | |||
| dest: "{{ matrix_mautrix_wsproxy_config_path }}/config.yaml" | |||
| mode: 0644 | |||
| @@ -44,7 +44,7 @@ | |||
| group: "{{ matrix_user_groupname }}" | |||
| - name: Ensure mautrix-wsproxy registration.yaml installed | |||
| copy: | |||
| ansible.builtin.copy: | |||
| content: "{{ matrix_mautrix_wsproxy_registration|to_nice_yaml }}" | |||
| dest: "{{ matrix_mautrix_wsproxy_config_path }}/registration.yaml" | |||
| mode: 0644 | |||
| @@ -52,19 +52,19 @@ | |||
| group: "{{ matrix_user_groupname }}" | |||
| - name: Ensure matrix-mautrix-wsproxy.service installed | |||
| template: | |||
| ansible.builtin.template: | |||
| src: "{{ role_path }}/templates/systemd/matrix-mautrix-wsproxy.service.j2" | |||
| dest: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" | |||
| mode: 0644 | |||
| register: matrix_mautrix_wsproxy_systemd_service_result | |||
| - name: Ensure systemd reloaded after matrix-mautrix-wsproxy.service installation | |||
| service: | |||
| daemon_reload: yes | |||
| ansible.builtin.service: | |||
| daemon_reload: true | |||
| when: "matrix_mautrix_wsproxy_systemd_service_result.changed" | |||
| - name: Ensure matrix-mautrix-wsproxy.service restarted, if necessary | |||
| service: | |||
| ansible.builtin.service: | |||
| name: "matrix-mautrix-wsproxy.service" | |||
| state: restarted | |||
| when: "matrix_mautrix_wsproxy_requires_restart|bool" | |||
| @@ -1,24 +1,24 @@ | |||
| --- | |||
| - name: Check existence of matrix-mautrix-wsproxy service | |||
| stat: | |||
| ansible.builtin.stat: | |||
| path: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" | |||
| register: matrix_mautrix_wsproxy_service_stat | |||
| - name: Ensure matrix-mautrix-wsproxy is stopped | |||
| service: | |||
| ansible.builtin.service: | |||
| name: matrix-mautrix-wsproxy | |||
| state: stopped | |||
| daemon_reload: yes | |||
| daemon_reload: true | |||
| when: "matrix_mautrix_wsproxy_service_stat.stat.exists" | |||
| - name: Ensure matrix-mautrix-wsproxy.service doesn't exist | |||
| file: | |||
| ansible.builtin.file: | |||
| path: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" | |||
| state: absent | |||
| when: "matrix_mautrix_wsproxy_service_stat.stat.exists" | |||
| - name: Ensure systemd reloaded after matrix-mautrix-wsproxy.service removal | |||
| service: | |||
| daemon_reload: yes | |||
| ansible.builtin.service: | |||
| daemon_reload: true | |||
| when: "matrix_mautrix_wsproxy_service_stat.stat.exists" | |||
| @@ -1,11 +1,10 @@ | |||
| --- | |||
| - name: Fail if required settings not defined | |||
| fail: | |||
| ansible.builtin.fail: | |||
| msg: >- | |||
| You need to define a required configuration setting (`{{ item }}`). | |||
| when: "vars[item] == ''" | |||
| with_items: | |||
| - "matrix_mautrix_wsproxy_appservice_token" | |||
| - "matrix_mautrix_wsproxy_homeserver_token" | |||
| @@ -146,7 +146,7 @@ | |||
| when: matrix_nginx_proxy_proxy_ntfy_enabled | bool | |||
| - name: Ensure Matrix nginx-proxy configuration for mautrix wsproxy exists | |||
| template: | |||
| ansible.builtin.template: | |||
| src: "{{ role_path }}/templates/nginx/conf.d/matrix-mautrix-wsproxy.conf.j2" | |||
| dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-mautrix-wsproxy.conf" | |||
| mode: 0644 | |||
| @@ -309,7 +309,7 @@ | |||
| when: "not matrix_nginx_proxy_proxy_ntfy_enabled | bool" | |||
| - name: Ensure Matrix nginx-proxy configuration for mautrix wsproxy deleted | |||
| file: | |||
| ansible.builtin.file: | |||
| path: "{{ matrix_nginx_proxy_confd_path }}/matrix-mautrix-wsproxy.conf" | |||
| state: absent | |||
| when: "not matrix_nginx_proxy_proxy_mautrix_wsproxy_enabled|bool" | |||