From 6fb961eb12b012dddd79b60dd8985cd5191ed21f Mon Sep 17 00:00:00 2001 From: MdotAmaan <38326222+MdotAmaan@users.noreply.github.com> Date: Thu, 28 Jul 2022 22:14:45 +0400 Subject: [PATCH] Make changes according to feedback Co-authored-by: Slavi Pantaleev Update group_vars/matrix_servers Co-authored-by: Slavi Pantaleev Remove old data migration tasks Co-authored-by: Slavi Pantaleev Update roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml Co-authored-by: Slavi Pantaleev Redo bridge permissions --- ...iguring-playbook-bridge-mautrix-discord.md | 2 ++ group_vars/matrix_servers | 4 +-- .../defaults/main.yml | 6 +++++ .../tasks/setup_install.yml | 27 ------------------- .../tasks/validate_config.yml | 10 ------- .../templates/config.yaml.j2 | 18 +++++-------- .../systemd/matrix-mautrix-discord.service.j2 | 4 +-- 7 files changed, 19 insertions(+), 52 deletions(-) diff --git a/docs/configuring-playbook-bridge-mautrix-discord.md b/docs/configuring-playbook-bridge-mautrix-discord.md index 73c762a8..46b73e0e 100644 --- a/docs/configuring-playbook-bridge-mautrix-discord.md +++ b/docs/configuring-playbook-bridge-mautrix-discord.md @@ -1,5 +1,7 @@ # Setting up Mautrix Discord (optional) +**Note**: bridging to [Discord](https://discordapp.com/) can also happen via the [mx-puppet-discord](configuring-playbook-bridge-mx-puppet-discord.md) and [matrix-appservice-discord](configuring-playbook-bridge-appservice-discord.md) bridges supported by the playbook. + The playbook can install and configure [mautrix-discord](https://github.com/mautrix/discord) for you. See the project's [documentation](https://docs.mau.fi/bridges/go/discord/index.html) to learn what it does and why it might be useful to you. diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 1d52c3ad..18bd1fc7 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -646,9 +646,9 @@ matrix_mautrix_discord_systemd_required_services_list: | (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) }} -matrix_mautrix_discord_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudiscord.as.token') | to_uuid }}" +matrix_mautrix_discord_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudisc.as.tok') | to_uuid }}" -matrix_mautrix_discord_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudiscord.hs.token') | to_uuid }}" +matrix_mautrix_discord_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudisc.hs.tok') | to_uuid }}" matrix_mautrix_discord_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" diff --git a/roles/matrix-bridge-mautrix-discord/defaults/main.yml b/roles/matrix-bridge-mautrix-discord/defaults/main.yml index a1ff83cd..dbc23031 100644 --- a/roles/matrix-bridge-mautrix-discord/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-discord/defaults/main.yml @@ -25,6 +25,12 @@ matrix_mautrix_discord_appservice_address: "http://matrix-mautrix-discord:8080" matrix_mautrix_discord_command_prefix: "!discord" +matrix_mautrix_discord_bridge_permissions: | + {{ + {matrix_mautrix_discord_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # A list of extra arguments to pass to the container matrix_mautrix_discord_container_extra_arguments: [] diff --git a/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml index 935371ef..7e2ed79c 100644 --- a/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml @@ -87,33 +87,6 @@ pull: true when: "matrix_mautrix_discord_container_image_self_build | bool" -- name: Check if an old database file exists - ansible.builtin.stat: - path: "{{ matrix_mautrix_discord_base_path }}/mautrix-discord.db" - register: matrix_mautrix_discord_stat_database - -- name: Check if an old matrix state file exists - ansible.builtin.stat: - path: "{{ matrix_mautrix_discord_base_path }}/mx-state.json" - register: matrix_mautrix_discord_stat_mx_state - -- name: (Data relocation) Ensure matrix-mautrix-discord.service is stopped - ansible.builtin.service: - name: matrix-mautrix-discord - state: stopped - enabled: false - daemon_reload: true - failed_when: false - when: "matrix_mautrix_discord_stat_database.stat.exists" - -- name: (Data relocation) Move mautrix-discord database file to ./data directory - ansible.builtin.command: "mv {{ matrix_mautrix_discord_base_path }}/mautrix-discord.db {{ matrix_mautrix_discord_data_path }}/mautrix-discord.db" - when: "matrix_mautrix_discord_stat_database.stat.exists" - -- name: (Data relocation) Move mautrix-discord mx-state file to ./data directory - ansible.builtin.command: "mv {{ matrix_mautrix_discord_base_path }}/mx-state.json {{ matrix_mautrix_discord_data_path }}/mx-state.json" - when: "matrix_mautrix_discord_stat_mx_state.stat.exists" - - name: Ensure mautrix-discord config.yaml installed ansible.builtin.copy: content: "{{ matrix_mautrix_discord_configuration | to_nice_yaml(indent=2, width=999999) }}" diff --git a/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml index ddf78524..4ba7e127 100644 --- a/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml @@ -8,13 +8,3 @@ with_items: - "matrix_mautrix_discord_appservice_token" - "matrix_mautrix_discord_homeserver_token" - - -- name: (Deprecation) Catch and report renamed settings - ansible.builtin.fail: - msg: >- - Your configuration contains a variable, which now has a different name. - Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`). - when: "item.old in vars" - with_items: - - {'old': 'matrix_mautrix_discord_log_level', 'new': 'matrix_mautrix_discord_logging_level'} diff --git a/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 index fb10b1ac..fdd4f788 100644 --- a/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 @@ -2,9 +2,9 @@ # Homeserver details. homeserver: # The address that this appservice can use to connect to the homeserver. - address: {{ matrix_mautrix_discord_homeserver_address }} + address: {{ matrix_mautrix_discord_homeserver_address | to_json }} # The domain of the homeserver (for MXIDs, etc). - domain: {{ matrix_mautrix_discord_homeserver_domain }} + domain: {{ matrix_mautrix_discord_homeserver_domain | to_json }} # Is the homeserver actually mautrix-asmux? asmux: false # The URL to push real-time bridge status to. @@ -20,7 +20,7 @@ homeserver: # Changing these values requires regeneration of the registration. appservice: # The address that the homeserver can use to connect to this appservice. - address: {{ matrix_mautrix_discord_appservice_address }} + address: {{ matrix_mautrix_discord_appservice_address | to_json }} # The hostname and port where this appservice should listen. hostname: 0.0.0.0 @@ -58,8 +58,8 @@ appservice: ephemeral_events: true # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. - as_token: "{{ matrix_mautrix_discord_appservice_token }}" - hs_token: "{{ matrix_mautrix_discord_homeserver_token }}" + as_token: {{ matrix_mautrix_discord_appservice_token | to_json }} + hs_token: {{ matrix_mautrix_discord_homeserver_token | to_json }} # Bridge config bridge: @@ -208,11 +208,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - "{{ matrix_mautrix_discord_homeserver_domain }}": user - {% if matrix_admin %} - "{{ matrix_admin }}": admin - {% endif %} + permissions: {{ matrix_mautrix_discord_bridge_permissions|to_json }} logging: directory: ./logs @@ -220,6 +216,6 @@ logging: file_date_format: "2006-01-02" file_mode: 384 timestamp_format: Jan _2, 2006 15:04:05 - print_level: {{ matrix_mautrix_discord_logging_level }} + print_level: {{ matrix_mautrix_discord_logging_level | to_json }} print_json: false file_json: false diff --git a/roles/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 b/roles/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 index 76046b44..788cd012 100644 --- a/roles/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 +++ b/roles/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 @@ -24,8 +24,8 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-mautrix-discor --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ --cap-drop=ALL \ --network={{ matrix_docker_network }} \ - -v {{ matrix_mautrix_discord_config_path }}:/config:z \ - -v {{ matrix_mautrix_discord_data_path }}:/data:z \ + --mount type=bind,src={{ matrix_mautrix_discord_config_path }},dst=/config,ro \ + --mount type=bind,src={{ matrix_mautrix_discord_data_path }},dst=/data \ --workdir=/data \ {% for arg in matrix_mautrix_discord_container_extra_arguments %} {{ arg }} \