diff --git a/.config/ansible-lint.yml b/.config/ansible-lint.yml new file mode 100644 index 00000000..beff4658 --- /dev/null +++ b/.config/ansible-lint.yml @@ -0,0 +1,13 @@ +--- + +use_default_rules: true + +skip_list: + - unnamed-task + - no-handler + - no-jinja-nesting + - schema + - command-instead-of-shell + - role-name + +offline: false diff --git a/.github/workflows/matrix.yml b/.github/workflows/matrix.yml index f58fe75f..aa107858 100644 --- a/.github/workflows/matrix.yml +++ b/.github/workflows/matrix.yml @@ -7,10 +7,18 @@ on: # yamllint disable-line rule:truthy jobs: yamllint: - name: 🧹 yamllint + name: yamllint runs-on: ubuntu-latest steps: - - name: ⤵️ Check out configuration from GitHub + - name: Check out uses: actions/checkout@v3 - - name: 🚀 Run yamllint - uses: frenck/action-yamllint@v1.1.2 + - name: Run yamllint + uses: frenck/action-yamllint@v1.2.0 + ansible-lint: + name: ansible-lint + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v3 + - name: Run ansible-lint + uses: ansible-community/ansible-lint-action@main diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c68ed63..c9f20ee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,200 @@ +# 2022-07-29 + +## mautrix-discord support + +Thanks to [MdotAmaan](https://github.com/MdotAmaan)'s efforts, the playbook now supports bridging to [Discord](https://discordapp.com/) via the [mautrix-discord](https://mau.dev/mautrix/discord) bridge. See our [Setting up Mautrix Discord bridging](docs/configuring-playbook-bridge-mautrix-discord.md) documentation page for getting started. + +**Note**: this is a new Discord bridge. The playbook still retains Discord bridging via [matrix-appservice-discord](docs/configuring-playbook-bridge-appservice-discord.md) and [mx-puppet-discord](docs/configuring-playbook-bridge-mx-puppet-discord.md). You're free too use the bridge that serves you better, or even all three of them (for different users and use-cases). + + +# 2022-07-27 + +## matrix-appservice-kakaotalk support + +The playbook now supports bridging to [Kakaotalk](https://www.kakaocorp.com/page/service/service/KakaoTalk?lang=ENG) via [matrix-appservice-kakaotalk](https://src.miscworks.net/fair/matrix-appservice-kakaotalk) - a bridge based on [node-kakao](https://github.com/storycraft/node-kakao) (now unmaintained) and some [mautrix-facebook](https://github.com/mautrix/facebook) code. Thanks to [hnarjis](https://github.com/hnarjis) for helping us add support for this! + +See our [Setting up Appservice Kakaotalk bridging](docs/configuring-playbook-bridge-appservice-kakaotalk.md) documentation to get started. + + +# 2022-07-20 + +## maubot support + +Thanks to [Stuart Mumford (@Cadair)](https://github.com/cadair) for starting ([PR #373](https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/373) and [PR #622](https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/622)) and to [Julian-Samuel Gebühr (@moan0s)](https://github.com/moan0s) for finishing up (in [PR #1894](https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/1894)), the playbook can now help you set up [maubot](https://github.com/maubot/maubot) - a plugin-based Matrix bot system. + +See our [Setting up maubot](docs/configuring-playbook-bot-maubot.md) documentation to get started. + + +# 2022-07-14 + +## mx-puppet-skype removal + +The playbook no longer includes the [mx-puppet-skype](https://github.com/Sorunome/mx-puppet-skype) bridge, because it has been broken and unmaintaned for a long time. Users that have `matrix_mx_puppet_skype_enabled` in their configuration files will encounter an error when running the playbook until they remove references to this bridge from their configuration. + +To completely clean up your server from `mx-puppet-skype`'s presence on it: + +- ensure your Ansible configuration (`vars.yml` file) no longer contains `matrix_mx_puppet_skype_*` references +- stop and disable the systemd service (run `systemctl disable --now matrix-mx-puppet-skype` on the server) +- delete the systemd service (run `rm /etc/systemd/system/matrix-mx-puppet-skype.service` on the server) +- delete `/matrix/mx-puppet-skype` (run `rm -rf /matrix/mx-puppet-skype` on the server) +- drop the `matrix_mx_puppet_skype` database (run `/usr/local/bin/matrix-postgres-cli` on the server, and execute the `DROP DATABASE matrix_mx_puppet_skype;` query there) + +If you still need bridging to [Skype](https://www.skype.com/), consider switching to [go-skype-bridge](https://github.com/kelaresg/go-skype-bridge) instead. See [Setting up Go Skype Bridge bridging](docs/configuring-playbook-bridge-go-skype-bridge.md). + +If you think this is a mistake and `mx-puppet-skype` works for you (or you get it to work somehow), let us know and we may reconsider this removal. + + +## signald (0.19.0+) upgrade requires data migration + +In [Pull Request #1921](https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/1921) we upgraded [signald](https://signald.org/) (used by the mautrix-signal bridge) from `v0.18.5` to `v0.20.0`. + +Back in the [`v0.19.0` released of signald](https://gitlab.com/signald/signald/-/blob/main/releases/0.19.0.md) (which we skipped and migrated straight to `v0.20.0`), a new `--migrate-data` command had been added that migrates avatars, group images, attachments, etc., into the database (those were previously stored in the filesystem). + +If you've been using the mautrix-signal bridge for a while, you may have files stored in the local filesystem, which will need to be upgraded. + +We attempt to do this data migration automatically every time Signald starts (`matrix-mautrix-signal-daemon.service`) using a `ExecStartPre` systemd unit definition. + +Keep an eye on your Signal bridge and let us know (in our [support room](README.md#support) or in [Pull Request #1921](https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/1921)) if you experience any trouble! + + +# 2022-07-05 + +## Ntfy push notifications support + +Thanks to [Julian Foad](https://matrix.to/#/@julian:foad.me.uk), the playbook can now install a [ntfy](https://ntfy.sh/) push notifications server for you. + +See our [Setting up the ntfy push notifications server](docs/configuring-playbook-ntfy.md) documentation to get started. + + +# 2022-06-23 + +## (Potential Backward Compatibility Break) Changes around metrics collection + +**TLDR**: we've made extensive **changes to metrics exposure/collection, which concern people using an external Prometheus server**. If you don't know what that is, you don't need to read below. + +**Why do major changes to metrics**? Because various services were exposing metrics in different, hacky, ways. Synapse was exposing metrics at `/_synapse/metrics` and `/_synapse-worker-.../metrics` on the `matrix.DOMAIN`. The Hookshot role was **repurposing** the Granana web UI domain (`stats.DOMAIN`) for exposing its metrics on `stats.DOMAIN/hookshot/metrics`, while protecting these routes using Basic Authentication **normally used for Synapse** (`/_synapse/metrics`). Node-exporter and Postgres-exporter roles were advising for more `stats.DOMAIN` usage in manual ways. Each role was doing things differently and mixing variables from other roles. Each metrics endpoint was ending up in a different place, protected by who knows what Basic Authentication credentials (if protected at all). + +**The solution**: a completely revamped way to expose metrics to an external Prometheus server. We are **introducing new `https://matrix.DOMAIN/metrics/*` endpoints**, where various services *can* expose their metrics, for collection by external Prometheus servers. To enable the `/metrics/*` endpoints, use `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. There's also a way to protect access using [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). See the `matrix-nginx-proxy` role or our [Collecting metrics to an external Prometheus server](docs/configuring-playbook-prometheus-grafana.md#collecting-metrics-to-an-external-prometheus-server) documentation for additional variables around `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. + +**If you are using the [Hookshot bridge](docs/configuring-playbook-bridge-hookshot.md)**, you may find that: +1. **Metrics may not be enabled by default anymore**: + - If Prometheus is enabled (`matrix_prometheus_enabled: true`), then Hookshot metrics will be enabled automatically (`matrix_hookshot_metrics_enabled: true`). These metrics will be collected from the local (in-container) Prometheus over the container network. + - **If Prometheus is not enabled** (you are either not using Prometheus or are using an external one), **Hookshot metrics will not be enabled by default anymore**. Feel free to enable them by setting `matrix_hookshot_metrics_enabled: true`. Also, see below. +2. When metrics are meant to be **consumed by an external Prometheus server**, `matrix_hookshot_metrics_proxying_enabled` needs to be set to `true`, so that metrics would be exposed (proxied) "publicly" on `https://matrix.DOMAIN/metrics/hookshot`. To make use of this, you'll also need to enable the new `https://matrix.DOMAIN/metrics/*` endpoints mentioned above, using `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. Learn more in our [Collecting metrics to an external Prometheus server](docs/configuring-playbook-prometheus-grafana.md#collecting-metrics-to-an-external-prometheus-server) documentation. +3. **We've changed the URL we're exposing Hookshot metrics at** for external Prometheus servers. Until now, you were advised to consume Hookshot metrics from `https://stats.DOMAIN/hookshot/metrics` (working in conjunction with `matrix_nginx_proxy_proxy_synapse_metrics`). From now on, **this no longer works**. As described above, you need to start consuming metrics from `https://matrix.DOMAIN/metrics/hookshot`. + +**If you're using node-exporter** (`matrix_prometheus_node_exporter_enabled: true`) and would like to collect its metrics from an external Prometheus server, see `matrix_prometheus_node_exporter_metrics_proxying_enabled` described in our [Collecting metrics to an external Prometheus server](docs/configuring-playbook-prometheus-grafana.md#collecting-metrics-to-an-external-prometheus-server) documentation. You will be able to collect its metrics from `https://matrix.DOMAIN/metrics/node-exporter`. + +**If you're using [postgres-exporter](docs/configuring-playbook-prometheus-postgres.md)** (`matrix_prometheus_postgres_exporter_enabled: true`) and would like to collect its metrics from an external Prometheus server, see `matrix_prometheus_postgres_exporter_metrics_proxying_enabled` described in our [Collecting metrics to an external Prometheus server](docs/configuring-playbook-prometheus-grafana.md#collecting-metrics-to-an-external-prometheus-server) documentation. You will be able to collect its metrics from `https://matrix.DOMAIN/metrics/postgres-exporter`. + +**If you're using Synapse** and would like to collect its metrics from an external Prometheus server, you may find that: + +1. Exposing metrics is now done using `matrix_synapse_metrics_proxying_enabled`, not `matrix_nginx_proxy_proxy_synapse_metrics: true`. You may still need to enable metrics using `matrix_synapse_metrics_enabled: true` before exposing them. +2. Protecting metrics endpoints using [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) is now done in another way. See our [Collecting metrics to an external Prometheus server](docs/configuring-playbook-prometheus-grafana.md#collecting-metrics-to-an-external-prometheus-server) documentation +3. If Synapse metrics are exposed, they will be made available at `https://matrix.DOMAIN/metrics/synapse/main-process` or `https://matrix.DOMAIN/metrics/synapse/worker/TYPE-ID` (when workers are enabled), not at `https://matrix.DOMAIN/_synapse/metrics` and `https://matrix.DOMAIN/_synapse-worker-.../metrics` +4. The playbook still generates an `external_prometheus.yml.example` sample file for scraping Synapse from Prometheus as described in [Collecting Synapse worker metrics to an external Prometheus server](docs/configuring-playbook-prometheus-grafana.md#collecting-synapse-worker-metrics-to-an-external-prometheus-server), but it's now saved under `/matrix/synapse` (not `/matrix`). + +**If you where already using a external Prometheus server** before this change, and you gave a hashed version of the password as a variable, the playbook will now take care of hashing the password for you. Thus, you need to provide the non-hashed version now. + +# 2022-06-13 + +## go-skype-bridge bridging support + +Thanks to [CyberShadow](https://github.com/CyberShadow), the playbook can now install the [go-skype-bridge](https://github.com/kelaresg/go-skype-bridge) bridge for bridging Matrix to [Skype](https://www.skype.com/). + +See our [Setting up Go Skype Bridge](docs/configuring-playbook-bridge-go-skype-bridge.md) documentation to get started. + +The playbook has supported [mx-puppet-skype](https://github.com/Sorunome/mx-puppet-skype) bridging (see [Setting up MX Puppet Skype bridging](docs/configuring-playbook-bridge-mx-puppet-skype.md)) since [2020-04-09](#2020-04-09), but `mx-puppet-skype` is reportedly broken. + + +# 2022-06-09 + +## Running Ansible in a container can now happen on the Matrix server itself + +If you're tired of being on an old and problematic Ansible version, you can now run [run Ansible in a container on the Matrix server itself](docs/ansible.md#running-ansible-in-a-container-on-the-matrix-server-itself). + + +# 2022-05-31 + +## Synapse v1.60 upgrade may cause trouble and require manual intervention + +Synapse v1.60 will try to add a new unique index to `state_group_edges` upon startup and could fail if your database is corrupted. + +We haven't observed this problem yet, but [the Synapse v1.60.0 upgrade notes](https://github.com/matrix-org/synapse/blob/v1.60.0/docs/upgrade.md#adding-a-new-unique-index-to-state_group_edges-could-fail-if-your-database-is-corrupted) mention it, so we're giving you a heads up here in case you're unlucky. + +**If Synapse fails to start** after your next playbook run, you'll need to: + +- SSH into the Matrix server +- launch `/usr/local/bin/matrix-postgres-cli` +- switch to the `synapse` database: `\c synapse` +- run the following SQL query: + +```sql +BEGIN; +DELETE FROM state_group_edges WHERE (ctid, state_group, prev_state_group) IN ( + SELECT row_id, state_group, prev_state_group + FROM ( + SELECT + ctid AS row_id, + MIN(ctid) OVER (PARTITION BY state_group, prev_state_group) AS min_row_id, + state_group, + prev_state_group + FROM state_group_edges + ) AS t1 + WHERE row_id <> min_row_id +); +COMMIT; +``` + +You could then restart services: `ansible-playbook -i inventory/hosts setup.yml --tags=start` + + +# 2022-04-25 + +## buscarron bot support + +Thanks to [Aine](https://gitlab.com/etke.cc) of [etke.cc](https://etke.cc/), the playbook can now set up [the Buscarron bot](https://gitlab.com/etke.cc/buscarron). It's a bot you can use to send any form (HTTP POST, HTML) to a (encrypted) Matrix room + +See our [Setting up Buscarron](docs/configuring-playbook-bot-buscarron.md) documentation to get started. + + +# 2022-04-21 + +## matrix-registration-bot support + +Thanks to [Julian-Samuel Gebühr (@moan0s)](https://github.com/moan0s), the playbook can now help you set up [matrix-registration-bot](https://github.com/moan0s/matrix-registration-bot) - a bot that is used to create and manage registration tokens for a Matrix server. + +See our [Setting up matrix-registration-bot](docs/configuring-playbook-bot-matrix-registration-bot.md) documentation to get started. + + +# 2022-04-19 + +## Borg backup support + +Thanks to [Aine](https://gitlab.com/etke.cc) of [etke.cc](https://etke.cc/), the playbook can now set up [Borg](https://www.borgbackup.org/) backups with [borgmatic](https://torsion.org/borgmatic/) of your Matrix server. + +See our [Setting up borg backup](docs/configuring-playbook-backup-borg.md) documentation to get started. + + +## (Compatibility Break) Upgrading to Synapse v1.57 on setups using workers may require manual action + +If you're running a worker setup for Synapse (`matrix_synapse_workers_enabled: true`), the [Synapse v1.57 upgrade notes](https://github.com/matrix-org/synapse/blob/v1.57.0rc1/docs/upgrade.md#changes-to-database-schema-for-application-services) say that you may need to take special care when upgrading: + +> Synapse v1.57.0 includes a change to the way transaction IDs are managed for application services. If your deployment uses a dedicated worker for application service traffic, **it must be stopped** when the database is upgraded (which normally happens when the main process is upgraded), to ensure the change is made safely without any risk of reusing transaction IDs. + +If you're not running an `appservice` worker (`matrix_synapse_workers_preset: little-federation-helper` or `matrix_synapse_workers_appservice_workers_count: 0`), you are probably safe to upgrade as per normal, without taking any special care. + +If you are running a setup with an `appservice` worker, or otherwise want to be on the safe side, we recommend the following upgrade path: + +0. Pull the latest playbook changes +1. Stop all services (`ansible-playbook -i inventory/hosts setup.yml --tags=stop`) +2. Re-run the playbook (`ansible-playbook -i inventory/hosts setup.yml --tags=setup-all`) +3. Start Postgres (`systemctl start matrix-postgres` on the server) +4. Start the main Synapse process (`systemctl start matrix-synapse` on the server) +5. Wait a while so that Synapse can start and complete the database migrations. You can use `journalctl -fu matrix-synapse` on the server to get a clue. Waiting a few minutes should also be enough. +6. It should now be safe to start all other services. `ansible-playbook -i inventory/hosts setup.yml --tags=start` will do it for you + + # 2022-04-14 ## (Compatibility Break) Changes to `docker-src` permissions necessitating manual action diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..f0aeb397 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: lint + +help: ## Show this help. + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' + +lint: ## Runs ansible-lint against all roles in the playbook + ansible-lint diff --git a/README.md b/README.md index 631dc297..56e3cc2d 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ Using this playbook, you can get the following services configured on your serve - (optional, advanced) the [Matrix Corporal](https://github.com/devture/matrix-corporal) reconciliator and gateway for a managed Matrix server +- (optional) the [mautrix-discord](https://github.com/mautrix/discord) bridge for bridging your Matrix server to [Discord](https://discord.com/) - see [docs/configuring-playbook-bridge-mautrix-discord.md](docs/configuring-playbook-bridge-mautrix-discord.md) for setup documentation + - (optional) the [mautrix-telegram](https://github.com/mautrix/telegram) bridge for bridging your Matrix server to [Telegram](https://telegram.org/) - (optional) the [mautrix-whatsapp](https://github.com/mautrix/whatsapp) bridge for bridging your Matrix server to [WhatsApp](https://www.whatsapp.com/) @@ -79,7 +81,7 @@ Using this playbook, you can get the following services configured on your serve - (optional) the [Heisenbridge](https://github.com/hifi/heisenbridge) for bridging your Matrix server to IRC bouncer-style - see [docs/configuring-playbook-bridge-heisenbridge.md](docs/configuring-playbook-bridge-heisenbridge.md) for setup documentation -- (optional) the [mx-puppet-skype](https://hub.docker.com/r/sorunome/mx-puppet-skype) for bridging your Matrix server to [Skype](https://www.skype.com) - see [docs/configuring-playbook-bridge-mx-puppet-skype.md](docs/configuring-playbook-bridge-mx-puppet-skype.md) for setup documentation +- (optional) the [go-skype-bridge](https://github.com/kelaresg/go-skype-bridge) for bridging your Matrix server to [Skype](https://www.skype.com) - see [docs/configuring-playbook-bridge-go-skype-bridge.md](docs/configuring-playbook-bridge-go-skype-bridge.md) for setup documentation - (optional) the [mx-puppet-slack](https://hub.docker.com/r/sorunome/mx-puppet-slack) for bridging your Matrix server to [Slack](https://slack.com) - see [docs/configuring-playbook-bridge-mx-puppet-slack.md](docs/configuring-playbook-bridge-mx-puppet-slack.md) for setup documentation @@ -89,7 +91,7 @@ Using this playbook, you can get the following services configured on your serve - (optional) the [mx-puppet-discord](https://github.com/matrix-discord/mx-puppet-discord) bridge for [Discord](https://discordapp.com/) - see [docs/configuring-playbook-bridge-mx-puppet-discord.md](docs/configuring-playbook-bridge-mx-puppet-discord.md) for setup documentation -- (optional) the [mx-puppet-groupme](https://gitlab.com/robintown/mx-puppet-groupme) bridge for [GroupMe](https://groupme.com/) - see [docs/configuring-playbook-bridge-mx-puppet-groupme.md](docs/configuring-playbook-bridge-mx-puppet-groupme.md) for setup documentation +- (optional) the [mx-puppet-groupme](https://gitlab.com/xangelix-pub/matrix/mx-puppet-groupme) bridge for [GroupMe](https://groupme.com/) - see [docs/configuring-playbook-bridge-mx-puppet-groupme.md](docs/configuring-playbook-bridge-mx-puppet-groupme.md) for setup documentation - (optional) the [mx-puppet-steam](https://github.com/icewind1991/mx-puppet-steam) bridge for [Steam](https://steamapp.com/) - see [docs/configuring-playbook-bridge-mx-puppet-steam.md](docs/configuring-playbook-bridge-mx-puppet-steam.md) for setup documentation @@ -103,6 +105,10 @@ Using this playbook, you can get the following services configured on your serve - (optional) [matrix-reminder-bot](https://github.com/anoadragon453/matrix-reminder-bot) for scheduling one-off & recurring reminders and alarms - see [docs/configuring-playbook-bot-matrix-reminder-bot.md](docs/configuring-playbook-bot-matrix-reminder-bot.md) for setup documentation +- (optional) [matrix-registration-bot](https://github.com/moan0s/matrix-registration-bot) for invitations by creating and managing registration tokens - see [docs/configuring-playbook-bot-matrix-registration-bot.md](docs/configuring-playbook-bot-matrix-registration-bot.md) for setup documentation + +- (optional) [maubot](https://github.com/maubot/maubot) a plugin-based Matrix bot system - see [docs/configuring-playbook-bot-maubot.md](docs/configuring-playbook-bot-maubot.md) for setup documentation + - (optional) [honoroit](https://gitlab.com/etke.cc/honoroit) helpdesk bot - see [docs/configuring-playbook-bot-honoroit.md](docs/configuring-playbook-bot-honoroit.md) for setup documentation - (optional) [Go-NEB](https://github.com/matrix-org/go-neb) multi functional bot written in Go - see [docs/configuring-playbook-bot-go-neb.md](docs/configuring-playbook-bot-go-neb.md) for setup documentation @@ -117,12 +123,16 @@ Using this playbook, you can get the following services configured on your serve - (optional) the [Sygnal](https://github.com/matrix-org/sygnal) push gateway - see [Setting up the Sygnal push gateway](docs/configuring-playbook-sygnal.md) for setup documentation +- (optional) the [ntfy](https://ntfy.sh) push notifications server - see [docs/configuring-playbook-ntfy.md](docs/configuring-playbook-ntfy.md) for setup documentation + - (optional) the [Hydrogen](https://github.com/vector-im/hydrogen-web) web client - see [docs/configuring-playbook-client-hydrogen.md](docs/configuring-playbook-client-hydrogen.md) for setup documentation - (optional) the [Cinny](https://github.com/ajbura/cinny) web client - see [docs/configuring-playbook-client-cinny.md](docs/configuring-playbook-client-cinny.md) for setup documentation - (optional) the [Borg](https://borgbackup.org) backup - see [docs/configuring-playbook-backup-borg.md](docs/configuring-playbook-backup-borg.md) for setup documentation +- (optional) the [Buscarron](https://gitlab.com/etke.cc/buscarron) bot - see [docs/configuring-playbook-bot-buscarron.md](docs/configuring-playbook-bot-buscarron.md) for setup documentation + Basically, this playbook aims to get you up-and-running with all the necessities around Matrix, without you having to do anything else. **Note**: the list above is exhaustive. It includes optional or even some advanced components that you will most likely not need. diff --git a/docs/alternative-architectures.md b/docs/alternative-architectures.md index a6c2a02a..c8097b60 100644 --- a/docs/alternative-architectures.md +++ b/docs/alternative-architectures.md @@ -2,7 +2,7 @@ As stated in the [Prerequisites](prerequisites.md), currently only `x86_64` is fully supported. However, it is possible to set the target architecture, and some tools can be built on the host or other measures can be used. -To that end add the following variable to your `vars.yaml` file: +To that end add the following variable to your `vars.yml` file (see [Configuring playbook](configuring-playbook.md)): ```yaml matrix_architecture: @@ -13,7 +13,7 @@ Currently supported architectures are the following: - `arm64` - `arm32` -so for the Raspberry Pi, the following should be in your `vars.yaml` file: +so for the Raspberry Pi, the following should be in your `vars.yml` file: ```yaml matrix_architecture: "arm32" diff --git a/docs/ansible.md b/docs/ansible.md index 50cf83ed..bd1fe927 100644 --- a/docs/ansible.md +++ b/docs/ansible.md @@ -30,7 +30,7 @@ Depending on your distribution, you may be able to upgrade Ansible in a few diff - by using an additional repository (PPA, etc.), which provides newer Ansible versions. See instructions for [CentOS](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-rhel-centos-or-fedora), [Debian](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-debian), or [Ubuntu](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu) on the Ansible website. -- by removing the Ansible package (`yum remove ansible` or `apt-get remove ansible`) and installing via [pip](https://pip.pypa.io/en/stable/installing/) (`pip install ansible`). +- by removing the Ansible package (`yum remove ansible` or `apt-get remove ansible`) and installing via [pip](https://pip.pypa.io/en/stable/installation/) (`pip install ansible`). If using the `pip` method, do note that the `ansible-playbook` binary may not be on the `$PATH` (https://linuxconfig.org/linux-path-environment-variable), but in some more special location like `/usr/local/bin/ansible-playbook`. You may need to invoke it using the full path. @@ -41,9 +41,50 @@ If you find yourself needing to resort to such hacks, please consider reporting ## Using Ansible via Docker -Alternatively, you can run Ansible on your computer from inside a Docker container (powered by the [devture/ansible](https://hub.docker.com/r/devture/ansible/) Docker image). +Alternatively, you can run Ansible inside a Docker container (powered by the [devture/ansible](https://hub.docker.com/r/devture/ansible/) Docker image). -Here's a sample command to get you started (run this from the playbook's directory): +This ensures that you're using a very recent Ansible version, which is less likely to be incompatible with the playbook. + +There are 2 ways to go about it: + +- [Running Ansible in a container on the Matrix server itself](#running-ansible-in-a-container-on-the-matrix-server-itself) +- [Running Ansible in a container on another computer (not the Matrix server)](#running-ansible-in-a-container-on-another-computer-not-the-matrix-server) + + +### Running Ansible in a container on the Matrix server itself + +To run Ansible in a (Docker) container on the Matrix server itself, you need to have a working Docker installation. +Docker is normally installed by the playbook, so this may be a bit of a chicken and egg problem. To solve it: + +- you **either** need to install Docker manually first. Follow [the upstream instructions](https://docs.docker.com/engine/install/) for your distribution and consider setting `matrix_docker_installation_enabled: false` in your `vars.yml` file, to prevent the playbook from installing Docker +- **or** you need to run the playbook in another way (e.g. [Running Ansible in a container on another computer (not the Matrix server)](#running-ansible-in-a-container-on-another-computer-not-the-matrix-server)) at least the first time around + +Once you have a working Docker installation on the server, **clone the playbook** somewhere on the server and configure it as per usual (`inventory/hosts`, `inventory/host_vars/..`, etc.), as described in [configuring the playbook](configuring-playbook.md). + +You would then need to add `ansible_connection=community.docker.nsenter` to the host line in `inventory/hosts`. This tells Ansible to connect to the "remote" machine by switching Linux namespaces with [nsenter](https://man7.org/linux/man-pages/man1/nsenter.1.html), instead of using SSH. +Alternatively, you can leave your `inventory/hosts` as is and specify the connection type in **each** `ansible-playbook` call you do later, like this: `ansible-playbook --connection=community.docker.nsenter ...` + +Run this from the playbook's directory: + +```bash +docker run -it --rm \ +--privileged \ +--pid=host \ +-w /work \ +-v `pwd`:/work \ +--entrypoint=/bin/sh \ +docker.io/devture/ansible:2.13.0-r0 +``` + +Once you execute the above command, you'll be dropped into a `/work` directory inside a Docker container. +The `/work` directory contains the playbook's code. + +You can execute `ansible-playbook ...` (or `ansible-playbook --connection=community.docker.nsenter ...`) commands as per normal now. + + +### Running Ansible in a container on another computer (not the Matrix server) + +Run this from the playbook's directory: ```bash docker run -it --rm \ @@ -51,7 +92,7 @@ docker run -it --rm \ -v `pwd`:/work \ -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa:ro \ --entrypoint=/bin/sh \ -docker.io/devture/ansible:2.11.6-r1 +docker.io/devture/ansible:2.13.0-r0 ``` The above command tries to mount an SSH key (`$HOME/.ssh/id_rsa`) into the container (at `/root/.ssh/id_rsa`). @@ -60,9 +101,9 @@ If your SSH key is at a different path (not in `$HOME/.ssh/id_rsa`), adjust that Once you execute the above command, you'll be dropped into a `/work` directory inside a Docker container. The `/work` directory contains the playbook's code. -You can execute `ansible-playbook` commands as per normal now. +You can execute `ansible-playbook ...` commands as per normal now. -### If you don't use SSH keys for authentication +#### If you don't use SSH keys for authentication If you don't use SSH keys for authentication, simply remove that whole line (`-v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa:ro`). To authenticate at your server using a password, you need to add a package. So, when you are in the shell of the ansible docker container (the previously used `docker run -it ...` command), run: diff --git a/docs/assets/obtain_admin_access_token_element.png b/docs/assets/obtain_admin_access_token_element.png new file mode 100644 index 00000000..2204ff39 Binary files /dev/null and b/docs/assets/obtain_admin_access_token_element.png differ diff --git a/docs/configuring-dns.md b/docs/configuring-dns.md index c16ab2fc..ca7c08b0 100644 --- a/docs/configuring-dns.md +++ b/docs/configuring-dns.md @@ -36,8 +36,10 @@ If you are using Cloudflare DNS, make sure to disable the proxy and set all reco | CNAME | `stats` | - | - | - | `matrix.` | | CNAME | `goneb` | - | - | - | `matrix.` | | CNAME | `sygnal` | - | - | - | `matrix.` | +| CNAME | `ntfy` | - | - | - | `matrix.` | | CNAME | `hydrogen` | - | - | - | `matrix.` | | CNAME | `cinny` | - | - | - | `matrix.` | +| CNAME | `buscarron` | - | - | - | `matrix.` | ## Subdomains setup @@ -56,10 +58,14 @@ The `goneb.` subdomain may be necessary, because this playbook coul The `sygnal.` subdomain may be necessary, because this playbook could install the [Sygnal](https://github.com/matrix-org/sygnal) push gateway. The installation of Sygnal is disabled by default, it is not a core required component. To learn how to install it, see our [configuring Sygnal guide](configuring-playbook-sygnal.md). If you do not wish to set up Sygnal (you probably don't, unless you're also developing/building your own Matrix apps), feel free to skip the `sygnal.` DNS record. +The `ntfy.` subdomain may be necessary, because this playbook could install the [ntfy](https://ntfy.sh/) UnifiedPush-compatible push notifications server. The installation of ntfy is disabled by default, it is not a core required component. To learn how to install it, see our [configuring ntfy guide](configuring-playbook-ntfy.md). If you do not wish to set up ntfy, feel free to skip the `ntfy.` DNS record. + The `hydrogen.` subdomain may be necessary, because this playbook could install the [Hydrogen](https://github.com/vector-im/hydrogen-web) web client. The installation of Hydrogen is disabled by default, it is not a core required component. To learn how to install it, see our [configuring Hydrogen guide](configuring-playbook-client-hydrogen.md). If you do not wish to set up Hydrogen, feel free to skip the `hydrogen.` DNS record. The `cinny.` subdomain may be necessary, because this playbook could install the [Cinny](https://github.com/ajbura/cinny) web client. The installation of cinny is disabled by default, it is not a core required component. To learn how to install it, see our [configuring cinny guide](configuring-playbook-client-cinny.md). If you do not wish to set up cinny, feel free to skip the `cinny.` DNS record. +The `buscarron.` subdomain may be necessary, because this playbook could install the [buscarron](https://gitlab.com/etke.cc/buscarron) bot. The installation of buscarron is disabled by default, it is not a core required component. To learn how to install it, see our [configuring buscarron guide](configuring-playbook-bot-buscarron.md). If you do not wish to set up buscarron, feel free to skip the `buscarron.` DNS record. + ## `_matrix-identity._tcp` SRV record setup To make the [ma1sd](https://github.com/ma1uta/ma1sd) Identity Server (which this playbook may optionally install for you) enable its federation features, set up an SRV record that looks like this: diff --git a/docs/configuring-playbook-backup-borg.md b/docs/configuring-playbook-backup-borg.md index 4177c561..41ca0156 100644 --- a/docs/configuring-playbook-backup-borg.md +++ b/docs/configuring-playbook-backup-borg.md @@ -8,6 +8,9 @@ You will need a remote server where borg will store the backups. There are hoste The backup will run based on `matrix_backup_borg_schedule` var (systemd timer calendar), default: 4am every day. +By default, if you're using the integrated Postgres database server (as opposed to [an external Postgres server](configuring-playbook-external-postgres.md)), Borg backups will also include dumps of your Postgres database. An alternative solution for backing up the Postgres database is [postgres backup](configuring-playbook-postgres-backup.md). If you decide to go with another solution, you can disable Postgres-backup support for Borg using the `matrix_backup_borg_postgresql_enabled` variable. + + ## Prerequisites 1. Create a new SSH key: @@ -40,7 +43,13 @@ matrix_backup_borg_location_repositories: - USER@HOST:REPO matrix_backup_borg_storage_encryption_passphrase: "PASSPHRASE" matrix_backup_borg_ssh_key_private: | - PRIVATE KEY + -----BEGIN OPENSSH PRIVATE KEY----- + TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZW + xpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRv + bG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlzIG5vc3 + RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1aXAgZXgg + ZWEgY29tbW9kbyBjb25zZXF1YXQuIA== + -----END OPENSSH PRIVATE KEY----- ``` where: @@ -49,7 +58,7 @@ where: * HOST - SSH host of a provider/server * REPO - borg repository name, it will be initialized on backup start, eg: `matrix` * PASSPHRASE - passphrase used for encrypting backups, you may generate it with `pwgen -s 64 1` or use any password manager -* PRIVATE KEY - the content of the **private** part of the SSH key you created before +* PRIVATE KEY - the content of the **private** part of the SSH key you created before. The whole key (all of its belonging lines) under `matrix_backup_borg_ssh_key_private` needs to be indented with 2 spaces To backup without encryption, add `matrix_backup_borg_encryption: 'none'` to your vars. This will also enable the `matrix_backup_borg_unknown_unencrypted_repo_access_is_ok` variable. diff --git a/docs/configuring-playbook-bot-buscarron.md b/docs/configuring-playbook-bot-buscarron.md new file mode 100644 index 00000000..3a5822ab --- /dev/null +++ b/docs/configuring-playbook-bot-buscarron.md @@ -0,0 +1,75 @@ +# Setting up Buscarron (optional) + +The playbook can install and configure [buscarron](https://gitlab.com/etke.cc/buscarron) for you. + +It's a bot you can use to setup **your own helpdesk on matrix** +It's a bot you can use to send any form (HTTP POST, HTML) to a (encrypted) matrix room + +## Registering the bot user + +By default, the playbook will set up the bot with a username like this: `@bot.buscarron:DOMAIN`. + +(to use a different username, adjust the `matrix_bot_buscarron_login` variable). + +You **need to register the bot user manually** before setting up the bot. You can use the playbook to [register a new user](registering-users.md): + +``` +ansible-playbook -i inventory/hosts setup.yml --extra-vars='username=bot.buscarron password=PASSWORD_FOR_THE_BOT admin=no' --tags=register-user +``` + +Choose a strong password for the bot. You can generate a good password with a command like this: `pwgen -s 64 1`. + + +## Adjusting the playbook configuration + +Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file: + +```yaml +matrix_bot_buscarron_enabled: true + +# Adjust this to whatever password you chose when registering the bot user +matrix_bot_buscarron_password: PASSWORD_FOR_THE_BOT + +# Adjust accepted forms +matrix_bot_buscarron_forms: + - name: contact # (mandatory) Your form name, will be used as endpoint, eg: buscarron.DOMAIN/contact + room: "!yourRoomID:DOMAIN" # (mandatory) Room ID where form submission will be posted + redirect: https://DOMAIN # (mandatory) To what page user will be redirected after the form submission + ratelimit: 1r/m # (optional) rate limit of the form, format: r/, eg: 1r/s or 54r/m + extensions: [] # (optional) list of form extensions (not used yet) + +matrix_bot_buscarron_spam_hosts: [] # (optional) list of email domains/hosts that should be rejected automatically +matrix_bot_buscarron_spam_emails: [] # (optional) list of email addresses that should be rejected automatically +``` + +You will also need to add a DNS record so that buscarron can be accessed. +By default buscarron will use https://buscarron.DOMAIN so you will need to create an CNAME record for `buscarron`. +See [Configuring DNS](configuring-dns.md). + +If you would like to use a different domain, add the following to your configuration file (changing it to use your preferred domain): + +```yaml +matrix_server_fqn_buscarron: "form.{{ matrix_domain }}" +``` + + +## Installing + +After configuring the playbook, run the [installation](installing.md) command again: + +``` +ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start +``` + + +## Usage + +To use the bot, invite the `@bot.buscarron:DOMAIN` to the room you specified in a config, after that any point your form to the form url, example for the `contact` form: + +```html +
+ +
+``` + +You can also refer to the upstream [documentation](https://gitlab.com/etke.cc/buscarron). diff --git a/docs/configuring-playbook-bot-matrix-registration-bot.md b/docs/configuring-playbook-bot-matrix-registration-bot.md new file mode 100644 index 00000000..c47d5bfd --- /dev/null +++ b/docs/configuring-playbook-bot-matrix-registration-bot.md @@ -0,0 +1,72 @@ +# Setting up matrix-registration-bot (optional) + +The playbook can install and configure [matrix-registration-bot](https://github.com/moan0s/matrix-registration-bot) for you. + +The bot allows you to easily **create and manage registration tokens**. It can be used for an invitation-based server, +where you invite someone by sending them a registration token. They can register as normal but have to provide a valid +registration token in a final step of the registration. + +See the project's [documentation](https://github.com/moan0s/matrix-registration-bot#supported-commands) to learn what it +does and why it might be useful to you. + + +## Registering the bot user + +By default, the playbook will set use the bot with a username like this: `@bot.matrix-registration-bot:DOMAIN`. + +(to use a different username, adjust the `matrix_bot_matrix_registration_bot_matrix_user_id_localpart` variable). + +You **need to register the bot user manually** before setting up the bot. You can use the playbook to [register a new user](registering-users.md): + +``` +ansible-playbook -i inventory/hosts setup.yml --extra-vars='username=bot.matrix-registration-bot password=PASSWORD_FOR_THE_BOT admin=yes' --tags=register-user +``` + +Choose a strong password for the bot. You can generate a good password with a command like this: `pwgen -s 64 1`. + +## Obtaining an admin access token + +In order to use the bot you need to add an admin user's access token token to the configuration. As you created an admin user for the +bot, it is recommended to obtain an access token by logging into Element/Schildichat with the bot account +(using the password you set) and navigate to `Settings->Help&About` and scroll to the bottom. +You can expand "Access token" to copy it. + +![Obatining an admin access token with Element](assets/obtain_admin_access_token_element.png) + +**IMPORTANT**: once you copy the token, just close the Matrix client window/tab. Do not "log out", as that would invalidate the token. + +## Adjusting the playbook configuration + +Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file: + +```yaml +matrix_bot_matrix_registration_bot_enabled: true +# Token obtained via logging into the bot account (see above) +matrix_bot_matrix_registration_bot_bot_access_token: "syt_bW9hbm9z_XXXXXXXXXXXXXr_2kuzbE" + +# Enables registration +matrix_synapse_enable_registration: true + +# Restrict registration to users with a token +matrix_synapse_registration_requires_token: true +``` + + +## Installing + +After configuring the playbook, run the [installation](installing.md) command again: + +``` +ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start +``` + + +## Usage + +To use the bot, create a **non-encrypted** room and invite `@bot.matrix-registration-bot:DOMAIN` (where `YOUR_DOMAIN` is your base domain, not the `matrix.` domain). + +In this room send `help` and the bot will reply with all options. + +You can also refer to the upstream [Usage documentation](https://github.com/moan0s/matrix-registration-bot#supported-commands). +If you have any questions, or if you need help setting it up, read the [troublshooting guide](https://github.com/moan0s/matrix-registration-bot/blob/main/docs/troubleshooting.md) +or join [#matrix-registration-bot:hyteck.de](https://matrix.to/#/#matrix-registration-bot:hyteck.de). diff --git a/docs/configuring-playbook-bot-maubot.md b/docs/configuring-playbook-bot-maubot.md new file mode 100644 index 00000000..d5990a11 --- /dev/null +++ b/docs/configuring-playbook-bot-maubot.md @@ -0,0 +1,63 @@ +# Setting up maubot (optional) + +The playbook can install and configure [maubot](https://github.com/maubot/maubot) for you. + +After setting up maubot, you can use the web management interface to make it do things. +The default location of the management interface is `matrix./_matrix/maubot/` + +See the project's [documentation](https://docs.mau.fi/maubot/usage/basic.html) to learn what it +does and why it might be useful to you. + +## Adjusting the playbook configuration + +Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file: + +```yaml +matrix_bot_maubot_enabled: true +matrix_bot_maubot_admins: + - yourusername: securepassword +``` + +You can add multiple admins. The admin accounts are not connected to any matrix ID and are only used to access the +maubot administration interface. + + +## Installing + +After configuring the playbook, run the [installation](installing.md) command again: + +``` +ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start +``` + +## Usage + +You can visit `matrix./_matrix/maubot/` to manage your available plugins, clients and instances. + +You should start in the following order +1. **Create one or more clients:** A client is a matrix account which the bot will use to message. +2. **Upload some Plugins:** Plugins can be obtained from [here](https://github.com/maubot/maubot#plugins) or any other source. +3. **Create an instance:** An instance is the actual bot. You have to specify a client which the bot instance will use +and the plugin (how the bot will behave) + +To add a client you first need to create an account and obtain a valid access token. + +## Registering the bot user + +You **need to register the bot user manually** before setting up the bot. You can use the playbook to [register a new user](registering-users.md): + +``` +ansible-playbook -i inventory/hosts setup.yml --extra-vars='username=bot.maubot password=PASSWORD_FOR_THE_BOT admin=yes' --tags=register-user +``` + +Choose a strong password for the bot. You can generate a good password with a command like this: `pwgen -s 64 1`. + +## Obtaining an admin access token + +This can be done via `mbc auth` (see the [maubot documentation](https://docs.mau.fi/maubot/usage/cli/auth.html)) or by logging into Element/Schildichat with the bot account +(using the password you set) and navigate to `Settings->Help&About` and scroll to the bottom. +You can expand "Access token" to copy it. + +![Obatining an admin access token with Element](assets/obtain_admin_access_token_element.png) + +**IMPORTANT**: once you copy the token, just close the Matrix client window/tab. Do not "log out", as that would invalidate the token. diff --git a/docs/configuring-playbook-bridge-appservice-discord.md b/docs/configuring-playbook-bridge-appservice-discord.md index e25686bf..d37724c0 100644 --- a/docs/configuring-playbook-bridge-appservice-discord.md +++ b/docs/configuring-playbook-bridge-appservice-discord.md @@ -1,6 +1,8 @@ # Setting up Appservice Discord (optional) -**Note**: bridging to [Discord](https://discordapp.com/) can also happen via the [mx-puppet-discord](configuring-playbook-bridge-mx-puppet-discord.md) bridge supported by the playbook. +**Note**: bridging to [Discord](https://discordapp.com/) can also happen via the [mx-puppet-discord](configuring-playbook-bridge-mx-puppet-discord.md) and [mautrix-discord](configuring-playbook-bridge-mautrix-discord.md) bridges supported by the playbook. +- For using as a Bot we are recommend the Appservice Discord bridge (the one being discussed here), because it supports plumbing. +- For personal use we recommend the [mautrix-discord](configuring-playbook-bridge-mautrix-discord.md) bridge, because it is the most fully-featured and stable of the 3 Discord bridges supported by the playbook. The playbook can install and configure [matrix-appservice-discord](https://github.com/Half-Shot/matrix-appservice-discord) for you. @@ -61,7 +63,7 @@ To get started with Portal Bridging: 1. To invite the bot to Discord, retrieve the invite link from the `{{ matrix_appservice_discord_config_path }}/invite_link` file on the server (this defaults to `/matrix/appservice-discord/config/invite_link`). You need to peek at the file on the server via SSH, etc., because it's not available via HTTP(S). 2. Room addresses follow this syntax: `#_discord__`. You can easily find the guild and channel IDs by logging into Discord in a browser and opening the desired channel. The URL will have this format: `discord.com/channels//`. -3. Once you have figured out the appropriate room address, you can join by doing `/join #_discord__` in your Matrix client. +3. Once you have figured out the appropriate room address, you can join by doing `/join #_discord__` in your Matrix client. ## Getting Administrator access in a portal bridged room diff --git a/docs/configuring-playbook-bridge-appservice-kakaotalk.md b/docs/configuring-playbook-bridge-appservice-kakaotalk.md new file mode 100644 index 00000000..9ea7a3d1 --- /dev/null +++ b/docs/configuring-playbook-bridge-appservice-kakaotalk.md @@ -0,0 +1,68 @@ +# Setting up Appservice Kakaotalk (optional) + +The playbook can install and configure [matrix-appservice-kakaotalk](https://src.miscworks.net/fair/matrix-appservice-kakaotalk) for you. `matrix-appservice-kakaotalk` is a bridge to [Kakaotalk](https://www.kakaocorp.com/page/service/service/KakaoTalk?lang=ENG) based on [node-kakao](https://github.com/storycraft/node-kakao) (now unmaintained) and some [mautrix-facebook](https://github.com/mautrix/facebook) code. + +See the project's [documentation](https://src.miscworks.net/fair/matrix-appservice-kakaotalk) to learn what it does and why it might be useful to you. + + +## Installing + +To enable the bridge, add this to your `vars.yml` file: + +```yaml +matrix_appservice_kakaotalk_enabled: true +``` + +You may optionally wish to add some [Additional configuration](#additional-configuration), or to [prepare for double-puppeting](#set-up-double-puppeting) before the initial installation. + +After adjusting your `vars.yml` file, re-run the playbook and restart all services: `ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start` + +To make use of the Kakaotalk bridge, see [Usage](#usage) below. + + +### Additional configuration + +There are some additional things you may wish to configure about the bridge. + +Take a look at: + +- `roles/matrix-bridge-appservice-kakaotalk/defaults/main.yml` for some variables that you can customize via your `vars.yml` file +- `roles/matrix-bridge-appservice-kakaotalk/templates/config.yaml.j2` for the bridge's default configuration. You can override settings (even those that don't have dedicated playbook variables) using the `matrix_appservice_kakaotalk_configuration_extension_yaml` variable + + +### Set up Double Puppeting + +If you'd like to use [Double Puppeting](https://docs.mau.fi/bridges/general/double-puppeting.html) (hint: you most likely do), you have 2 ways of going about it. + +#### Method 1: automatically, by enabling Shared Secret Auth + +The bridge will automatically perform Double Puppeting if you enable [Shared Secret Auth](configuring-playbook-shared-secret-auth.md) for this playbook. + +This is the recommended way of setting up Double Puppeting, as it's easier to accomplish, works for all your users automatically, and has less of a chance of breaking in the future. + +#### Method 2: manually, by asking each user to provide a working access token + +**Note**: This method for enabling Double Puppeting can be configured only after you've already set up bridging (see [Usage](#usage)). + +When using this method, **each user** that wishes to enable Double Puppeting needs to follow the following steps: + +- retrieve a Matrix access token for yourself. You can use the following command: + +``` +curl \ +--data '{"identifier": {"type": "m.id.user", "user": "YOUR_MATRIX_USERNAME" }, "password": "YOUR_MATRIX_PASSWORD", "type": "m.login.password", "device_id": "Appservice-Kakaotalk", "initial_device_display_name": "Appservice-Kakaotalk"}' \ +https://matrix.DOMAIN/_matrix/client/r0/login +``` + +- send the access token to the bot. Example: `login-matrix MATRIX_ACCESS_TOKEN_HERE` + +- make sure you don't log out the `Appservice-Kakaotalk` device some time in the future, as that would break the Double Puppeting feature + + +## Usage + +Start a chat with `@kakaotalkbot:YOUR_DOMAIN` (where `YOUR_DOMAIN` is your base domain, not the `matrix.` domain). + +Send `login --save EMAIL_OR_PHONE_NUMBER` to the bridge bot to enable bridging for your Kakaotalk account. The `--save` flag may be omitted, if you'd rather not save your password. + +After successfully enabling bridging, you may wish to [set up Double Puppeting](#set-up-double-puppeting), if you haven't already done so. diff --git a/docs/configuring-playbook-bridge-go-skype-bridge.md b/docs/configuring-playbook-bridge-go-skype-bridge.md new file mode 100644 index 00000000..a7a4fbc8 --- /dev/null +++ b/docs/configuring-playbook-bridge-go-skype-bridge.md @@ -0,0 +1,23 @@ +# Setting up Go Skype Bridge (optional) + +The playbook can install and configure +[go-skype-bridge](https://github.com/kelaresg/go-skype-bridge) for you. + +See the project page to learn what it does and why it might be useful to you. + +To enable the [Skype](https://www.skype.com/) bridge just use the following +playbook configuration: + + +```yaml +matrix_go_skype_bridge_enabled: true +``` + + +## Usage + +Once the bot is enabled, you need to start a chat with `Skype bridge bot` +with the handle `@skypebridgebot:YOUR_DOMAIN` (where `YOUR_DOMAIN` is your base +domain, not the `matrix.` domain). + +Send `help` to the bot to see the commands available. diff --git a/docs/configuring-playbook-bridge-hookshot.md b/docs/configuring-playbook-bridge-hookshot.md index 38e13a8a..3e8a54a2 100644 --- a/docs/configuring-playbook-bridge-hookshot.md +++ b/docs/configuring-playbook-bridge-hookshot.md @@ -4,19 +4,19 @@ The playbook can install and configure [matrix-hookshot](https://github.com/matr Hookshot can bridge [Webhooks](https://en.wikipedia.org/wiki/Webhook) from software project management services such as GitHub, GitLab, JIRA, and Figma, as well as generic webhooks. -See the project's [documentation](https://matrix-org.github.io/matrix-hookshot/hookshot.html) to learn what it does in detail and why it might be useful to you. +See the project's [documentation](https://matrix-org.github.io/matrix-hookshot/latest/hookshot.html) to learn what it does in detail and why it might be useful to you. Note: the playbook also supports [matrix-appservice-webhooks](configuring-playbook-bridge-appservice-webhooks.md), which however is soon to be archived by its author and to be replaced by hookshot. ## Setup Instructions -Refer to the [official instructions](https://matrix-org.github.io/matrix-hookshot/setup.html) to learn what the individual options do. +Refer to the [official instructions](https://matrix-org.github.io/matrix-hookshot/latest/setup.html) to learn what the individual options do. 1. For each of the services (GitHub, GitLab, Jira, Figma, generic webhooks) fill in the respective variables `matrix_hookshot_service_*` listed in [main.yml](/roles/matrix-bridge-hookshot/defaults/main.yml) as required. 2. Take special note of the `matrix_hookshot_*_enabled` variables. Services that need no further configuration are enabled by default (GitLab, Generic), while you must first add the required configuration and enable the others (GitHub, Jira, Figma). -3. If you're setting up the GitHub bridge, you'll need to generate and download a private key file after you created your GitHub app. Copy the contents of that file to the variable `matrix_hookshot_github_private_key` so the playbook can install it for you, or use one of the [other methods](#manage-github-private-key-with-matrix-aux-role) explained below. +3. If you're setting up the GitHub bridge, you'll need to generate and download a private key file after you created your GitHub app. Copy the contents of that file to the variable `matrix_hookshot_github_private_key` so the playbook can install it for you, or use one of the [other methods](#manage-github-private-key-with-matrix-aux-role) explained below. 4. If you've already installed Matrix services using the playbook before, you'll need to re-run it (`--tags=setup-all,start`). If not, proceed with [configuring other playbook services](configuring-playbook.md) and then with [Installing](installing.md). Get back to this guide once ready. Hookshot can be set up individually using the tag `setup-hookshot`. -5. Refer to [Hookshot's official instructions](https://matrix-org.github.io/matrix-hookshot/usage.html) to start using the bridge. **Important:** Note that the different listeners are bound to certain paths which might differe from those assumed by the hookshot documentation, see [URLs for bridges setup](urls-for-bridges-setup) below. +5. Refer to [Hookshot's official instructions](https://matrix-org.github.io/matrix-hookshot/latest/usage.html) to start using the bridge. **Important:** Note that the different listeners are bound to certain paths which might differ from those assumed by the hookshot documentation, see [URLs for bridges setup](urls-for-bridges-setup) below. Other configuration options are available via the `matrix_hookshot_configuration_extension_yaml` and `matrix_hookshot_registration_extension_yaml` variables, see the comments in [main.yml](/roles/matrix-bridge-hookshot/defaults/main.yml) for how to use them. @@ -26,14 +26,14 @@ Unless indicated otherwise, the following endpoints are reachable on your `matri | listener | default path | variable | used as | |---|---|---|---| -| webhooks | `/hookshot/webhooks/` | `matrix_hookshot_webhook_endpoint` | generics, GitHub "Webhook URL", etc. | +| webhooks | `/hookshot/webhooks/` | `matrix_hookshot_webhook_endpoint` | generics, GitHub "Webhook URL", GitLab "URL", etc. | | github oauth | `/hookshot/webhooks/oauth` | `matrix_hookshot_github_oauth_endpoint` | GitHub "Callback URL" | | jira oauth | `/hookshot/webhooks/jira/oauth` | `matrix_hookshot_jira_oauth_endpoint` | JIRA OAuth | | figma endpoint | `/hookshot/webhooks/figma/webhook` | `matrix_hookshot_figma_endpoint` | Figma | | provisioning | `/hookshot/v1/` | `matrix_hookshot_provisioning_endpoint` | Dimension [provisioning](#provisioning-api) | | appservice | `/hookshot/_matrix/app/` | `matrix_hookshot_appservice_endpoint` | Matrix server | -| widgets | `/hookshot/widgetapi/` | `/matrix_hookshot_widgets_endpoint` | Widgets | -| metrics | `/hookshot/metrics/` (on `stats.` subdomain) | `matrix_hookshot_metrics_endpoint` | Prometheus | +| widgets | `/hookshot/widgetapi/` | `matrix_hookshot_widgets_endpoint` | Widgets | +| metrics | `/metrics/hookshot` | `matrix_hookshot_metrics_enabled` and `matrix_hookshot_metrics_proxying_enabled`. Requires `/metrics/*` endpoints to also be enabled via `matrix_nginx_proxy_proxy_matrix_metrics_enabled` (see the `matrix-nginx-proxy` role). Read more in the [Metrics section](#metrics) below. | Prometheus | See also `matrix_hookshot_matrix_nginx_proxy_configuration` in [init.yml](/roles/matrix-bridge-hookshot/tasks/init.yml). @@ -63,7 +63,14 @@ The provisioning API will be enabled automatically if you set `matrix_dimension_ ### Metrics -If metrics are enabled, they will be automatically available in the builtin Prometheus and Grafana, but you need to set up your own Dashboard for now. If additionally metrics proxying for use with external Prometheus is enabled (`matrix_nginx_proxy_proxy_synapse_metrics`), hookshot metrics will also be available (at `matrix_hookshot_metrics_endpoint`, default `/hookshot/metrics`, on the stats subdomain) and with the same password. See also [the Prometheus and Grafana docs](../configuring-playbook-prometheus-grafana.md). +Metrics are **only enabled by default** if the builtin [Prometheus](configuring-playbook-prometheus-grafana.md) is enabled (by default, Prometheus isn't enabled). If so, metrics will automatically be collected by Prometheus and made available in Grafana. You will, however, need to set up your own Dashboard for displaying them. + +To explicitly enable metrics, use `matrix_hookshot_metrics_enabled: true`. This only exposes metrics over the container network, however. + +**To collect metrics from an external Prometheus server**, besides enabling metrics as described above, you will also need to: + +- enable the `https://matrix.DOMAIN/metrics/*` endpoints on `matrix.DOMAIN` using `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true` (see the `matrix-nginx-role` or [the Prometheus and Grafana docs](configuring-playbook-prometheus-grafana.md) for enabling this feature) +- expose the Hookshot metrics under `https://matrix.DOMAIN/metrics/hookshot` by setting `matrix_hookshot_metrics_proxying_enabled: true` ### Collision with matrix-appservice-webhooks diff --git a/docs/configuring-playbook-bridge-mautrix-discord.md b/docs/configuring-playbook-bridge-mautrix-discord.md new file mode 100644 index 00000000..517fd9b4 --- /dev/null +++ b/docs/configuring-playbook-bridge-mautrix-discord.md @@ -0,0 +1,87 @@ +# 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. +- For using as a Bot we recommend the [Appservice Discord](configuring-playbook-bridge-appservice-discord.md), because it supports plumbing. +- For personal use with a discord account we recommend the `mautrix-discord` bridge (the one being discussed here), because it is the most fully-featured and stable of the 3 Discord bridges supported by the playbook. +The `mautrix-discord` bridge (the one being discussed here) is the most fully-featured and stable of the 3 Discord bridges supported by the playbook, so it's the one we recommend. + +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. + + +## Prerequisites + +For using this bridge, you would **need to authenticate by scanning a QR code with the Discord app on your phone**. + +You can delete the Discord app after the authentication process. + +If this is a dealbreaker for you, consider using one of the other Discord bridges supported by the playbook: [mx-puppet-discord](configuring-playbook-bridge-mx-puppet-discord.md) or [matrix-appservice-discord](configuring-playbook-bridge-appservice-discord.md). These come with their own complexity and limitations, however, so we recommend that you proceed with this one if possible. + + +## Installing + +To enable the bridge, add this to your `vars.yml` file: + +```yaml +matrix_mautrix_discord_enabled: true +``` + +You may optionally wish to add some [Additional configuration](#additional-configuration), or to [prepare for double-puppeting](#set-up-double-puppeting) before the initial installation. + +After adjusting your `vars.yml` file, re-run the playbook and restart all services: `ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start` + +To make use of the bridge, see [Usage](#usage) below. + + +### Additional configuration + +There are some additional things you may wish to configure about the bridge. + +Take a look at: + +- `roles/matrix-bridge-mautrix-discord/defaults/main.yml` for some variables that you can customize via your `vars.yml` file +- `roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2` for the bridge's default configuration. You can override settings (even those that don't have dedicated playbook variables) using the `matrix_mautrix_discord_configuration_extension_yaml` variable + + +### Set up Double Puppeting + +If you'd like to use [Double Puppeting](https://docs.mau.fi/bridges/general/double-puppeting.html) (hint: you most likely do), you have 2 ways of going about it. + +#### Method 1: automatically, by enabling Shared Secret Auth + +The bridge will automatically perform Double Puppeting if you enable [Shared Secret Auth](configuring-playbook-shared-secret-auth.md) for this playbook. + +This is the recommended way of setting up Double Puppeting, as it's easier to accomplish, works for all your users automatically, and has less of a chance of breaking in the future. + +#### Method 2: manually, by asking each user to provide a working access token + +**Note**: This method for enabling Double Puppeting can be configured only after you've already set up bridging (see [Usage](#usage)). + +When using this method, **each user** that wishes to enable Double Puppeting needs to follow the following steps: + +- retrieve a Matrix access token for yourself. You can use the following command: + +``` +curl \ +--data '{"identifier": {"type": "m.id.user", "user": "YOUR_MATRIX_USERNAME" }, "password": "YOUR_MATRIX_PASSWORD", "type": "m.login.password", "device_id": "Mautrix-Discord", "initial_device_display_name": "Mautrix-Discord"}' \ +https://matrix.DOMAIN/_matrix/client/r0/login +``` + +- send the access token to the bot. Example: `login-matrix MATRIX_ACCESS_TOKEN_HERE` + +- make sure you don't log out the `Mautrix-Discord` device some time in the future, as that would break the Double Puppeting feature + + +## Usage + +1. Start a chat with `@discordbot:YOUR_DOMAIN` (where `YOUR_DOMAIN` is your base domain, not the `matrix.` domain). +2. Send a `login` command +3. You'll see a QR code which you need to scan with the Discord app on your phone. You can scan it with the camera app too, which will open Discord, which will then instruct you to scan it a 2nd time in the Discord app. +4. After confirming (in the Discord app) that you'd like to allow this login, the bot should respond with "Succcessfully authenticated as ..." +5. Now that you're logged in, you can send a `help` command to the bot again, to see additional commands you have access to +6. Some Direct Messages from Discord should start syncing automatically +7. If you'd like to bridge guilds: +- send `guilds status` to see the list of guilds +- for each guild that you'd like bridged, send `guilds bridge GUILD_ID --entire` +8. You may wish to uninstall the Discord app from your phone now. It's not needed for the bridge to function. diff --git a/docs/configuring-playbook-bridge-mautrix-facebook.md b/docs/configuring-playbook-bridge-mautrix-facebook.md index 1845682f..4429f004 100644 --- a/docs/configuring-playbook-bridge-mautrix-facebook.md +++ b/docs/configuring-playbook-bridge-mautrix-facebook.md @@ -24,10 +24,22 @@ If you would like to be able to administrate the bridge from your account it can matrix_mautrix_facebook_configuration_extension_yaml: | bridge: permissions: - '@YOUR_USERNAME:YOUR_DOMAIN': admin + '@YOUR_USERNAME:{{ matrix_domain }}': admin ``` -You may wish to look at `roles/matrix-bridge-mautrix-facebook/templates/config.yaml.j2` to find other things you would like to configure. +Using both would look like + +```yaml +matrix_mautrix_facebook_configuration_extension_yaml: | + bridge: + permissions: + '@YOUR_USERNAME:{{ matrix_domain }}': admin + encryption: + allow: true + default: true +``` + +You may wish to look at `roles/matrix-bridge-mautrix-facebook/templates/config.yaml.j2` and `roles/matrix-bridge-mautrix-facebook/defaults/main.yml` to find other things you would like to configure. ## Set up Double Puppeting @@ -91,3 +103,5 @@ Once connected, you should be able to verify that you're browsing the web throug Then proceed to log in to [Facebook/Messenger](https://www.facebook.com/). Once logged in, proceed to [set up bridging](#usage). + +If that doesn't work, enable 2FA [Facebook help page on enabling 2FA](https://www.facebook.com/help/148233965247823) and try to login again with a new password, and entering the 2FA code when prompted, it may take more then one try, in between attempts, check facebook.com to see if they are requiring another password change diff --git a/docs/configuring-playbook-bridge-mautrix-instagram.md b/docs/configuring-playbook-bridge-mautrix-instagram.md index 38d107d0..cbfdcb0b 100644 --- a/docs/configuring-playbook-bridge-mautrix-instagram.md +++ b/docs/configuring-playbook-bridge-mautrix-instagram.md @@ -7,6 +7,32 @@ See the project's [documentation](https://docs.mau.fi/bridges/python/instagram/i ```yaml matrix_mautrix_instagram_enabled: true ``` +There are some additional things you may wish to configure about the bridge before you continue. + +Encryption support is off by default. If you would like to enable encryption, add the following to your `vars.yml` file: +```yaml +matrix_mautrix_instagram_configuration_extension_yaml: | + bridge: + encryption: + allow: true + default: true +``` + +If you would like to be able to administrate the bridge from your account it can be configured like this: +```yaml +# The easy way. The specified Matrix user ID will be made an admin of all bridges +matrix_admin: "@YOUR_USERNAME:{{ matrix_domain }}" + +# OR: +# The more verbose way. Applies to this bridge only. You may define multiple Matrix users as admins. +matrix_mautrix_instagram_configuration_extension_yaml: | + bridge: + permissions: + '@YOUR_USERNAME:YOUR_DOMAIN': admin +``` + +You may wish to look at `roles/matrix-bridge-mautrix-instagram/templates/config.yaml.j2` and `roles/matrix-bridge-mautrix-instagram/defaults/main.yml` to find other things you would like to configure. + ## Usage diff --git a/docs/configuring-playbook-bridge-mx-puppet-discord.md b/docs/configuring-playbook-bridge-mx-puppet-discord.md index 2be7f206..c266f843 100644 --- a/docs/configuring-playbook-bridge-mx-puppet-discord.md +++ b/docs/configuring-playbook-bridge-mx-puppet-discord.md @@ -1,6 +1,8 @@ # Setting up MX Puppet Discord (optional) -**Note**: bridging to [Discord](https://discordapp.com/) can also happen via the [matrix-appservice-discord](configuring-playbook-bridge-appservice-discord.md) bridge supported by the playbook. +**Note**: bridging to [Discord](https://discordapp.com/) can also happen via the [matrix-appservice-discord](configuring-playbook-bridge-appservice-discord.md)and [mautrix-discord](configuring-playbook-bridge-mautrix-discord.md) bridges supported by the playbook. +- For using as a Bot we recommend the [Appservice Discord](configuring-playbook-bridge-appservice-discord.md), because it supports plumbing. +- For personal use with a discord account we recommend the [mautrix-discord](configuring-playbook-bridge-mautrix-discord.md) bridge, because it is the most fully-featured and stable of the 3 Discord bridges supported by the playbook. The playbook can install and configure [mx-puppet-discord](https://github.com/matrix-discord/mx-puppet-discord) for you. diff --git a/docs/configuring-playbook-bridge-mx-puppet-groupme.md b/docs/configuring-playbook-bridge-mx-puppet-groupme.md index 2f0eda19..4d03d5d9 100644 --- a/docs/configuring-playbook-bridge-mx-puppet-groupme.md +++ b/docs/configuring-playbook-bridge-mx-puppet-groupme.md @@ -1,7 +1,7 @@ # Setting up MX Puppet GroupMe (optional) The playbook can install and configure -[mx-puppet-groupme](https://gitlab.com/robintown/mx-puppet-groupme) for you. +[mx-puppet-groupme](https://gitlab.com/xangelix-pub/matrix/mx-puppet-groupme) for you. See the project page to learn what it does and why it might be useful to you. diff --git a/docs/configuring-playbook-bridge-mx-puppet-skype.md b/docs/configuring-playbook-bridge-mx-puppet-skype.md index cca5e305..c80b1af8 100644 --- a/docs/configuring-playbook-bridge-mx-puppet-skype.md +++ b/docs/configuring-playbook-bridge-mx-puppet-skype.md @@ -1,30 +1,5 @@ # Setting up MX Puppet Skype (optional) -The playbook can install and configure -[mx-puppet-skype](https://github.com/Sorunome/mx-puppet-skype) for you. +The playbook used to be able to install and configure [mx-puppet-skype](https://github.com/Sorunome/mx-puppet-skype), but no longer includes this component, because it has been broken and unmaintaned for a long time. -See the project page to learn what it does and why it might be useful to you. - -To enable the [Skype](https://www.skype.com/) bridge just use the following -playbook configuration: - - -```yaml -matrix_mx_puppet_skype_enabled: true -``` - - -## Usage - -Once the bot is enabled you need to start a chat with `Skype Puppet Bridge` with -the handle `@_skypepuppet_bot:YOUR_DOMAIN` (where `YOUR_DOMAIN` is your base -domain, not the `matrix.` domain). - -Send `link ` to the bridge bot to link your skype account. - -Once logged in, send `list` to the bot user to list the available rooms. - -Clicking rooms in the list will result in you receiving an invitation to the -bridged room. - -Also send `help` to the bot to see the commands available. +Bridging to [Skype](https://www.skype.com/) can also happen via the [go-skype-bridge](configuring-playbook-bridge-go-skype-bridge.md) bridge supported by the playbook. diff --git a/docs/configuring-playbook-matrix-registration.md b/docs/configuring-playbook-matrix-registration.md index b0240d3f..2b4b07ff 100644 --- a/docs/configuring-playbook-matrix-registration.md +++ b/docs/configuring-playbook-matrix-registration.md @@ -2,6 +2,8 @@ The playbook can install and configure [matrix-registration](https://github.com/ZerataX/matrix-registration) for you. +**WARNING**: this is a poorly maintained and buggy project. It's better to avoid using it. + > matrix-registration is a simple python application to have a token based matrix registration. Use matrix-registration to **create unique registration links**, which people can use to register on your Matrix server. It allows you to **keep your server's registration closed (private)**, but still allow certain people (these having a special link) to register a user account. diff --git a/docs/configuring-playbook-mautrix-bridges.md b/docs/configuring-playbook-mautrix-bridges.md new file mode 100644 index 00000000..1cd76f96 --- /dev/null +++ b/docs/configuring-playbook-mautrix-bridges.md @@ -0,0 +1,111 @@ +# Setting up a Generic Mautrix Bridge (optional) + +The playbook can install and configure various [mautrix](https://github.com/mautrix) bridges (twitter, facebook, instagram, signal, hangouts, googlechat, etc.), as well as many other (non-mautrix) bridges. +This is a common guide for configuring mautrix bridges. + +You can see each bridge's features at in the `ROADMAP.md` file in its corresponding [mautrix](https://github.com/mautrix) repository. + +To enable a bridge add: + + +```yaml +# Replace SERVICENAME with one of: twitter, facebook, instagram, .. +matrix_mautrix_SERVICENAME_enabled: true +``` + +to your `vars.yml` + +There are some additional things you may wish to configure about the bridge before you continue. Each bridge may have additional requirements besides `_enabled: true`. For example, the mautrix-telegram bridge (our documentation page about it is [here](configuring-playbook-bridge-mautrix-telegram.md)) requires the `matrix_mautrix_telegram_api_id` and `matrix_mautrix_telegram_api_hash` variables to be defined. Refer to each bridge's individual documentation page for details about enabling bridges. + +You can add + +```yaml +matrix_admin: "@YOUR_USERNAME:{{ matrix_domain }}" +``` +to `vars.yml` to **configure a user as an administrator for all bridges**. +**Alternatively** (more verbose, but allows multiple admins to be configured), you can do the same on a per-bridge basis with: + +```yaml +matrix_mautrix_SERVICENAME_configuration_extension_yaml: | + bridge: + permissions: + '@YOUR_USERNAME:{{ matrix_domain }}': admin +``` + +Encryption support is off by default. If you would like to enable encryption, add the following to your `vars.yml` file: +```yaml +matrix_mautrix_SERVICENAME_configuration_extension_yaml: | + bridge: + encryption: + allow: true + default: true +``` + + +You can only have one `matrix_mautrix_SERVICENAME_configuration_extension_yaml` definition in `vars.yml` per bridge, so if you need multiple pieces of configuration there, just merge them like this: + +```yaml +matrix_mautrix_SERVICENAME_configuration_extension_yaml: | + bridge: + permissions: + '@YOUR_USERNAME:{{ matrix_domain }}': admin + encryption: + allow: true + default: true +``` + +## Setting the bot's username + +```yaml +matrix_mautrix_SERVICENAME_appservice_bot_username: "BOTNAME" +``` + +Can be used to set the username for the bridge. + +## Discovering additional configuration options + +You may wish to look at `roles/matrix-bridge-mautrix-SERVICENAME/templates/config.yaml.j2` and `roles/matrix-bridge-mautrix-SERVICENAME/defaults/main.yml` to find other things you would like to configure. + + +## Set up Double Puppeting + +To set up [Double Puppeting](https://docs.mau.fi/bridges/general/double-puppeting.html) + +please do so automatically, by enabling Shared Secret Auth + +The bridge will automatically perform Double Puppeting if you enable [Shared Secret Auth](configuring-playbook-shared-secret-auth.md) for this playbook by adding + +```yaml +matrix_synapse_ext_password_provider_shared_secret_auth_enabled: true +matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret: YOUR_SHARED_SECRET_GOES_HERE +``` + +You should generate a strong shared secret with a command like this: pwgen -s 64 1 + +This is the recommended way of setting up Double Puppeting, as it's easier to accomplish, works for all your users automatically, and has less of a chance of breaking in the future. + +## Controlling the logging level + +```yaml +matrix_mautrix_SERVICENAME_logging_level: WARN +``` + +to `vars.yml` to control the logging level, where you may replace WARN with one of the following to control the verbosity of the logs generated: TRACE, DEBUG, INFO, WARN, ERROR, or FATAL. + +If you have issues with a service, and are requesting support, the higher levels of logging will generally be more helpful. + + +## Usage + +You then need to start a chat with `@SERVICENAMEbot:YOUR_DOMAIN` (where `YOUR_DOMAIN` is your base domain, not the `matrix.` domain). + +Send `login ` to the bridge bot to get started You can learn more here about authentication from the bridge's official documentation on Authentication https://docs.mau.fi/bridges/python/SERVICENAME/authentication.html . + +If you run into trouble, check the [Troubleshooting](#troubleshooting) section below. + + + +## Troubleshooting + +For troubleshooting information with a specific bridge, please see the playbook documentation about it (some other document in in `docs/`) and the upstream ([mautrix](https://github.com/mautrix)) bridge documentation for that specific bridge. +Reporting bridge bugs should happen upstream, in the corresponding mautrix repository, not to us. diff --git a/docs/configuring-playbook-ntfy.md b/docs/configuring-playbook-ntfy.md new file mode 100644 index 00000000..57dfb3b2 --- /dev/null +++ b/docs/configuring-playbook-ntfy.md @@ -0,0 +1,93 @@ +# Setting up ntfy (optional) + +The playbook can install and configure the [ntfy](https://ntfy.sh/) push notifications server for you. + +Using the [UnifiedPush](https://unifiedpush.org) standard, ntfy enables self-hosted (Google-free) push notifications from Matrix (and other) servers to UnifiedPush-compatible matrix compatible client apps running on Android and other devices. + +This role is intended to support UnifiedPush notifications for use with the Matrix and Matrix-related services that this playbook installs. This role is not intended to support all of ntfy's other features. + +**Note**: In contrast to push notifications using Google's FCM or Apple's APNs, the use of UnifiedPush allows each end-user to choose the push notification server that they prefer. As a consequence, deploying this ntfy server does not by itself ensure any particular user or device or client app will use it. + + +## Adjusting the playbook configuration + +Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file (adapt to your needs): + +```yaml +# Enabling it is the only required setting +matrix_ntfy_enabled: true + +# Some other options +matrix_server_fqn_ntfy: "ntfy.{{ matrix_domain }}" +matrix_ntfy_configuration_extension_yaml: | + log_level: DEBUG +``` + +For a more complete list of variables that you could override, see `roles/matrix-ntfy/defaults/main.yml`. + +For a complete list of ntfy config options that you could put in `matrix_ntfy_configuration_extension_yaml`, see the [ntfy config documentation](https://ntfy.sh/docs/config/#config-options). + + +## Installing + +Don't forget to add `ntfy.` to DNS as described in [Configuring DNS](configuring-dns.md) before running the playbook. + +After configuring the playbook, run the [installation](installing.md) command again: + +``` +ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start +``` + + +## Usage + +To make use of your ntfy installation, on Android for example, you need two things: + +* the `ntfy` app +* a UnifiedPush-compatible matrix app + +You need to install the `ntfy` app on each device on which you want to receive push notifications through your ntfy server. The `ntfy` app will provide UnifiedPush notifications to any number of UnifiedPush-compatible messaging apps installed on the same device. + +### Setting up the `ntfy` Android app + +1. Install the [ntfy Android app](https://ntfy.sh/docs/subscribe/phone/) from F-droid or Google Play. +2. In its Settings -> `General: Default server`, enter your ntfy server URL, such as `https://ntfy.DOMAIN`. +3. In its Settings -> `Advanced: Connection protocol`, choose `WebSockets`. + +That is all you need to do in the ntfy app. It has many other features, but for our purposes you can ignore them. In particular you do not need to follow any instructions about subscribing to a notification topic as UnifiedPush will do that automatically. + +### Setting up a UnifiedPush-compatible matrix app + +Install any UnifiedPush-enabled matrix app on that same device. The matrix app will learn from the `ntfy` app that you have configured UnifiedPush on this device, and then it will tell your matrix server to use it. + +Steps needed for specific matrix apps: + +* FluffyChat-android: + - Should auto-detect and use it. No manual settings. + +* SchildiChat-android: + 1. enable `Settings` -> `Notifications` -> `UnifiedPush: Force custom push gateway`. + 2. choose `Settings` -> `Notifications` -> `UnifiedPush: Re-register push distributor`. *(For info, a more complex alternative to achieve the same is: delete the relevant unifiedpush registration in `ntfy` app, force-close SchildiChat, re-open it.)* + 3. verify `Settings` -> `Notifications` -> `UnifiedPush: Notification targets` as described below in the "Troubleshooting" section. + +* Element-android v1.4.26+: + - [not yet documented; should auto-detect and use it?] + +If the matrix app asks, "Choose a distributor: FCM Fallback or ntfy", then choose "ntfy". + +If the matrix app doesn't seem to pick it up, try restarting it and try the Troubleshooting section below. + + +## Troubleshooting + +First check that the matrix client app you are using supports UnifiedPush. There may well be different variants of the app. + +Set the ntfy server's log level to 'DEBUG', as shown in the example settings above, and watch the server's logs with `sudo journalctl -fu matrix-ntfy`. + +To check if UnifiedPush is correctly configured on the client device, look at "Settings -> Notifications -> Notification Targets" in Element-Android or SchildiChat, or "Settings -> Notifications -> Devices" in FluffyChat. There should be one entry for each matrix client app that has enabled push notifications, and when that client is using UnifiedPush you should see a URL that begins with your ntfy server's URL. + +In the "Notification Targets" screen in Element-Android or SchildiChat, two relevant URLs are shown, "push\_key" and "Url", and both should begin with your ntfy server's URL. If "push\_key" shows your server but "Url" shows an external server such as `up.schildi.chat` then push notifications will still work but are being routed through that external server before they reach your ntfy server. To rectify that, in SchildiChat (at least around version 1.4.20.sc55) you must enable the `Force custom push gateway` setting as described in the "Usage" section above. + +If it is not working, useful tools are "Settings -> Notifications -> Re-register push distributor" and "Settings -> Notifications -> Troubleshoot Notifications" in SchildiChat (possibly also Element-Android). In particular the "Endpoint/FCM" step of that troubleshooter should display your ntfy server's URL that it has discovered from the ntfy client app. + +The simple [UnifiedPush troubleshooting](https://unifiedpush.org/users/troubleshooting/) app [UP-Example](https://f-droid.org/en/packages/org.unifiedpush.example/) can be used to manually test UnifiedPush registration and operation on an Android device. diff --git a/docs/configuring-playbook-own-webserver.md b/docs/configuring-playbook-own-webserver.md index c7e56f14..76fa2d8b 100644 --- a/docs/configuring-playbook-own-webserver.md +++ b/docs/configuring-playbook-own-webserver.md @@ -57,6 +57,14 @@ matrix_nginx_proxy_ssl_protocols: "TLSv1.2" If you are experiencing issues, try updating to a newer version of Nginx. As a data point in May 2021 a user reported that Nginx 1.14.2 was not working for them. They were getting errors about socket leaks. Updating to Nginx 1.19 fixed their issue. +If you are not going to be running your webserver on the same docker network, or the same machine as matrix, these variables can be set to bind synapse to an exposed port. [Keep in mind that there are some security concerns if you simply proxy everything to it](https://github.com/matrix-org/synapse/blob/master/docs/reverse_proxy.md#synapse-administration-endpoints) +```yaml +# Takes an ":" or "" value (e.g. "127.0.0.1:8048" or "192.168.1.3:80"), or empty string to not expose. +matrix_synapse_container_client_api_host_bind_port: '' +matrix_synapse_container_federation_api_plain_host_bind_port: '' +``` + + ### Using your own external Apache webserver diff --git a/docs/configuring-playbook-postgres-backup.md b/docs/configuring-playbook-postgres-backup.md index 2d878c11..75b599c8 100644 --- a/docs/configuring-playbook-postgres-backup.md +++ b/docs/configuring-playbook-postgres-backup.md @@ -2,6 +2,9 @@ The playbook can install and configure [docker-postgres-backup-local](https://github.com/prodrigestivill/docker-postgres-backup-local) for you. +For a more complete backup solution (one that includes not only Postgres, but also other configuration/data files), you may wish to look into [borg backup](configuring-playbook-backup-borg.md) instead. + + ## Adjusting the playbook configuration Minimal working configuration (`inventory/host_vars/matrix.DOMAIN/vars.yml`) to enable Postgres backup: diff --git a/docs/configuring-playbook-prometheus-grafana.md b/docs/configuring-playbook-prometheus-grafana.md index f178def2..b2878c12 100644 --- a/docs/configuring-playbook-prometheus-grafana.md +++ b/docs/configuring-playbook-prometheus-grafana.md @@ -9,8 +9,12 @@ Remember to add `stats.` to DNS as described in [Configuring DNS](c ```yaml matrix_prometheus_enabled: true +# You can remove this, if unnecessary. matrix_prometheus_node_exporter_enabled: true +# You can remove this, if unnecessary. +matrix_prometheus_postgres_exporter_enabled: true + matrix_grafana_enabled: true matrix_grafana_anonymous_access: false @@ -34,6 +38,7 @@ Name | Description -----|---------- `matrix_prometheus_enabled`|[Prometheus](https://prometheus.io) is a time series database. It holds all the data we're going to talk about. `matrix_prometheus_node_exporter_enabled`|[Node Exporter](https://prometheus.io/docs/guides/node-exporter/) is an addon of sorts to Prometheus that collects generic system information such as CPU, memory, filesystem, and even system temperatures +`matrix_prometheus_postgres_exporter_enabled`|[Postgres Exporter](configuring-playbook-prometheus-postgres.md) is an addon of sorts to expose Postgres database metrics to Prometheus. `matrix_grafana_enabled`|[Grafana](https://grafana.com/) is the visual component. It shows (on the `stats.` subdomain) the dashboards with the graphs that we're interested in `matrix_grafana_anonymous_access`|By default you need to log in to see graphs. If you want to publicly share your graphs (e.g. when asking for help in [`#synapse:matrix.org`](https://matrix.to/#/#synapse:matrix.org?via=matrix.org&via=privacytools.io&via=mozilla.org)) you'll want to enable this option. `matrix_grafana_default_admin_user`
`matrix_grafana_default_admin_password`|By default Grafana creates a user with `admin` as the username and password. If you feel this is insecure and you want to change it beforehand, you can do that here @@ -48,28 +53,55 @@ Most of our docker containers run with limited system access, but the `prometheu ## Collecting metrics to an external Prometheus server -If you wish, you could expose homeserver metrics without enabling (installing) Prometheus and Grafana via the playbook. This may be useful for hooking Matrix services to an external Prometheus/Grafana installation. +**If the integrated Prometheus server is enabled** (`matrix_prometheus_enabled: true`), metrics are collected by it from each service via communication that happens over the container network. Each service does not need to expose its metrics "publicly". + +When you'd like **to collect metrics from an external Prometheus server**, you need to expose service metrics outside of the container network. + +The playbook provides a single endpoint (`https://matrix.DOMAIN/metrics/*`), under which various services may expose their metrics (e.g. `/metrics/node-exporter`, `/metrics/postgres-exporter`, `/metrics/hookshot`, etc). To enable this `/metrics/*` feature, use `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. To protect access using [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication), see `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled` below. -To do this, you may be interested in the following variables: +The following variables may be of interest: Name | Description -----|---------- +`matrix_nginx_proxy_proxy_matrix_metrics_enabled`|Set this to `true` to enable metrics exposure for various services on `https://matrix.DOMAIN/metrics/*`. Refer to the individual `matrix_SERVICE_metrics_proxying_enabled` variables below for exposing metrics for each individual service. +`matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled`|Set this to `true` to protect all `https://matrix.DOMAIN/metrics/*` endpoints with [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) (see the other variables below for supplying the actual credentials). When enabled, all endpoints beneath `/metrics` will be protected with the same credentials +`matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username`|Set this to the Basic Authentication username you'd like to protect `/metrics/*` with. You also need to set `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password`. If one username/password pair is not enough, you can leave the `username` and `password` variables unset and use `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content` instead +`matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password`|Set this to the Basic Authentication password you'd like to protect `/metrics/*` with +`matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content`|Set this to the Basic Authentication credentials (raw `htpasswd` file content) used to protect `/metrics/*`. This htpasswd-file needs to be generated with the `htpasswd` tool and can include multiple username/password pairs. If you only need one credential, use `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username` and `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password` instead. `matrix_synapse_metrics_enabled`|Set this to `true` to make Synapse expose metrics (locally, on the container network) -`matrix_nginx_proxy_proxy_synapse_metrics`|Set this to `true` to make matrix-nginx-proxy expose the Synapse metrics at `https://matrix.DOMAIN/_synapse/metrics` -`matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled`|Set this to `true` to password-protect (using HTTP Basic Auth) `https://matrix.DOMAIN/_synapse/metrics` (the username is always `prometheus`, the password is defined in `matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_key`) -`matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_key`|Set this to a password to use for HTTP Basic Auth for protecting `https://matrix.DOMAIN/_synapse/metrics` (the username is always `prometheus` - it's not configurable). Do not write the password in plain text. See `man 1 htpasswd` or use `htpasswd -c mypass.htpasswd prometheus` to generate the expected hash for nginx. -`matrix_server_fqn_grafana`|Use this variable to override the domain at which the Grafana web user-interface is at (defaults to `stats.DOMAIN`) +`matrix_synapse_metrics_proxying_enabled`|Set this to `true` to expose Synapse's metrics on `https://matrix.DOMAIN/metrics/synapse/main-process` and `https://matrix.DOMAIN/metrics/synapse/worker/TYPE-ID` (only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`). Read [below](#collecting-synapse-worker-metrics-to-an-external-prometheus-server) if you're running a Synapse worker setup (`matrix_synapse_workers_enabled: true`). +`matrix_prometheus_node_exporter_enabled`|Set this to `true` to enable the node (general system stats) exporter (locally, on the container network) +`matrix_prometheus_node_exporter_metrics_proxying_enabled`|Set this to `true` to expose the node (general system stats) metrics on `https://matrix.DOMAIN/metrics/node-exporter` (only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`) +`matrix_prometheus_postgres_exporter_enabled`|Set this to `true` to enable the [Postgres exporter](configuring-playbook-prometheus-postgres.md) (locally, on the container network) +`matrix_prometheus_postgres_exporter_metrics_proxying_enabled`|Set this to `true` to expose the [Postgres exporter](configuring-playbook-prometheus-postgres.md) metrics on `https://matrix.DOMAIN/metrics/postgres-exporter` (only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`) +`matrix_bridge_hookshot_metrics_enabled`|Set this to `true` to make [Hookshot](configuring-playbook-bridge-hookshot.md) expose metrics (locally, on the container network) +`matrix_bridge_hookshot_metrics_proxying_enabled`|Set this to `true` to expose the [Hookshot](configuring-playbook-bridge-hookshot.md) metrics on `https://matrix.DOMAIN/metrics/hookshot` (only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`) +`matrix_SERVICE_metrics_proxying_enabled`|Various other services/roles may provide similar `_metrics_enabled` and `_metrics_proxying_enabled` variables for exposing their metrics. Refer to each role for details. Only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true` +`matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks`|Add nginx `location` blocks to this list if you'd like to expose additional exporters manually (see below) + +Example for how to make use of `matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks` for exposing additional metrics locations: +```nginx +matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks: + - 'location /metrics/another-service { + resolver 127.0.0.11 valid=5s; + proxy_pass http://matrix-another-service:9100/metrics; + }' +``` + +Using `matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks` only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true` (see above). + +Note : The playbook will hash the basic_auth password for you on setup. Thus, you need to give the plain-text version of the password as a variable. -### Collecting worker metrics to an external Prometheus server +### Collecting Synapse worker metrics to an external Prometheus server -If you are using workers (`matrix_synapse_workers_enabled`) and have enabled `matrix_nginx_proxy_proxy_synapse_metrics` as described above, the playbook will also automatically proxy the all worker threads's metrics to `https://matrix.DOMAIN/_synapse-worker-TYPE-ID/metrics`, where `TYPE` corresponds to the type and `ID` to the instanceId of a worker as exemplified in `matrix_synapse_workers_enabled_list`. +If you are using workers (`matrix_synapse_workers_enabled: true`) and have enabled `matrix_synapse_metrics_proxying_enabled` as described above, the playbook will also automatically expose all Synapse worker threads' metrics to `https://matrix.DOMAIN/metrics/synapse/worker/TYPE-ID`, where `TYPE` corresponds to the type and `ID` to the instanceId of a worker as exemplified in `matrix_synapse_workers_enabled_list`. -The playbook also generates an exemplary prometheus.yml config file (`matrix_base_data_path/external_prometheus.yml.template`) with all the correct paths which you can copy to your Prometheus server and adapt to your needs, especially edit the specified `password_file` path and contents and path to your `synapse-v2.rules`. +The playbook also generates an exemplary config file (`/matrix/synapse/external_prometheus.yml.template`) with all the correct paths which you can copy to your Prometheus server and adapt to your needs. Make sure to edit the specified `password_file` path and contents and path to your `synapse-v2.rules`. It will look a bit like this: ```yaml scrape_configs: - job_name: 'synapse' - metrics_path: /_synapse/metrics + metrics_path: /metrics/synapse/main-process scheme: https basic_auth: username: prometheus @@ -80,7 +112,7 @@ scrape_configs: job: "master" index: 1 - job_name: 'synapse-generic_worker-1' - metrics_path: /_synapse-worker-generic_worker-18111/metrics + metrics_path: /metrics/synapse/worker/generic_worker-18111 scheme: https basic_auth: username: prometheus @@ -92,38 +124,6 @@ scrape_configs: index: 18111 ``` -### Collecting system and Postgres metrics to an external Prometheus server (advanced) - -When you normally enable the Prometheus and Grafana via the playbook, it will also show general system (via node-exporter) and Postgres (via postgres-exporter) stats. If you are instead collecting your metrics to an external Prometheus server, you can follow this advanced configuration example to also export these stats. - -It would be possible to use `matrix_prometheus_node_exporter_container_http_host_bind_port` etc., but that is not always the best choice, for example because your server is on a public network. - -Use the following variables in addition to the ones mentioned above: - -Name | Description ------|---------- -`matrix_nginx_proxy_proxy_grafana_enabled`|Set this to `true` to make the stats subdomain (`matrix_server_fqn_grafana`) available via the Nginx proxy -`matrix_ssl_additional_domains_to_obtain_certificates_for`|Add `"{{ matrix_server_fqn_grafana }}"` to this list to have letsencrypt fetch a certificate for the stats subdomain -`matrix_prometheus_node_exporter_enabled`|Set this to `true` to enable the node (general system stats) exporter -`matrix_prometheus_postgres_exporter_enabled`|Set this to `true` to enable the Postgres exporter -`matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks`|Add locations to this list depending on which of the above exporters you enabled (see below) - -```nginx -matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks: - - 'location /node-exporter/ { - resolver 127.0.0.11 valid=5s; - proxy_pass http://matrix-prometheus-node-exporter:9100/; - auth_basic "protected"; - auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd; - }' - - 'location /postgres-exporter/ { - resolver 127.0.0.11 valid=5s; - proxy_pass http://matrix-prometheus-postgres-exporter:9187/; - auth_basic "protected"; - auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd; - }' -``` -You can customize the `location`s to your liking, just point your Prometheus to there later (e.g. `stats.DOMAIN/node-exporter/metrics`). Nginx is very picky about the `proxy_pass`syntax: take care to follow the example closely and note the trailing slash as well as absent use of variables. postgres-exporter uses the nonstandard port 9187. ## More information @@ -131,4 +131,3 @@ You can customize the `location`s to your liking, just point your Prometheus to - [The Prometheus scraping rules](https://github.com/matrix-org/synapse/tree/master/contrib/prometheus) (we use v2) - [The Synapse Grafana dashboard](https://github.com/matrix-org/synapse/tree/master/contrib/grafana) - [The Node Exporter dashboard](https://github.com/rfrail3/grafana-dashboards) (for generic non-synapse performance graphs) - diff --git a/docs/configuring-playbook-prometheus-postgres.md b/docs/configuring-playbook-prometheus-postgres.md index 34407aae..6fd13a9e 100644 --- a/docs/configuring-playbook-prometheus-postgres.md +++ b/docs/configuring-playbook-prometheus-postgres.md @@ -7,11 +7,6 @@ You can enable this with the following settings in your configuration file (`inv ```yaml matrix_prometheus_postgres_exporter_enabled: true - -# the role creates a postgres user as credential. You can configure these if required: -matrix_prometheus_postgres_exporter_database_username: 'matrix_prometheus_postgres_exporter' -matrix_prometheus_postgres_exporter_database_password: 'some-password' - ``` ## What does it do? @@ -20,7 +15,8 @@ Name | Description -----|---------- `matrix_prometheus_postgres_exporter_enabled`|Enable the postgres prometheus exporter. This sets up the docker container, connects it to the database and adds a 'job' to the prometheus config which tells prometheus about this new exporter. The default is 'false' `matrix_prometheus_postgres_exporter_database_username`| The 'username' for the user that the exporter uses to connect to the database. The default is 'matrix_prometheus_postgres_exporter' -`matrix_prometheus_postgres_exporter_database_password`| The 'password' for the user that the exporter uses to connect to the database. +`matrix_prometheus_postgres_exporter_database_password`| The 'password' for the user that the exporter uses to connect to the database. By default, this is auto-generated by the playbook +`matrix_prometheus_postgres_exporter_metrics_proxying_enabled`|If set to `true`, exposes the Postgres exporter metrics on `https://matrix.DOMAIN/metrics/postgres-exporter` for usage with an [external Prometheus server](configuring-playbook-prometheus-grafana.md#collecting-metrics-to-an-external-prometheus-server) (only takes effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`) ## More information diff --git a/docs/configuring-playbook-ssl-certificates.md b/docs/configuring-playbook-ssl-certificates.md index eae584e7..30a8f0b8 100644 --- a/docs/configuring-playbook-ssl-certificates.md +++ b/docs/configuring-playbook-ssl-certificates.md @@ -74,6 +74,7 @@ By default, it obtains certificates for: - possibly for `jitsi.`, if you have explicitly [set up Jitsi](configuring-playbook-jitsi.md). - possibly for `stats.`, if you have explicitly [set up Grafana](configuring-playbook-prometheus-grafana.md). - possibly for `sygnal.`, if you have explicitly [set up Sygnal](configuring-playbook-sygnal.md). +- possibly for `ntfy.`, if you have explicitly [set up ntfy](configuring-playbook-ntfy.md). - possibly for your base domain (``), if you have explicitly configured [Serving the base domain](configuring-playbook-base-domain-serving.md) If you are hosting other domains on the Matrix machine, you can make the playbook obtain and renew certificates for those other domains too. diff --git a/docs/configuring-playbook-synapse-admin.md b/docs/configuring-playbook-synapse-admin.md index 68d70305..ad1bda02 100644 --- a/docs/configuring-playbook-synapse-admin.md +++ b/docs/configuring-playbook-synapse-admin.md @@ -62,3 +62,15 @@ matrix_synapse_admin_container_extra_arguments: # The Synapse Admin container uses port 80 by default - '--label "traefik.http.services.matrix-synapse-admin.loadbalancer.server.port=80"' ``` + +### Sample configuration for running behind Caddy v2 + +Below is a sample configuration for using this playbook with a [Caddy](https://caddyserver.com/v2) 2.0 reverse proxy (non-default configuration where `matrix-nginx-proxy` is disabled - `matrix_nginx_proxy_enabled: false`). + +```caddy +# This is a basic configuration that will function the same as the default nginx proxy - exposing the synapse-admin panel to matrix.YOURSERVER.com/synapse-admin/ + handle_path /synapse-admin* { + reverse_proxy localhost:8766 { + } + } +``` diff --git a/docs/configuring-playbook-telemetry.md b/docs/configuring-playbook-telemetry.md index da583838..a97fa59c 100644 --- a/docs/configuring-playbook-telemetry.md +++ b/docs/configuring-playbook-telemetry.md @@ -3,8 +3,7 @@ By default, this playbook configures your Matrix homeserver to not send any telemetry data anywhere. The [matrix.org](https://matrix.org) team would really appreciate it if you could help the project out by reporting -anonymized usage statistics from your homeserver. Only very [basic aggregate -data](#usage-statistics-being-submitted) (e.g. number of users) will be reported, but it helps track the +usage statistics from your homeserver. Enabling usage statistics helps track the growth of the Matrix community, and helps to make Matrix a success. @@ -19,28 +18,9 @@ matrix_synapse_report_stats: true ## Usage statistics being submitted -If statistics reporting is enabled, the information that gets submitted to the matrix.org team [according to the source code](https://github.com/matrix-org/synapse/blob/master/synapse/app/homeserver.py) is: +When enabled, Synapse will regularly upload a few dozen statistics about your server. +This data includes your homeserver's domain, the total number of users, the number of active +users, the total number of rooms, and the number of messages sent per day on your homeserver. -- your homeserver's domain name - -- uptime of the homeserver program - -- [Python](https://www.python.org/) version powering your homeserver - -- total number of users on your home server (including bridged users) - -- total number of native Matrix users on your home server - -- total number of rooms on your homeserver - -- total number of daily active users on your homeserver - -- total number of daily active rooms on your homeserver - -- total number of messages sent per day - -- cache setting information - -- CPU and memory statistics for the homeserver program - -- database engine type and version +See [Synapse's documentation](https://github.com/matrix-org/synapse/blob/develop/docs/usage/administration/monitoring/reporting_homeserver_usage_statistics.md#available-statistics) +for the full list of statistics that are reported. diff --git a/docs/configuring-playbook.md b/docs/configuring-playbook.md index 3d5e6c2c..1c03a9b5 100644 --- a/docs/configuring-playbook.md +++ b/docs/configuring-playbook.md @@ -18,6 +18,7 @@ You can then follow these steps inside the playbook directory: 1. edit the inventory hosts file (`inventory/hosts`) to your liking +1. (optional, advanced) to run Ansible against multiple servers with different `sudo` credentials, you can copy the sample inventory hosts yaml file for each of your hosts: (`cp examples/host.yml inventory/my_host1.yml` …) and use the [`ansible-all-hosts.sh`](../inventory/scripts/ansible-all-hosts.sh) script [in the installation step](installing.md). For a basic Matrix installation, that's all you need. For a more custom setup, see the [Other configuration options](#other-configuration-options) below. @@ -51,7 +52,7 @@ When you're done with all the configuration you'd like to do, continue with [Ins - [Serving your base domain using this playbook's nginx server](configuring-playbook-base-domain-serving.md) (optional) -- [Configure Nginx (optional, advanced)](configuring-playbook-nginx.md) (optional, advanced) +- [Configure Nginx](configuring-playbook-nginx.md) (optional, advanced) - [Using your own webserver, instead of this playbook's nginx proxy](configuring-playbook-own-webserver.md) (optional, advanced) @@ -92,6 +93,8 @@ When you're done with all the configuration you'd like to do, continue with [Ins ### Bridging other networks +- [Setting up Mautrix Discord bridging](configuring-playbook-bridge-mautrix-discord.md) (optional) + - [Setting up Mautrix Telegram bridging](configuring-playbook-bridge-mautrix-telegram.md) (optional) - [Setting up Mautrix Whatsapp bridging](configuring-playbook-bridge-mautrix-whatsapp.md) (optional) @@ -110,17 +113,19 @@ When you're done with all the configuration you'd like to do, continue with [Ins - [Setting up Appservice IRC bridging](configuring-playbook-bridge-appservice-irc.md) (optional) -- [Setting up Beeper LinkedIn bridging](configuring-playbook-bridge-beeper-linkedin.md) (optional) - - [Setting up Appservice Discord bridging](configuring-playbook-bridge-appservice-discord.md) (optional) - [Setting up Appservice Slack bridging](configuring-playbook-bridge-appservice-slack.md) (optional) - [Setting up Appservice Webhooks bridging](configuring-playbook-bridge-appservice-webhooks.md) (optional) +- [Setting up Appservice Kakaotalk bridging](configuring-playbook-bridge-appservice-kakaotalk.md) (optional) + +- [Setting up Beeper LinkedIn bridging](configuring-playbook-bridge-beeper-linkedin.md) (optional) + - [Setting up matrix-hookshot](configuring-playbook-bridge-hookshot.md) - a bridge between Matrix and multiple project management services, such as [GitHub](https://github.com), [GitLab](https://about.gitlab.com) and [JIRA](https://www.atlassian.com/software/jira). (optional) -- [Setting up MX Puppet Skype bridging](configuring-playbook-bridge-mx-puppet-skype.md) (optional) +- ~~[Setting up MX Puppet Skype bridging](configuring-playbook-bridge-mx-puppet-skype.md)~~ (optional) - this component has been broken for a long time, so it has been removed from the playbook. Consider [Setting up Go Skype Bridge bridging](configuring-playbook-bridge-go-skype-bridge.md) - [Setting up MX Puppet Slack bridging](configuring-playbook-bridge-mx-puppet-slack.md) (optional) @@ -134,6 +139,8 @@ When you're done with all the configuration you'd like to do, continue with [Ins - [Setting up MX Puppet Steam bridging](configuring-playbook-bridge-mx-puppet-steam.md) (optional) +- [Setting up Go Skype Bridge bridging](configuring-playbook-bridge-go-skype-bridge.md) (optional) + - [Setting up Email2Matrix](configuring-playbook-email2matrix.md) (optional) - [Setting up Matrix SMS bridging](configuring-playbook-bridge-matrix-bridge-sms.md) (optional) @@ -145,13 +152,28 @@ When you're done with all the configuration you'd like to do, continue with [Ins - [Setting up matrix-reminder-bot](configuring-playbook-bot-matrix-reminder-bot.md) - a bot to remind you about stuff (optional) +- [Setting up matrix-registration-bot](configuring-playbook-bot-matrix-registration-bot.md) - a bot to create and manage registration tokens to invite users (optional) + +- [Setting up maubot](configuring-playbook-bot-maubot.md) - a plugin-based Matrix bot system (optional) + - [Setting up honoroit](configuring-playbook-bot-honoroit.md) - a helpdesk bot (optional) - [Setting up Go-NEB](configuring-playbook-bot-go-neb.md) - an extensible multifunctional bot (optional) - [Setting up Mjolnir](configuring-playbook-bot-mjolnir.md) - a moderation tool/bot (optional) +- [Setting up Buscarron](configuring-playbook-bot-buscarron.md) - a bot you can use to send any form (HTTP POST, HTML) to a (encrypted) Matrix room (optional) + + +### Backups + +- [Setting up borg backup](configuring-playbook-backup-borg.md) - a full Matrix server backup solution, including the Postgres database (optional) + +- [Setting up postgres backup](configuring-playbook-postgres-backup.md) - a Postgres-database backup solution (note: does not include other files) (optional) + ### Other specialized services - [Setting up the Sygnal push gateway](configuring-playbook-sygnal.md) (optional) + +- [Setting up the ntfy push notifications server](configuring-playbook-ntfy.md) (optional) diff --git a/docs/configuring-well-known.md b/docs/configuring-well-known.md index 27a4001c..81caf04c 100644 --- a/docs/configuring-well-known.md +++ b/docs/configuring-well-known.md @@ -15,7 +15,7 @@ All services created by this playbook are meant to be installed on their own ser As [per the Server-Server specification](https://matrix.org/docs/spec/server_server/r0.1.0.html#server-discovery), to use a Matrix user identifier like `@:` while hosting services on a subdomain like `matrix.`, the Matrix network needs to be instructed of such delegation/redirection. -Server delegation can be configured using DNS SRV records or by setting up a `/.well-known/matrix/server` file on the base domain (``). +Server delegation can be configured using DNS SRV records or by setting up a `/.well-known/matrix/server` file on the base domain (``). Both methods have their place and will continue to do so. You only need to use just one of these delegation methods. For simplicity reasons, our setup advocates for the `/.well-known/matrix/server` method and guides you into using that. @@ -36,6 +36,37 @@ However, this playbook installs your Matrix server on another domain (e.g. `matr To learn how to set it up, read the Installing section below. +## (Optional) Introduction to Homeserver Admin Contact and Support page + +[MSC 1929](https://github.com/matrix-org/matrix-spec-proposals/pull/1929) specifies a way to add contact details of admins, as well as a link to a support page for users who are having issues with the service. + +This MSC did not get accepted yet, but we think it might already be useful to Homeserver admins who wish to provide this information to end-users. + +The two playbook variables that you could look for, if you're interested in being an early adopter, are: `matrix_homeserver_admin_contacts` and `matrix_homeserver_support_url`. + +Example snippet for `vars.yml`: +``` +# Enable generation of `/.well-known/matrix/support`. +# This needs to be enabled explicitly for now, because MSC 1929 is not yet accepted. +matrix_well_known_matrix_support_enabled: true + +# Homeserver admin contacts as per MSC 1929 https://github.com/matrix-org/matrix-spec-proposals/pull/1929 +matrix_homeserver_admin_contacts: + - matrix_id: "@admin1:{{ matrix_domain }}" + email_address: admin@domain.tld + role: admin + - matrix_id: "@admin2:{{ matrix_domain }}" + email_address: admin2@domain.tld + role: admin + - email_address: security@domain.tld + role: security + +matrix_homeserver_support_url: "https://example.domain.tld/support" +``` + +To learn how to set up `/.well-known/matrix/support` for the base domain, read the Installing section below. + + ## Installing well-known files on the base domain's server To implement the two service discovery mechanisms, your base domain's server (e.g. `example.com`) needs to run an HTTPS-capable webserver. @@ -46,7 +77,7 @@ If you decide to go this route, you don't need to read ahead in this document. W If you're managing the base domain by yourself somehow, you'll need to set up serving of some `/.well-known/matrix/*` files from it via HTTPS. -To make things easy for you to set up, this playbook generates and hosts 2 well-known files on the Matrix domain's server (e.g. `https://matrix.example.com/.well-known/matrix/server` and `https://matrix.example.com/.well-known/matrix/client`), even though this is the wrong place to host them. +To make things easy for you to set up, this playbook generates and hosts 2 well-known files on the Matrix domain's server. The files are generated at `/matrix/static-files/.well-known/matrix/` and hosted at `https://matrix.example.com/.well-known/matrix/server` and `https://matrix.example.com/.well-known/matrix/client`, even though this is the wrong place to host them. You have 3 options when it comes to installing the files on the base domain's server: @@ -85,12 +116,12 @@ With this method, you **don't need** to add special HTTP headers for [CORS](http **For nginx**, it would be something like this: ```nginx -# This is your HTTPS-enabled server for DOMAIN. +# This is your HTTPS-enabled server for example.com. server { - server_name DOMAIN; + server_name example.com; location /.well-known/matrix { - proxy_pass https://matrix.DOMAIN/.well-known/matrix; + proxy_pass https://matrix.example.com/.well-known/matrix; proxy_set_header X-Forwarded-For $remote_addr; } @@ -98,16 +129,15 @@ server { } ``` -**For Apache**, it would be something like this: +**For Apache2**, it would be something like this: ```apache - ServerName DOMAIN + ServerName example.com SSLProxyEngine on - - ProxyPass "https://matrix.DOMAIN/.well-known/matrix" - + ProxyPass /.well-known/matrix https://matrix.example.com/.well-known/matrix nocanon + ProxyPassReverse /.well-known/matrix https://matrix.example.com/.well-known/matrix nocanon # other configuration @@ -116,16 +146,10 @@ server { **For Caddy 2**, it would be something like this: ```caddy -reverse_proxy /.well-known/matrix/* https://matrix.DOMAIN { - header_up Host {http.reverse_proxy.upstream.hostport} -} -``` - -**For Caddy 1**, it would be something like this: - -```caddy -proxy /.well-known/matrix/ https://matrix.DOMAIN { - header_upstream Host {http.reverse_proxy.upstream.hostport} +example.com { + reverse_proxy /.well-known/matrix/* https://matrix.example.com { + header_up Host {upstream_hostport} + } } ``` @@ -152,12 +176,17 @@ backend matrix-backend ``` # In the _redirects file in the website's root -/.well-known/matrix/* https://matrix.DOMAIN/.well-known/matrix/:splat 200! +/.well-known/matrix/* https://matrix.example.com/.well-known/matrix/:splat 200! ``` +**For AWS CloudFront** + + 1. Add a custom origin with matrix. to your distribution + 1. Add two behaviors, one for `.well-known/matrix/client` and one for `.well-known/matrix/server` and point them to your new origin. + Make sure to: -- **replace `DOMAIN`** in the server configuration with your actual domain name +- **replace `example.com`** in the server configuration with your actual domain name - and: to **do this for the HTTPS-enabled server block**, as that's where Matrix expects the file to be @@ -167,5 +196,6 @@ No matter which method you've used to set up the well-known files, if you've don - `https:///.well-known/matrix/server` - `https:///.well-known/matrix/client` +- `https:///.well-known/matrix/support` You can also check if everything is configured correctly, by [checking if services work](maintenance-checking-services.md). diff --git a/docs/container-images.md b/docs/container-images.md index bf5885e0..5f0ed0e0 100644 --- a/docs/container-images.md +++ b/docs/container-images.md @@ -68,8 +68,6 @@ These services are not part of our default installation, but can be enabled by [ - [folivonet/matrix-sms-bridge](https://hub.docker.com/repository/docker/folivonet/matrix-sms-bridge) - the [matrix-sms-bridge](https://github.com/benkuly/matrix-sms-bridge) (optional) -- [sorunome/mx-puppet-skype](https://hub.docker.com/r/sorunome/mx-puppet-skype) - the [mx-puppet-skype](https://github.com/Sorunome/mx-puppet-skype) bridge to [Skype](https://www.skype.com) (optional) - - [sorunome/mx-puppet-slack](https://hub.docker.com/r/sorunome/mx-puppet-slack) - the [mx-puppet-slack](https://github.com/Sorunome/mx-puppet-slack) bridge to [Slack](https://slack.com) (optional) - [sorunome/mx-puppet-instagram](https://hub.docker.com/r/sorunome/mx-puppet-instagram) - the [mx-puppet-instagram](https://github.com/Sorunome/mx-puppet-instagram) bridge to [Instagram](https://www.instagram.com) (optional) @@ -78,7 +76,7 @@ These services are not part of our default installation, but can be enabled by [ - [sorunome/mx-puppet-discord](https://hub.docker.com/r/sorunome/mx-puppet-discord) - the [mx-puppet-discord](https://github.com/matrix-discord/mx-puppet-discord) bridge to [Discord](https://discordapp.com) (optional) -- [xangelix/mx-puppet-groupme](https://hub.docker.com/r/xangelix/mx-puppet-groupme) - the [mx-puppet-groupme](https://gitlab.com/robintown/mx-puppet-groupme) bridge to [GroupMe](https://groupme.com/) (optional) +- [xangelix/mx-puppet-groupme](https://hub.docker.com/r/xangelix/mx-puppet-groupme) - the [mx-puppet-groupme](https://gitlab.com/xangelix-pub/matrix/mx-puppet-groupme) bridge to [GroupMe](https://groupme.com/) (optional) - [icewind1991/mx-puppet-steam](https://hub.docker.com/r/icewind1991/mx-puppet-steam) - the [mx-puppet-steam](https://github.com/icewind1991/mx-puppet-steam) bridge to [Steam](https://steampowered.com) (optional) @@ -94,6 +92,10 @@ These services are not part of our default installation, but can be enabled by [ - [anoa/matrix-reminder-bot](https://hub.docker.com/r/anoa/matrix-reminder-bot) - the [matrix-reminder-bot](https://github.com/anoadragon453/matrix-reminder-bot) bot for one-off & recurring reminders and alarms (optional) +- [moanos/matrix-registration-bot/](https://hub.docker.com/r/moanos/matrix-registration-bot/) - the [matrix-registration-bot](https://github.com/moan0s/matrix-registration-bot) bot (manage registration tokens for invitations to the server) (optional) + +- [dock.mau.dev/maubot/maubot](https://mau.dev/maubot/maubot/container_registry) - the [maubot](https://github.com/maubot/maubot) bot (a plugin-based Matrix bot system) (optional) + - [etke.cc/honoroit](https://gitlab.com/etke.cc/honoroit/container_registry) - the [honoroit](https://gitlab.com/etke.cc/honoroit) helpdesk bot (optional) - [matrixdotorg/go-neb](https://hub.docker.com/r/matrixdotorg/go-neb) - the [Go-NEB](https://github.com/matrix-org/go-neb) bot (optional) @@ -109,3 +111,5 @@ These services are not part of our default installation, but can be enabled by [ - [grafana/grafana](https://hub.docker.com/r/grafana/grafana/) - [Grafana](https://github.com/grafana/grafana/) is a graphing tool that works well with the above two images. Our playbook also adds two dashboards for [Synapse](https://github.com/matrix-org/synapse/tree/master/contrib/grafana) and [Node Exporter](https://github.com/rfrail3/grafana-dashboards) - [matrixdotorg/sygnal](https://hub.docker.com/r/matrixdotorg/sygnal/) - [Sygnal](https://github.com/matrix-org/sygnal) is a reference Push Gateway for Matrix + +- [binwiederhier/ntfy](https://hub.docker.com/r/binwiederhier/ntfy/) - [ntfy](https://ntfy.sh/) is a self-hosted, UnifiedPush-compatible push notifications server diff --git a/docs/faq.md b/docs/faq.md index d9c7a586..f2df8698 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -55,7 +55,7 @@ There are 3 ways to get into Martix, depending on your technical ability and nee - **using the existing default server** - the easiest way is to use an existing server. The largest public Matrix server is `matrix.org` and it's configured as a default server in clients such as [Element](https://element.io) and many others. Just use Element on the browser via that link (or download the Element app on a smartphone), create an account and start chatting. -- **using some other server** - instead of using the largest public server (`matrix.org`), you can use another public one. Here's a [list of public Matrix servers](https://publiclist.anchel.nl/) to choose from. Again, you download [Element](https://element.io) or [some other client](https://matrix.org/clients/) of your choosing and adjust the homeserver URL during login. +- **using some other server** - instead of using the largest public server (`matrix.org`), you can use another public one. Here's a [list of public Matrix servers](https://joinmatrix.org/servers/) to choose from. Again, you download [Element](https://element.io) or [some other client](https://matrix.org/clients/) of your choosing and adjust the homeserver URL during login. - **using your own server** - running your own server puts you in ultimate control of your data. It also lets you have your own user identifiers (e.g. `@bob:your-domain.com`). See [How do I set up my own Matrix server](#how-do-i-set-up-my-own-matrix-server). diff --git a/docs/prerequisites.md b/docs/prerequisites.md index 0da1c715..1ed4befe 100644 --- a/docs/prerequisites.md +++ b/docs/prerequisites.md @@ -20,6 +20,8 @@ If your distro runs within an [LXC container](https://linuxcontainers.org/), you - The [Ansible](http://ansible.com/) program being installed on your own computer. It's used to run this playbook and configures your server for you. Take a look at [our guide about Ansible](ansible.md) for more information, as well as [version requirements](ansible.md#supported-ansible-versions) and alternative ways to run Ansible. +- [`git`](https://git-scm.com/) is the recommended way to download the playbook to your computer. `git` may also be required on the server if you will be [self-building](self-building.md) components. + - An HTTPS-capable web server at the base domain name (``) which is capable of serving static files. Unless you decide to [Serve the base domain from the Matrix server](configuring-playbook-base-domain-serving.md) or alternatively, to use DNS SRV records for [Server Delegation](howto-server-delegation.md). - Properly configured DNS records for `` (details in [Configuring DNS](configuring-dns.md)). diff --git a/docs/self-building.md b/docs/self-building.md index 9cb5bf2a..3351a1f8 100644 --- a/docs/self-building.md +++ b/docs/self-building.md @@ -33,11 +33,11 @@ List of roles where self-building the Docker image is currently possible: - `matrix-bridge-mautrix-telegram` - `matrix-bridge-mautrix-signal` - `matrix-bridge-mautrix-whatsapp` -- `matrix-bridge-mx-puppet-skype` - `matrix-bridge-mx-puppet-steam` - `matrix-bot-mjolnir` - `matrix-bot-honoroit` - `matrix-bot-matrix-reminder-bot` +- `matrix-bot-maubot` - `matrix-email2matrix` Adding self-building support to other roles is welcome. Feel free to contribute! diff --git a/examples/caddy2/Caddyfile b/examples/caddy2/Caddyfile index 6370cb01..162e539e 100644 --- a/examples/caddy2/Caddyfile +++ b/examples/caddy2/Caddyfile @@ -214,3 +214,21 @@ element.DOMAIN.tld { # } # } #} +#DOMAIN.com { +# Uncomment this if you are following "(Option 3): Setting up reverse-proxying of the well-known files from the base domain's server to the Matrix server" of https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/configuring-well-known.md#option-3-setting-up-reverse-proxying-of-the-well-known-files-from-the-base-domains-server-to-the-matrix-server +# @wellknown { +# path /.well-known/matrix/* +# } +# +# handle @wellknown { +# reverse_proxy https://matrix.DOMAIN.com { +# header_up Host {http.reverse_proxy.upstream.hostport} +# } +# } +# # Configration for the base domain goes here +# # handle { +# # header -Server +# # encode zstd gzip +# # reverse_proxy localhost:4020 +# # } +#} diff --git a/examples/host.yml b/examples/host.yml new file mode 100644 index 00000000..e9ba2810 --- /dev/null +++ b/examples/host.yml @@ -0,0 +1,11 @@ +--- + +# This is a host file for usage with the `ansible-all-hosts.sh` script, +# which runs Ansible against a bunch of hosts, each with its own `sudo` password. +matrix_servers: + hosts: + matrix.: + ansible_host: + ansible_ssh_user: + become: true + become_user: root diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 365ecd47..f519bb75 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -215,6 +215,43 @@ matrix_appservice_irc_database_password: "{{ '%s' | format(matrix_homeserver_gen # ###################################################################### +###################################################################### +# +# matrix-bridge-appservice-kakaotalk +# +###################################################################### + +# We don't enable bridges by default. +matrix_appservice_kakaotalk_enabled: false + +matrix_appservice_kakaotalk_systemd_required_services_list: | + {{ + ['docker.service'] + + + ['matrix-appservice-kakaotalk-node.service'] + + + ['matrix-' + matrix_homeserver_implementation + '.service'] + + + (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) + + + (['matrix-postgres.service'] if matrix_postgres_enabled else []) + }} + +matrix_appservice_kakaotalk_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'as.kakao.hs') | to_uuid }}" + +matrix_appservice_kakaotalk_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'as.kakao.hs') | to_uuid }}" + +matrix_appservice_kakaotalk_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" + +matrix_appservice_kakaotalk_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" +matrix_appservice_kakaotalk_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'as.kakao.db') | to_uuid }}" + +###################################################################### +# +# /matrix-bridge-appservice-kakaotalk +# +###################################################################### + ###################################################################### # @@ -254,6 +291,44 @@ matrix_beeper_linkedin_database_password: "{{ '%s' | format(matrix_homeserver_ge # ###################################################################### +###################################################################### +# +# matrix-bridge-go-skype-bridge +# +###################################################################### + +# We don't enable bridges by default. +matrix_go_skype_bridge_enabled: false + +matrix_go_skype_bridge_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm64'] }}" + +matrix_go_skype_bridge_systemd_required_services_list: | + {{ + ['docker.service'] + + + ['matrix-' + matrix_homeserver_implementation + '.service'] + + + (['matrix-postgres.service'] if matrix_postgres_enabled else []) + + + (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) + }} + +matrix_go_skype_bridge_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'skype.as.token') | to_uuid }}" + +matrix_go_skype_bridge_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'skype.hs.token') | to_uuid }}" + +matrix_go_skype_bridge_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" + +# Postgres is the default, except if not using `matrix_postgres` (internal postgres) +matrix_go_skype_bridge_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" +matrix_go_skype_bridge_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'goskype.db') | to_uuid }}" + +###################################################################### +# +# /matrix-bridge-go-skype-bridge +# +###################################################################### + ###################################################################### # # matrix-bridge-mautrix-facebook @@ -460,7 +535,7 @@ matrix_mautrix_signal_database_engine: 'postgres' matrix_mautrix_signal_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mau.signal.db') | to_uuid }}" matrix_mautrix_signal_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm64'] }}" -matrix_mautrix_signal_daemon_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" +matrix_mautrix_signal_daemon_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm64'] }}" ###################################################################### # @@ -535,14 +610,14 @@ matrix_mautrix_twitter_systemd_required_services_list: | (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) }} -matrix_mautrix_twitter_appservice_token: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'twt.as.token') | to_uuid }}" +matrix_mautrix_twitter_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'twt.as.token') | to_uuid }}" -matrix_mautrix_twitter_homeserver_token: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'twt.hs.token') | to_uuid }}" +matrix_mautrix_twitter_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'twt.hs.token') | to_uuid }}" matrix_mautrix_twitter_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" matrix_mautrix_twitter_database_hostname: "{{ 'matrix-postgres' if matrix_postgres_enabled else '' }}" -matrix_mautrix_twitter_database_password: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'mau.twt.db') | to_uuid if matrix_postgres_enabled else '' }}" +matrix_mautrix_twitter_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mau.twt.db') | to_uuid if matrix_postgres_enabled else '' }}" ###################################################################### # @@ -588,6 +663,44 @@ matrix_mautrix_whatsapp_database_password: "{{ '%s' | format(matrix_homeserver_g # ###################################################################### +###################################################################### +# +# matrix-bridge-mautrix-discord +# +###################################################################### + +# We don't enable bridges by default. +matrix_mautrix_discord_enabled: false + +matrix_mautrix_discord_container_image_self_build: "{{ matrix_architecture not in ['arm64', 'amd64'] }}" + +matrix_mautrix_discord_systemd_required_services_list: | + {{ + ['docker.service'] + + + ['matrix-' + matrix_homeserver_implementation + '.service'] + + + (['matrix-postgres.service'] if matrix_postgres_enabled else []) + + + (['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', 'maudisc.as.tok') | 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 '' }}" + +# Postgres is the default, except if not using `matrix_postgres` (internal postgres) +matrix_mautrix_discord_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" +matrix_mautrix_discord_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudiscord.db') | to_uuid }}" + +###################################################################### +# +# /matrix-bridge-mautrix-discord +# +###################################################################### + ###################################################################### # # matrix-sms-bridge @@ -675,8 +788,13 @@ matrix_hookshot_container_http_host_bind_ports: "{{ [] if matrix_nginx_proxy_ena matrix_hookshot_provisioning_enabled: "{{ matrix_hookshot_provisioning_secret and matrix_dimension_enabled }}" -matrix_hookshot_proxy_metrics: "{{ matrix_nginx_proxy_proxy_synapse_metrics }}" -matrix_hookshot_proxy_metrics_basic_auth_enabled: "{{ matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled }}" +# We only enable metrics (locally, in the container network) for the bridge if Prometheus is enabled. +# +# People using an external Prometheus server will need to toggle all of these to be able to consume metrics remotely: +# - `matrix_hookshot_metrics_enabled` +# - `matrix_hookshot_metrics_proxying_enabled` +# - `matrix_nginx_proxy_proxy_matrix_metrics_enabled` +matrix_hookshot_metrics_enabled: "{{ matrix_prometheus_enabled }}" matrix_hookshot_urlprefix_port_enabled: "{{ matrix_nginx_proxy_container_https_host_bind_port == 443 if matrix_nginx_proxy_https_enabled else matrix_nginx_proxy_container_https_host_bind_port == 80 }}" matrix_hookshot_urlprefix_port: ":{{ matrix_nginx_proxy_container_https_host_bind_port if matrix_nginx_proxy_https_enabled else matrix_nginx_proxy_container_http_host_bind_port }}" @@ -688,44 +806,6 @@ matrix_hookshot_urlprefix: "http{{ 's' if matrix_nginx_proxy_https_enabled else # ###################################################################### -###################################################################### -# -# matrix-bridge-mx-puppet-skype -# -###################################################################### - -# We don't enable bridges by default. -matrix_mx_puppet_skype_enabled: false - -matrix_mx_puppet_skype_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" - -matrix_mx_puppet_skype_systemd_required_services_list: | - {{ - ['docker.service'] - + - ['matrix-' + matrix_homeserver_implementation + '.service'] - + - (['matrix-postgres.service'] if matrix_postgres_enabled else []) - + - (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) - }} - -matrix_mx_puppet_skype_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'skype.as.tok') | to_uuid }}" - -matrix_mx_puppet_skype_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'skype.hs.tok') | to_uuid }}" - -matrix_mx_puppet_skype_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" - -# Postgres is the default, except if not using `matrix_postgres` (internal postgres) -matrix_mx_puppet_skype_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" -matrix_mx_puppet_skype_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mxpup.skype.db') | to_uuid }}" - -###################################################################### -# -# /matrix-bridge-mx-puppet-skype -# -###################################################################### - ###################################################################### # @@ -989,6 +1069,77 @@ matrix_bot_matrix_reminder_bot_container_image_self_build: "{{ matrix_architectu # ###################################################################### + +###################################################################### +# +# matrix-bot-matrix-registration-bot +# +###################################################################### + +# We don't enable bots by default. +matrix_bot_matrix_registration_bot_enabled: false + +matrix_bot_matrix_registration_bot_container_image_self_build: "{{ matrix_architecture not in ['amd64'] }}" + +matrix_bot_matrix_registration_bot_systemd_required_services_list: | + {{ + ['docker.service'] + + + ['matrix-' + matrix_homeserver_implementation + '.service'] + + + (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) + }} + + +###################################################################### +# +# /matrix-bot-matrix-registration-bot +# +###################################################################### + +###################################################################### +# +# matrix-bot-maubot +# +###################################################################### + +# We don't enable bots by default. +matrix_bot_maubot_enabled: false + +matrix_bot_maubot_container_image_self_build: "{{ matrix_architecture not in ['amd64'] }}" + +matrix_bot_maubot_systemd_required_services_list: | + {{ + ['docker.service'] + + + ['matrix-' + matrix_homeserver_implementation + '.service'] + + + (['matrix-postgres.service'] if matrix_postgres_enabled else []) + + + (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) + }} + +matrix_bot_maubot_registration_shared_secret: |- + {{ + { + 'synapse': matrix_synapse_registration_shared_secret, + 'dendrite': matrix_dendrite_registration_shared_secret, + }[matrix_homeserver_implementation] + }} + +matrix_bot_maubot_management_interface_http_bind_port: "{{ '' if matrix_nginx_proxy_enabled else ('127.0.0.1:' + matrix_bot_maubot_management_interface_port | string) }}" + +# Postgres is the default, except if not using `matrix_postgres` (internal postgres) +matrix_bot_maubot_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" +matrix_bot_maubot_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mxpup.dsc.db') | to_uuid }}" + +###################################################################### +# +# /matrix-bot-maubot +# +###################################################################### + + ###################################################################### # # matrix-bot-honoroit @@ -1020,6 +1171,37 @@ matrix_bot_honoroit_container_image_self_build: "{{ matrix_architecture not in [ # ###################################################################### +###################################################################### +# +# matrix-bot-buscarron +# +###################################################################### + +# We don't enable bots by default. +matrix_bot_buscarron_enabled: false + +matrix_bot_buscarron_systemd_required_services_list: | + {{ + ['docker.service'] + + + (['matrix-postgres.service'] if matrix_postgres_enabled else []) + + + (['matrix-synapse.service'] if matrix_synapse_enabled else []) + + + (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) + }} + +# Postgres is the default, except if not using `matrix_postgres` (internal postgres) +matrix_bot_buscarron_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" +matrix_bot_buscarron_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'buscarron.bot.db') | to_uuid }}" +matrix_bot_buscarron_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm32', 'arm64'] }}" + +###################################################################### +# +# /matrix-bot-buscarron +# +###################################################################### + ###################################################################### # @@ -1095,7 +1277,7 @@ matrix_backup_borg_postgresql_databases: | 'name': matrix_synapse_database_database }] if (matrix_synapse_enabled and matrix_synapse_database_database == matrix_postgres_db_name and matrix_synapse_database_host == 'matrix-postgres') else []) + - matrix_postgres_additional_databases)|map(attribute='name')|list + matrix_postgres_additional_databases)|map(attribute='name') | list }} matrix_backup_borg_location_source_directories: - "{{ matrix_base_data_path }}" @@ -1164,7 +1346,7 @@ matrix_corporal_matrix_registration_shared_secret: "{{ matrix_synapse_registrati matrix_coturn_enabled: true -matrix_coturn_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" +matrix_coturn_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm32', 'arm64'] }}" matrix_coturn_turn_external_ip_address: "{{ ansible_host }}" @@ -1368,7 +1550,7 @@ matrix_ma1sd_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" # Normally, matrix-nginx-proxy is enabled and nginx can reach ma1sd over the container network. # If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, you can expose # ma1sd's web-server port. -matrix_ma1sd_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_ma1sd_container_port|string }}" +matrix_ma1sd_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_ma1sd_container_port | string }}" # We enable Synapse integration via its Postgres database by default. @@ -1438,7 +1620,7 @@ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb: |- }[matrix_homeserver_implementation]|int }} -matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_synapse_admin_api_enabled: "{{ matrix_synapse_admin_enabled }}" +matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_synapse_admin_api_enabled: "{{ matrix_synapse_admin_enabled or matrix_bot_matrix_registration_bot_enabled }}" matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain: "{{ matrix_server_fqn_element if matrix_client_element_enabled else '' }}" @@ -1446,11 +1628,13 @@ matrix_nginx_proxy_proxy_matrix_enabled: true matrix_nginx_proxy_proxy_element_enabled: "{{ matrix_client_element_enabled }}" matrix_nginx_proxy_proxy_hydrogen_enabled: "{{ matrix_client_hydrogen_enabled }}" matrix_nginx_proxy_proxy_cinny_enabled: "{{ matrix_client_cinny_enabled }}" +matrix_nginx_proxy_proxy_buscarron_enabled: "{{ matrix_bot_buscarron_enabled }}" matrix_nginx_proxy_proxy_dimension_enabled: "{{ matrix_dimension_enabled }}" matrix_nginx_proxy_proxy_bot_go_neb_enabled: "{{ matrix_bot_go_neb_enabled }}" matrix_nginx_proxy_proxy_jitsi_enabled: "{{ matrix_jitsi_enabled }}" matrix_nginx_proxy_proxy_grafana_enabled: "{{ matrix_grafana_enabled }}" matrix_nginx_proxy_proxy_sygnal_enabled: "{{ matrix_sygnal_enabled }}" +matrix_nginx_proxy_proxy_ntfy_enabled: "{{ matrix_ntfy_enabled }}" matrix_nginx_proxy_proxy_matrix_corporal_api_enabled: "{{ matrix_corporal_enabled and matrix_corporal_http_api_enabled }}" matrix_nginx_proxy_proxy_matrix_corporal_api_addr_with_container: "matrix-corporal:41081" @@ -1477,14 +1661,14 @@ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container: "127.0.0.1:1 matrix_nginx_proxy_proxy_synapse_enabled: "{{ matrix_synapse_enabled }}" matrix_nginx_proxy_proxy_synapse_client_api_addr_with_container: "matrix-synapse:{{ matrix_synapse_container_client_api_port }}" matrix_nginx_proxy_proxy_synapse_client_api_addr_sans_container: "127.0.0.1:{{ matrix_synapse_container_client_api_port }}" -matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container: "matrix-synapse:{{matrix_synapse_container_federation_api_plain_port|string}}" -matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container: "localhost:{{matrix_synapse_container_federation_api_plain_port|string}}" +matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container: "matrix-synapse:{{matrix_synapse_container_federation_api_plain_port | string}}" +matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container: "127.0.0.1:{{matrix_synapse_container_federation_api_plain_port | string}}" matrix_nginx_proxy_proxy_dendrite_enabled: "{{ matrix_dendrite_enabled }}" -matrix_nginx_proxy_proxy_dendrite_client_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port|string }}" -matrix_nginx_proxy_proxy_dendrite_client_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port|string }}" -matrix_nginx_proxy_proxy_dendrite_federation_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port|string }}" -matrix_nginx_proxy_proxy_dendrite_federation_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port|string }}" +matrix_nginx_proxy_proxy_dendrite_client_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port | string }}" +matrix_nginx_proxy_proxy_dendrite_client_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port | string }}" +matrix_nginx_proxy_proxy_dendrite_federation_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port | string }}" +matrix_nginx_proxy_proxy_dendrite_federation_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port | string }}" matrix_nginx_proxy_proxy_conduit_enabled: "{{ matrix_conduit_enabled }}" matrix_nginx_proxy_proxy_conduit_client_api_addr_with_container: "matrix-conduit:{{ matrix_conduit_port_number|string }}" @@ -1497,13 +1681,6 @@ matrix_nginx_proxy_proxy_matrix_federation_port: "{{ matrix_federation_public_po matrix_nginx_proxy_container_federation_host_bind_port: "{{ matrix_federation_public_port }}" -# This used to be hooked to `matrix_synapse_metrics_enabled`, but we don't do it anymore. -# The fact that someone wishes to enable Synapse metrics does not necessarily mean they want to make them public. -# A local Prometheus can consume them over the container network. -matrix_nginx_proxy_proxy_synapse_metrics: false -matrix_nginx_proxy_proxy_synapse_metrics_addr_with_container: "matrix-synapse:{{ matrix_synapse_metrics_port }}" -matrix_nginx_proxy_proxy_synapse_metrics_addr_sans_container: "127.0.0.1:{{ matrix_synapse_metrics_port }}" - matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled: "{{ matrix_ma1sd_enabled }}" matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_with_container: "{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_with_container }}" matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_sans_container: "{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_sans_container }}" @@ -1525,8 +1702,6 @@ matrix_nginx_proxy_synapse_media_repository_locations: "{{matrix_synapse_workers matrix_nginx_proxy_synapse_user_dir_locations: "{{ matrix_synapse_workers_user_dir_endpoints|default([]) }}" matrix_nginx_proxy_synapse_frontend_proxy_locations: "{{ matrix_synapse_workers_frontend_proxy_endpoints|default([]) }}" -matrix_nginx_proxy_proxy_synapse_workers_enabled_list: "{{ matrix_synapse_workers_enabled_list }}" - matrix_nginx_proxy_systemd_wanted_services_list: | {{ ['matrix-' + matrix_homeserver_implementation + '.service'] @@ -1537,6 +1712,8 @@ matrix_nginx_proxy_systemd_wanted_services_list: | + (['matrix-client-cinny.service'] if matrix_client_cinny_enabled else []) + + (['matrix-bot-buscarron.service'] if matrix_bot_buscarron_enabled else []) + + (['matrix-client-element.service'] if matrix_client_element_enabled else []) + (['matrix-client-hydrogen.service'] if matrix_client_hydrogen_enabled else []) @@ -1547,6 +1724,8 @@ matrix_nginx_proxy_systemd_wanted_services_list: | + (['matrix-sygnal.service'] if matrix_sygnal_enabled else []) + + (['matrix-ntfy.service'] if matrix_ntfy_enabled else []) + + (['matrix-jitsi.service'] if matrix_jitsi_enabled else []) + (['matrix-bot-go-neb.service'] if matrix_bot_go_neb_enabled else []) @@ -1568,6 +1747,8 @@ matrix_ssl_domains_to_obtain_certificates_for: | + ([matrix_server_fqn_cinny] if matrix_client_cinny_enabled else []) + + ([matrix_server_fqn_buscarron] if matrix_bot_buscarron_enabled else []) + + ([matrix_server_fqn_dimension] if matrix_dimension_enabled else []) + ([matrix_server_fqn_bot_go_neb] if matrix_bot_go_neb_enabled else []) @@ -1578,6 +1759,8 @@ matrix_ssl_domains_to_obtain_certificates_for: | + ([matrix_server_fqn_sygnal] if matrix_sygnal_enabled else []) + + ([matrix_server_fqn_ntfy] if matrix_ntfy_enabled else []) + + ([matrix_domain] if matrix_nginx_proxy_base_domain_serving_enabled else []) + matrix_ssl_additional_domains_to_obtain_certificates_for @@ -1679,6 +1862,18 @@ matrix_postgres_additional_databases: | 'password': matrix_bot_honoroit_database_password, }] if (matrix_bot_honoroit_enabled and matrix_bot_honoroit_database_engine == 'postgres' and matrix_bot_honoroit_database_hostname == 'matrix-postgres') else []) + + ([{ + 'name': matrix_bot_maubot_database_name, + 'username': matrix_bot_maubot_database_username, + 'password': matrix_bot_maubot_database_password, + }] if (matrix_bot_maubot_enabled and matrix_bot_maubot_database_engine == 'postgres' and matrix_bot_maubot_database_hostname == 'matrix-postgres') else []) + + + ([{ + 'name': matrix_bot_buscarron_database_name, + 'username': matrix_bot_buscarron_database_username, + 'password': matrix_bot_buscarron_database_password, + }] if (matrix_bot_buscarron_enabled and matrix_bot_buscarron_database_engine == 'postgres' and matrix_bot_buscarron_database_hostname == 'matrix-postgres') else []) + + ([{ 'name': matrix_registration_database_name, 'username': matrix_registration_database_username, @@ -1703,12 +1898,24 @@ matrix_postgres_additional_databases: | 'password': matrix_appservice_irc_database_password, }] if (matrix_appservice_irc_enabled and matrix_appservice_irc_database_engine == 'postgres' and matrix_appservice_irc_database_hostname == 'matrix-postgres') else []) + + ([{ + 'name': matrix_appservice_kakaotalk_database_name, + 'username': matrix_appservice_kakaotalk_database_username, + 'password': matrix_appservice_kakaotalk_database_password, + }] if (matrix_appservice_kakaotalk_enabled and matrix_appservice_kakaotalk_database_engine == 'postgres' and matrix_appservice_kakaotalk_database_hostname == 'matrix-postgres') else []) + + ([{ 'name': matrix_beeper_linkedin_database_name, 'username': matrix_beeper_linkedin_database_username, 'password': matrix_beeper_linkedin_database_password, }] if (matrix_beeper_linkedin_enabled and matrix_beeper_linkedin_database_engine == 'postgres' and matrix_beeper_linkedin_database_hostname == 'matrix-postgres') else []) + + ([{ + 'name': matrix_go_skype_bridge_database_name, + 'username': matrix_go_skype_bridge_database_username, + 'password': matrix_go_skype_bridge_database_password, + }] if (matrix_go_skype_bridge_enabled and matrix_go_skype_bridge_database_engine == 'postgres' and matrix_go_skype_bridge_database_hostname == 'matrix-postgres') else []) + + ([{ 'name': matrix_mautrix_facebook_database_name, 'username': matrix_mautrix_facebook_database_username, @@ -1758,10 +1965,10 @@ matrix_postgres_additional_databases: | }] if (matrix_mautrix_whatsapp_enabled and matrix_mautrix_whatsapp_database_engine == 'postgres' and matrix_mautrix_whatsapp_database_hostname == 'matrix-postgres') else []) + ([{ - 'name': matrix_mx_puppet_skype_database_name, - 'username': matrix_mx_puppet_skype_database_username, - 'password': matrix_mx_puppet_skype_database_password, - }] if (matrix_mx_puppet_skype_enabled and matrix_mx_puppet_skype_database_engine == 'postgres' and matrix_mx_puppet_skype_database_hostname == 'matrix-postgres') else []) + 'name': matrix_mautrix_discord_database_name, + 'username': matrix_mautrix_discord_database_username, + 'password': matrix_mautrix_discord_database_password, + }] if (matrix_mautrix_discord_enabled and matrix_mautrix_discord_database_engine == 'postgres' and matrix_mautrix_discord_database_hostname == 'matrix-postgres') else []) + ([{ 'name': matrix_mx_puppet_slack_database_name, @@ -1823,14 +2030,14 @@ matrix_postgres_import_roles_to_ignore: | {{ [matrix_postgres_connection_username] + - matrix_postgres_additional_databases|map(attribute='username')|list + matrix_postgres_additional_databases|map(attribute='username') | list }} matrix_postgres_import_databases_to_ignore: | {{ [matrix_postgres_db_name] + - matrix_postgres_additional_databases|map(attribute='name')|list + matrix_postgres_additional_databases|map(attribute='name') | list }} ###################################################################### @@ -1859,6 +2066,22 @@ matrix_sygnal_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enable # ###################################################################### +###################################################################### +# +# matrix-ntfy +# +###################################################################### + +matrix_ntfy_enabled: false + +matrix_ntfy_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:2586' }}" + +###################################################################### +# +# /matrix-ntfy +# +###################################################################### + ###################################################################### # # matrix-redis @@ -1883,7 +2106,7 @@ matrix_redis_enabled: "{{ matrix_synapse_workers_enabled }}" # If you wish to connect to your Matrix server by other means, you may wish to disable this. matrix_client_element_enabled: true -matrix_client_element_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" +matrix_client_element_container_image_self_build: "{{ matrix_architecture not in ['arm64', 'amd64'] }}" # Normally, matrix-nginx-proxy is enabled and nginx can reach Element over the container network. # If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, you can expose @@ -1951,7 +2174,7 @@ matrix_client_hydrogen_self_check_validate_certificates: "{{ false if matrix_ssl matrix_client_cinny_enabled: false -matrix_client_cinny_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" +matrix_client_cinny_container_image_self_build: "{{ matrix_architecture not in ['arm64', 'amd64'] }}" # Normally, matrix-nginx-proxy is enabled and nginx can reach Cinny over the container network. # If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, you can expose @@ -1980,18 +2203,18 @@ matrix_synapse_container_image_self_build: "{{ matrix_architecture not in ['arm6 # When ma1sd is enabled, we can use it to validate email addresses and phone numbers. # Synapse can validate email addresses by itself as well, but it's probably not what we want by default when we have an identity server. -matrix_synapse_account_threepid_delegates_email: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port|string if matrix_ma1sd_enabled else '' }}" -matrix_synapse_account_threepid_delegates_msisdn: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port|string if matrix_ma1sd_enabled else '' }}" +matrix_synapse_account_threepid_delegates_email: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port | string if matrix_ma1sd_enabled else '' }}" +matrix_synapse_account_threepid_delegates_msisdn: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port | string if matrix_ma1sd_enabled else '' }}" # Normally, matrix-nginx-proxy is enabled and nginx can reach Synapse over the container network. # If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, # you can expose Synapse's ports to the host. # # For exposing the Matrix Client API's port (plain HTTP) to the local host. -matrix_synapse_container_client_api_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_client_api_port|string }}" +matrix_synapse_container_client_api_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_client_api_port | string }}" # # For exposing the Matrix Federation API's plain port (plain HTTP) to the local host. -matrix_synapse_container_federation_api_plain_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_federation_api_plain_port|string }}" +matrix_synapse_container_federation_api_plain_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_federation_api_plain_port | string }}" # # For exposing the Matrix Federation API's TLS port (HTTPS) to the internet on all network interfaces. matrix_synapse_container_federation_api_tls_host_bind_port: "{{ matrix_federation_public_port if (matrix_synapse_federation_enabled and matrix_synapse_tls_federation_listener_enabled) else '' }}" @@ -2091,7 +2314,7 @@ matrix_synapse_admin_enabled: false # Synapse Admin's HTTP port to the local host. matrix_synapse_admin_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:8766' }}" -matrix_synapse_admin_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" +matrix_synapse_admin_container_image_self_build: "{{ matrix_architecture not in ['arm64', 'amd64'] }}" ###################################################################### # @@ -2135,10 +2358,10 @@ matrix_prometheus_scraper_node_enabled: "{{ matrix_prometheus_node_exporter_enab matrix_prometheus_scraper_node_targets: "{{ ['matrix-prometheus-node-exporter:9100'] if matrix_prometheus_node_exporter_enabled else [] }}" matrix_prometheus_scraper_postgres_enabled: "{{ matrix_prometheus_postgres_exporter_enabled }}" -matrix_prometheus_scraper_postgres_targets: "{{ ['matrix-prometheus-postgres-exporter:'+ matrix_prometheus_postgres_exporter_port|string] if matrix_prometheus_scraper_postgres_enabled else [] }}" +matrix_prometheus_scraper_postgres_targets: "{{ ['matrix-prometheus-postgres-exporter:'+ matrix_prometheus_postgres_exporter_port | string] if matrix_prometheus_scraper_postgres_enabled else [] }}" matrix_prometheus_scraper_hookshot_enabled: "{{ matrix_hookshot_metrics_enabled|default(false) }}" -matrix_prometheus_scraper_hookshot_targets: "{{ [matrix_hookshot_container_url|string +':'+ matrix_hookshot_metrics_port|string] if matrix_hookshot_metrics_enabled else [] }}" +matrix_prometheus_scraper_hookshot_targets: "{{ [matrix_hookshot_container_url | string +':'+ matrix_hookshot_metrics_port | string] if matrix_hookshot_metrics_enabled else [] }}" ###################################################################### # @@ -2268,7 +2491,7 @@ matrix_postgres_backup_databases: | 'name': matrix_synapse_database_database }] if (matrix_synapse_enabled and matrix_synapse_database_database == matrix_postgres_db_name and matrix_synapse_database_host == 'matrix-postgres') else []) + - matrix_postgres_additional_databases)|map(attribute='name')|list + matrix_postgres_additional_databases)|map(attribute='name') | list }} ###################################################################### @@ -2290,16 +2513,16 @@ matrix_dendrite_enabled: "{{ matrix_homeserver_implementation == 'dendrite' }}" # you can expose Dendrite's ports to the host. # # For exposing Dendrite's plain HTTP server to the local host. -matrix_dendrite_container_http_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled else ('127.0.0.1:' + matrix_dendrite_http_bind_port|string) }}" +matrix_dendrite_container_http_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled else ('127.0.0.1:' + matrix_dendrite_http_bind_port | string) }}" # # For exposing Dendrite's HTTPS server to the local host. -matrix_dendrite_container_https_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled or not matrix_dendrite_https_bind_port else ('127.0.0.1:' + matrix_dendrite_https_bind_port|string) }}" +matrix_dendrite_container_https_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled or not matrix_dendrite_https_bind_port else ('127.0.0.1:' + matrix_dendrite_https_bind_port | string) }}" matrix_dendrite_sync_api_real_ip_header: "{{ 'X-Forwarded-For' if matrix_nginx_proxy_enabled else '' }}" -matrix_dendrite_registration_shared_secret: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'dendrite.rss') | to_uuid }}" +matrix_dendrite_registration_shared_secret: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'dendrite.rss') | to_uuid }}" -matrix_dendrite_database_password: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'dendrite.db') | to_uuid }}" +matrix_dendrite_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'dendrite.db') | to_uuid }}" # Even if TURN doesn't support TLS (it does by default), # it doesn't hurt to try a secure connection anyway. diff --git a/inventory/scripts/ansible-all-hosts.sh b/inventory/scripts/ansible-all-hosts.sh new file mode 100755 index 00000000..3b611ab3 --- /dev/null +++ b/inventory/scripts/ansible-all-hosts.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# Run the playbook on multiple hosts with different credentials with this script +# It defaults to ansible tags "setup-all,start". You can pass alternative tags +# to this script as arguments, e.g. +# +# ./inventory/scripts/ansible-all-hosts.sh self-check +# + +# set playbook root path +root=$(dirname "$(readlink -f "$0")")/../.. + +# set default tags or get from first argument if any +tags="${1:-setup-all,start}" + +# init password array +declare -A pws + +# capture passwords for all hosts +for host in "$root"/inventory/*.yml; do + read -rp "sudo password for $(basename "$host"): " -s pw + pws[$host]="$pw" + echo +done + +# run ansible on all captured passwords/hosts +for host in "${!pws[@]}"; do + ansible-playbook "$root"/setup.yml \ + --inventory-file "$host" \ + --extra-vars "ansible_become_pass=${pws[$host]}" \ + --tags="$tags" +done diff --git a/inventory/scripts/jitsi-generate-passwords.sh b/inventory/scripts/jitsi-generate-passwords.sh index c48a0c2d..f24a3fba 100755 --- a/inventory/scripts/jitsi-generate-passwords.sh +++ b/inventory/scripts/jitsi-generate-passwords.sh @@ -18,7 +18,7 @@ JIBRI_XMPP_PASSWORD=$(generatePassword) echo "# Paste these variables into your inventory/host_vars/matrix.DOMAIN/vars.yml file:" echo "" -echo "matrix_jitsi_jicofo_auth_password: "$JICOFO_AUTH_PASSWORD -echo "matrix_jitsi_jvb_auth_password: "$JVB_AUTH_PASSWORD -echo "matrix_jitsi_jibri_recorder_password: "$JIBRI_RECORDER_PASSWORD -echo "matrix_jitsi_jibri_xmpp_password: "$JIBRI_XMPP_PASSWORD +echo "matrix_jitsi_jicofo_auth_password: $JICOFO_AUTH_PASSWORD" +echo "matrix_jitsi_jvb_auth_password: $JVB_AUTH_PASSWORD" +echo "matrix_jitsi_jibri_recorder_password: $JIBRI_RECORDER_PASSWORD" +echo "matrix_jitsi_jibri_xmpp_password: $JIBRI_XMPP_PASSWORD" diff --git a/roles/matrix-aux/tasks/main.yml b/roles/matrix-aux/tasks/main.yml index 2585715b..df7c77d0 100644 --- a/roles/matrix-aux/tasks/main.yml +++ b/roles/matrix-aux/tasks/main.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/setup.yml" - when: run_stop|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" + when: run_stop | bool tags: - setup-all - setup-aux-files diff --git a/roles/matrix-aux/tasks/setup.yml b/roles/matrix-aux/tasks/setup.yml index 949c0b4a..ccb0bdcb 100644 --- a/roles/matrix-aux/tasks/setup.yml +++ b/roles/matrix-aux/tasks/setup.yml @@ -1,19 +1,19 @@ --- - name: Ensure AUX directories are created - file: + ansible.builtin.file: dest: "{{ item.dest }}" state: directory - owner: "{{ item.owner|default(matrix_user_username) }}" - group: "{{ item.group|default(matrix_user_groupname) }}" - mode: "{{ item.mode|default(matrix_aux_directory_default_mode) }}" + owner: "{{ item.owner | default(matrix_user_username) }}" + group: "{{ item.group | default(matrix_user_groupname) }}" + mode: "{{ item.mode | default(matrix_aux_directory_default_mode) }}" with_items: "{{ matrix_aux_directory_definitions }}" - name: Ensure AUX files are created - copy: + ansible.builtin.copy: dest: "{{ item.dest }}" content: "{{ item.content }}" - owner: "{{ item.owner|default(matrix_user_username) }}" - group: "{{ item.group|default(matrix_user_groupname) }}" - mode: "{{ item.mode|default(matrix_aux_file_default_mode) }}" + owner: "{{ item.owner | default(matrix_user_username) }}" + group: "{{ item.group | default(matrix_user_groupname) }}" + mode: "{{ item.mode | default(matrix_aux_file_default_mode) }}" with_items: "{{ matrix_aux_file_definitions }}" diff --git a/roles/matrix-backup-borg/defaults/main.yml b/roles/matrix-backup-borg/defaults/main.yml index 906522c2..89381788 100644 --- a/roles/matrix-backup-borg/defaults/main.yml +++ b/roles/matrix-backup-borg/defaults/main.yml @@ -1,4 +1,6 @@ --- +# Project source code URL: https://gitlab.com/etke.cc/borgmatic + matrix_backup_borg_enabled: true matrix_backup_borg_base_path: "{{ matrix_base_data_path }}/backup-borg" @@ -6,13 +8,14 @@ matrix_backup_borg_config_path: "{{ matrix_backup_borg_base_path }}/config" matrix_backup_borg_container_image_self_build: false matrix_backup_borg_docker_repo: "https://gitlab.com/etke.cc/borgmatic" +matrix_backup_borg_docker_repo_version: main matrix_backup_borg_docker_src_files_path: "{{ matrix_backup_borg_base_path }}/docker-src" # version determined automatically, based on postgres server version (if enabled), otherwise latest is used matrix_backup_borg_version: "" matrix_backup_borg_docker_image: "{{ matrix_backup_borg_docker_image_name_prefix }}etke.cc/borgmatic:{{ matrix_backup_borg_version }}" matrix_backup_borg_docker_image_name_prefix: "{{ 'localhost/' if matrix_backup_borg_container_image_self_build else 'registry.gitlab.com/' }}" -matrix_backup_borg_docker_image_force_pull: "{{ matrix_backup_borg_docker_image.endswith(':latest') or matrix_backup_borg_version|default('') == '' }}" +matrix_backup_borg_docker_image_force_pull: "{{ matrix_backup_borg_docker_image.endswith(':latest') or matrix_backup_borg_version | default('') == '' }}" # A list of extra arguments to pass to the container matrix_backup_borg_container_extra_arguments: [] @@ -91,8 +94,8 @@ matrix_backup_borg_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_backup_borg_configuration_yaml`. -matrix_backup_borg_configuration_extension: "{{ matrix_backup_borg_configuration_extension_yaml|from_yaml if matrix_backup_borg_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_backup_borg_configuration_extension: "{{ matrix_backup_borg_configuration_extension_yaml | from_yaml if matrix_backup_borg_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final borgmatic configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_backup_borg_configuration_yaml`. -matrix_backup_borg_configuration: "{{ matrix_backup_borg_configuration_yaml|from_yaml|combine(matrix_backup_borg_configuration_extension, recursive=True) }}" +matrix_backup_borg_configuration: "{{ matrix_backup_borg_configuration_yaml | from_yaml | combine(matrix_backup_borg_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-backup-borg/tasks/init.yml b/roles/matrix-backup-borg/tasks/init.yml index 0a90a2e8..d57f1249 100644 --- a/roles/matrix-backup-borg/tasks/init.yml +++ b/roles/matrix-backup-borg/tasks/init.yml @@ -1,4 +1,4 @@ --- -- set_fact: - matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-backup-borg.service', 'matrix-backup-borg.timer'] }}" - when: matrix_backup_borg_enabled|bool +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-backup-borg.timer'] }}" + when: matrix_backup_borg_enabled | bool diff --git a/roles/matrix-backup-borg/tasks/main.yml b/roles/matrix-backup-borg/tasks/main.yml index 0dbf54e1..5de4559c 100644 --- a/roles/matrix-backup-borg/tasks/main.yml +++ b/roles/matrix-backup-borg/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_backup_borg_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_backup_borg_enabled | bool" tags: - setup-all - setup-backup-borg -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_backup_borg_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_backup_borg_enabled | bool" tags: - setup-all - setup-backup-borg -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_backup_borg_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_backup_borg_enabled | bool" tags: - setup-all - setup-backup-borg diff --git a/roles/matrix-backup-borg/tasks/setup_install.yml b/roles/matrix-backup-borg/tasks/setup_install.yml index 6ef39863..e3401a13 100644 --- a/roles/matrix-backup-borg/tasks/setup_install.yml +++ b/roles/matrix-backup-borg/tasks/setup_install.yml @@ -1,19 +1,29 @@ --- + - block: - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml" + - name: Fail with matrix_backup_borg_version advice if Postgres not enabled + ansible.builtin.fail: + msg: >- + You are not running a built-in Postgres server (`matrix_postgres_enabled: false`), so auto-detecting its version and setting `matrix_backup_borg_version` automatically based on that cannot happen. + Consider setting `matrix_backup_borg_version` to your Postgres version manually. + when: not matrix_postgres_enabled + + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: detect_existing_postgres_version - name: Fail if detected Postgres version is unsupported - fail: + ansible.builtin.fail: msg: "You cannot use borg backup with such an old version ({{ matrix_postgres_detected_version }}) of Postgres. Consider upgrading - link to docs for upgrading Postgres: docs/maintenance-postgres.md#upgrading-postgresql" when: "matrix_postgres_detected_version not in matrix_backup_borg_supported_postgres_versions" - name: Set the correct borg backup version to use - set_fact: + ansible.builtin.set_fact: matrix_backup_borg_version: "{{ matrix_postgres_detected_version }}" - when: matrix_backup_borg_postgresql_enabled|bool and matrix_backup_borg_version == '' + when: matrix_backup_borg_postgresql_enabled | bool and matrix_backup_borg_version == '' - name: Ensure borg paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -22,18 +32,18 @@ with_items: - {path: "{{ matrix_backup_borg_config_path }}", when: true} - {path: "{{ matrix_backup_borg_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure borgmatic config is created - copy: - content: "{{ matrix_backup_borg_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_backup_borg_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_backup_borg_config_path }}/config.yaml" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - name: Ensure borg passwd is created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/passwd.j2" dest: "{{ matrix_backup_borg_config_path }}/passwd" owner: "{{ matrix_user_username }}" @@ -41,7 +51,7 @@ mode: 0640 - name: Ensure borg ssh key is created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/sshkey.j2" dest: "{{ matrix_backup_borg_config_path }}/sshkey" owner: "{{ matrix_user_username }}" @@ -54,21 +64,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_backup_borg_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_backup_borg_docker_image_force_pull }}" - when: "not matrix_backup_borg_container_image_self_build|bool" + when: "not matrix_backup_borg_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure borg repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_backup_borg_docker_repo }}" + version: "{{ matrix_backup_borg_docker_repo_version }}" dest: "{{ matrix_backup_borg_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_backup_borg_git_pull_results - when: "matrix_backup_borg_container_image_self_build|bool" + when: "matrix_backup_borg_container_image_self_build | bool" - name: Ensure borg image is built docker_image: @@ -80,33 +91,33 @@ dockerfile: Dockerfile path: "{{ matrix_backup_borg_docker_src_files_path }}" pull: true - when: "matrix_backup_borg_container_image_self_build|bool" + when: "matrix_backup_borg_container_image_self_build | bool" - name: Ensure matrix-backup-borg.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-backup-borg.service.j2" dest: "{{ matrix_systemd_path }}/matrix-backup-borg.service" mode: 0644 register: matrix_backup_borg_systemd_service_result - name: Ensure matrix-backup-borg.timer installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-backup-borg.timer.j2" dest: "{{ matrix_systemd_path }}/matrix-backup-borg.timer" mode: 0644 register: matrix_backup_borg_systemd_timer_result - name: Ensure systemd reloaded after matrix-backup-borg.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_backup_borg_systemd_service_result.changed|bool" + when: "matrix_backup_borg_systemd_service_result.changed | bool" - name: Ensure matrix-backup-borg.service enabled - service: + ansible.builtin.service: enabled: true name: matrix-backup-borg.service - name: Ensure matrix-backup-borg.timer enabled - service: + ansible.builtin.service: enabled: true name: matrix-backup-borg.timer diff --git a/roles/matrix-backup-borg/tasks/setup_uninstall.yml b/roles/matrix-backup-borg/tasks/setup_uninstall.yml index faad44f7..fb583f57 100644 --- a/roles/matrix-backup-borg/tasks/setup_uninstall.yml +++ b/roles/matrix-backup-borg/tasks/setup_uninstall.yml @@ -1,37 +1,37 @@ --- - name: Check existence of matrix-backup-borg service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-backup-borg.service" register: matrix_backup_borg_service_stat - name: Ensure matrix-backup-borg is stopped - service: + ansible.builtin.service: name: matrix-backup-borg state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure matrix-backup-borg.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-backup-borg.service" state: absent - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure matrix-backup-borg.timer doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-backup-borg.timer" state: absent - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-backup-borg.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure Matrix borg paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_backup_borg_base_path }}" state: absent diff --git a/roles/matrix-backup-borg/tasks/validate_config.yml b/roles/matrix-backup-borg/tasks/validate_config.yml index 84b78d1e..66e487dd 100644 --- a/roles/matrix-backup-borg/tasks/validate_config.yml +++ b/roles/matrix-backup-borg/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -9,7 +9,7 @@ - "matrix_backup_borg_location_repositories" - name: Fail if encryption passphrase is undefined unless repository is unencrypted - fail: + ansible.builtin.fail: msg: >- You need to define a required passphrase using the `matrix_backup_borg_storage_encryption_passphrase` variable. when: "matrix_backup_borg_storage_encryption_passphrase == '' and matrix_backup_borg_encryption != 'none'" diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index 9d0ded4a..6d69f3e5 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -8,6 +8,25 @@ # Example value: example.com matrix_domain: ~ +# The optional matrix admin MXID, used in bridges' configs to set bridge admin user +# Example value: "@someone:{{ matrix_domain }}" +matrix_admin: '' + +# Homeserver admin contacts and support page as per MSC 1929 +# See: https://github.com/matrix-org/matrix-spec-proposals/pull/1929 +# Users in form: +# matrix_homeserver_admin_contacts: +# - matrix_id: @admin:domain.tld +# email_address: admin@domain.tld +# role: admin +# - email_address: security@domain.tld +# role: security +# Also see: `matrix_well_known_matrix_support_enabled` +matrix_homeserver_admin_contacts: [] +# Url string like https://domain.tld/support.html +# Also see: `matrix_well_known_matrix_support_enabled` +matrix_homeserver_support_url: '' + # This will contain the homeserver implementation that is in use. # Valid values: synapse, dendrite, conduit # @@ -37,6 +56,9 @@ matrix_server_fqn_hydrogen: "hydrogen.{{ matrix_domain }}" # This is where you access the Cinny web client from (if enabled via matrix_client_cinny_enabled; disabled by default). matrix_server_fqn_cinny: "cinny.{{ matrix_domain }}" +# This is where you access the buscarron bot from (if enabled via matrix_bot_buscarron_enabled; disabled by default). +matrix_server_fqn_buscarron: "buscarron.{{ matrix_domain }}" + # This is where you access the Dimension. matrix_server_fqn_dimension: "dimension.{{ matrix_domain }}" @@ -52,6 +74,9 @@ matrix_server_fqn_grafana: "stats.{{ matrix_domain }}" # This is where you access the Sygnal push gateway. matrix_server_fqn_sygnal: "sygnal.{{ matrix_domain }}" +# This is where you access the ntfy push notification service. +matrix_server_fqn_ntfy: "ntfy.{{ matrix_domain }}" + matrix_federation_public_port: 8448 # The architecture that your server runs. @@ -71,6 +96,10 @@ matrix_container_global_registry_prefix: "docker.io/" matrix_container_retries_count: 10 matrix_container_retries_delay: 10 +# Each get_url will retry on failed attempt 10 times with delay of 10 seconds between each attempt. +matrix_geturl_retries_count: 10 +matrix_geturl_retries_delay: 10 + matrix_user_username: "matrix" matrix_user_groupname: "matrix" @@ -105,8 +134,8 @@ matrix_host_command_openssl: "/usr/bin/env openssl" matrix_host_command_systemctl: "/usr/bin/env systemctl" matrix_host_command_sh: "/usr/bin/env sh" -matrix_ntpd_package: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version|int > 18) else ( 'systemd' if ansible_os_family == 'Suse' else 'ntp' ) }}" -matrix_ntpd_service: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version|int > 18) or ansible_distribution == 'Archlinux' or ansible_os_family == 'Suse' else ('ntpd' if ansible_os_family == 'RedHat' else 'ntp') }}" +matrix_ntpd_package: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version | int > 18) else ( 'systemd' if ansible_os_family == 'Suse' else 'ntp' ) }}" +matrix_ntpd_service: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version | int > 18) or ansible_distribution == 'Archlinux' or ansible_os_family == 'Suse' else ('ntpd' if ansible_os_family == 'RedHat' else 'ntp') }}" matrix_homeserver_url: "https://{{ matrix_server_fqn_matrix }}" @@ -128,7 +157,7 @@ matrix_integration_manager_ui_url: ~ # The domain name where a Jitsi server is self-hosted. # If set, `/.well-known/matrix/client` will suggest Element clients to use that Jitsi server. # See: https://github.com/vector-im/element-web/blob/develop/docs/jitsi.md#configuring-element-to-use-your-self-hosted-jitsi-server -matrix_client_element_jitsi_preferredDomain: '' +matrix_client_element_jitsi_preferredDomain: '' # noqa var-naming # Controls whether Element should use End-to-End Encryption by default. # Setting this to false will update `/.well-known/matrix/client` and tell Element clients to avoid E2EE. @@ -173,11 +202,11 @@ matrix_well_known_matrix_client_configuration_default: "{{ lookup('template', 't # } matrix_well_known_matrix_client_configuration_extension_json: '{}' -matrix_well_known_matrix_client_configuration_extension: "{{ matrix_well_known_matrix_client_configuration_extension_json|from_json if matrix_well_known_matrix_client_configuration_extension_json|from_json is mapping else {} }}" +matrix_well_known_matrix_client_configuration_extension: "{{ matrix_well_known_matrix_client_configuration_extension_json | from_json if matrix_well_known_matrix_client_configuration_extension_json | from_json is mapping else {} }}" # Holds the final `/.well-known/matrix/client` configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_well_known_matrix_client_configuration_default` and `matrix_well_known_matrix_client_configuration_extension_json`. -matrix_well_known_matrix_client_configuration: "{{ matrix_well_known_matrix_client_configuration_default|combine(matrix_well_known_matrix_client_configuration_extension, recursive=True) }}" +matrix_well_known_matrix_client_configuration: "{{ matrix_well_known_matrix_client_configuration_default | combine(matrix_well_known_matrix_client_configuration_extension, recursive=True) }}" # Default `/.well-known/matrix/server` configuration - it covers the generic use case. # You can customize it by controlling the various variables inside the template file that it references. @@ -205,11 +234,23 @@ matrix_well_known_matrix_server_configuration_default: "{{ lookup('template', 't # } matrix_well_known_matrix_server_configuration_extension_json: '{}' -matrix_well_known_matrix_server_configuration_extension: "{{ matrix_well_known_matrix_server_configuration_extension_json|from_json if matrix_well_known_matrix_server_configuration_extension_json|from_json is mapping else {} }}" +matrix_well_known_matrix_server_configuration_extension: "{{ matrix_well_known_matrix_server_configuration_extension_json | from_json if matrix_well_known_matrix_server_configuration_extension_json | from_json is mapping else {} }}" # Holds the final `/.well-known/matrix/server` configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_well_known_matrix_server_configuration_default` and `matrix_well_known_matrix_server_configuration_extension_json`. -matrix_well_known_matrix_server_configuration: "{{ matrix_well_known_matrix_server_configuration_default|combine(matrix_well_known_matrix_server_configuration_extension, recursive=True) }}" +matrix_well_known_matrix_server_configuration: "{{ matrix_well_known_matrix_server_configuration_default | combine(matrix_well_known_matrix_server_configuration_extension, recursive=True) }}" + +# The side-effect of this lookup is that Ansible would even parse the JSON for us, returning a dict. +# This is unlike what it does when looking up YAML template files (no automatic parsing there). +matrix_well_known_matrix_support_configuration_default: "{{ lookup('template', 'templates/static-files/well-known/matrix-support.j2') }}" + +matrix_well_known_matrix_support_configuration_extension_json: '{}' + +matrix_well_known_matrix_support_configuration_extension: "{{ matrix_well_known_matrix_support_configuration_extension_json | from_json if matrix_well_known_matrix_support_configuration_extension_json | from_json is mapping else {} }}" + +# Holds the final `/.well-known/matrix/support` configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_well_known_matrix_support_configuration_default` and `matrix_well_known_matrix_support_configuration_extension_json`. +matrix_well_known_matrix_support_configuration: "{{ matrix_well_known_matrix_support_configuration_default | combine(matrix_well_known_matrix_support_configuration_extension, recursive=True) }}" # The Docker network that all services would be put into matrix_docker_network: "matrix" @@ -228,6 +269,13 @@ matrix_vars_yml_snapshotting_src: "{{ inventory_dir }}/host_vars/{{ inventory_ho # matrix domain (`matrix_server_fqn_matrix`). matrix_well_known_matrix_server_enabled: true +# Controls whether a `/.well-known/matrix/support` file is generated and used at all. +# +# This is not enabled by default, until the MSC gets accepted: https://github.com/matrix-org/matrix-spec-proposals/pull/1929 +# +# See `matrix_homeserver_admin_contacts`, `matrix_homeserver_support_url`, etc. +matrix_well_known_matrix_support_enabled: false + # Controls whether Docker is automatically installed. # If you change this to false you must install and update Docker manually. You also need to install the docker (https://pypi.org/project/docker/) Python package. matrix_docker_installation_enabled: true diff --git a/roles/matrix-base/tasks/clean_up_old_files.yml b/roles/matrix-base/tasks/clean_up_old_files.yml index 03eb8bcc..b79c01b3 100644 --- a/roles/matrix-base/tasks/clean_up_old_files.yml +++ b/roles/matrix-base/tasks/clean_up_old_files.yml @@ -1,7 +1,7 @@ --- - name: Get rid of old files and directories - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: diff --git a/roles/matrix-base/tasks/main.yml b/roles/matrix-base/tasks/main.yml index 1cdc0432..2205056d 100644 --- a/roles/matrix-base/tasks/main.yml +++ b/roles/matrix-base/tasks/main.yml @@ -1,34 +1,34 @@ --- -- import_tasks: "{{ role_path }}/tasks/sanity_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/sanity_check.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/clean_up_old_files.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/clean_up_old_files.yml" + when: run_setup | bool tags: - setup-all -- import_tasks: "{{ role_path }}/tasks/server_base/setup.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/server_base/setup.yml" + when: run_setup | bool tags: - setup-all # This needs to always run, because it populates `matrix_user_uid` and `matrix_user_gid`, # which are required by many other roles. -- import_tasks: "{{ role_path }}/tasks/setup_matrix_user.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_matrix_user.yml" + when: run_setup | bool tags: - always - setup-system-user -- import_tasks: "{{ role_path }}/tasks/setup_matrix_base.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_matrix_base.yml" + when: run_setup | bool tags: - setup-all -- import_tasks: "{{ role_path }}/tasks/setup_well_known.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_well_known.yml" + when: run_setup | bool tags: - setup-all - setup-ma1sd diff --git a/roles/matrix-base/tasks/sanity_check.yml b/roles/matrix-base/tasks/sanity_check.yml index ad3d35d6..5104ba43 100644 --- a/roles/matrix-base/tasks/sanity_check.yml +++ b/roles/matrix-base/tasks/sanity_check.yml @@ -1,27 +1,27 @@ --- - name: Fail if invalid homeserver implementation - fail: + ansible.builtin.fail: msg: "You need to set a valid homeserver implementation in `matrix_homeserver_implementation`" when: "matrix_homeserver_implementation not in ['synapse', 'dendrite', 'conduit']" # We generally support Ansible 2.7.1 and above. - name: Fail if running on Ansible < 2.7.1 - fail: + ansible.builtin.fail: msg: "You are running on Ansible {{ ansible_version.string }}, which is not supported. See our guide about Ansible: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/ansible.md" when: - "(ansible_version.major < 2) or (ansible_version.major == 2 and ansible_version.minor < 7) or (ansible_version.major == 2 and ansible_version.minor == 7 and ansible_version.revision < 1)" # Though we do not support Ansible 2.9.6 which is buggy - name: Fail if running on Ansible 2.9.6 on Ubuntu - fail: + ansible.builtin.fail: msg: "You are running on Ansible {{ ansible_version.string }}, which is not supported. See our guide about Ansible: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/ansible.md" when: - ansible_distribution == 'Ubuntu' - "ansible_version.major == 2 and ansible_version.minor == 9 and ansible_version.revision == 6" - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). @@ -35,7 +35,7 @@ # We have a dedicated check for this variable, because we'd like to have a custom (friendlier) message. - name: Fail if matrix_homeserver_generic_secret_key is undefined - fail: + ansible.builtin.fail: msg: | The `matrix_homeserver_generic_secret_key` variable must be defined and have a non-null and non-empty value. @@ -47,35 +47,45 @@ when: "matrix_homeserver_generic_secret_key is none or matrix_homeserver_generic_secret_key == ''" - name: Fail if required variables are undefined - fail: + ansible.builtin.fail: msg: "The `{{ item.var }}` variable must be defined and have a non-null and non-empty value" with_items: - - {'var': matrix_domain, 'value': "{{ matrix_domain|default('') }}"} - - {'var': matrix_server_fqn_matrix, 'value': "{{ matrix_server_fqn_matrix|default('') }}"} - - {'var': matrix_server_fqn_element, 'value': "{{ matrix_server_fqn_element|default('') }}"} - - {'var': matrix_homeserver_container_url, 'value': "{{ matrix_homeserver_container_url|default('') }}"} - - {'var': matrix_homeserver_container_federation_url, 'value': "{{ matrix_homeserver_container_federation_url|default('') }}"} + - {'var': matrix_domain, 'value': "{{ matrix_domain | default('') }}"} + - {'var': matrix_server_fqn_matrix, 'value': "{{ matrix_server_fqn_matrix | default('') }}"} + - {'var': matrix_server_fqn_element, 'value': "{{ matrix_server_fqn_element | default('') }}"} + - {'var': matrix_homeserver_container_url, 'value': "{{ matrix_homeserver_container_url | default('') }}"} + - {'var': matrix_homeserver_container_federation_url, 'value': "{{ matrix_homeserver_container_federation_url | default('') }}"} when: "item.value is none or item.value == ''" - name: Fail if uppercase domain used - fail: + ansible.builtin.fail: msg: "Detected that you're using an uppercase domain name - `{{ item }}`. This will cause trouble. Please use all-lowercase!" with_items: - "{{ matrix_domain }}" - "{{ matrix_server_fqn_matrix }}" - "{{ matrix_server_fqn_element }}" - when: "item != item|lower" + when: "item != item | lower" - name: Fail if using python2 on Archlinux - fail: + ansible.builtin.fail: msg: "Detected that you're using python2 when installing onto Archlinux. Archlinux by default only supports python3." when: - ansible_distribution == 'Archlinux' - ansible_python.version.major != 3 - name: Fail if architecture is set incorrectly - fail: + ansible.builtin.fail: msg: "Detected that variable matrix_architecture {{ matrix_architecture }} appears to be set incorrectly. See docs/alternative-architectures.md. Server appears to be {{ ansible_architecture }}." when: (ansible_architecture == "x86_64" and matrix_architecture != "amd64") or (ansible_architecture == "aarch64" and matrix_architecture != "arm64") or (ansible_architecture.startswith("armv") and matrix_architecture != "arm32") + +- name: Fail if encountering usage of removed role (mx-puppet-skype) + ansible.builtin.fail: + msg: >- + Your configuration seems to include a reference to `matrix_mx_puppet_skype_enabled`. Are you trying to install the mx-puppet-skype bridge? + The playbook no longer includes a role for installing mx-puppet-skype, because the mx-puppet-bridge is unmaintained and has been reported as broken for a long time. + To get rid of this error, remove all `matrix_mx_puppet_*` references from your configuration. + To clean up your server from mx-puppet-skype's presence, see this changelog entry: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/CHANGELOG.md#mx-puppet-skype-removal. + If you still need bridging to Skype, consider switching to the go-skype bridge instead. See `docs/configuring-playbook-bridge-go-skype-bridge.md`. + when: "'matrix_mx_puppet_skype_enabled' in vars" diff --git a/roles/matrix-base/tasks/server_base/setup.yml b/roles/matrix-base/tasks/server_base/setup.yml index bbfa077c..40d5a4d0 100644 --- a/roles/matrix-base/tasks/server_base/setup.yml +++ b/roles/matrix-base/tasks/server_base/setup.yml @@ -1,18 +1,18 @@ --- -- include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat.yml" - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int < 8 +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat.yml" + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int < 8 -- include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat8.yml" - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 7 and ansible_distribution_major_version|int < 30 +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat8.yml" + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 7 and ansible_distribution_major_version | int < 30 -- include_tasks: "{{ role_path }}/tasks/server_base/setup_fedora.yml" - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 30 +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_fedora.yml" + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 30 - block: # ansible_lsb is only available if lsb-release is installed. - name: Ensure lsb-release installed - apt: + ansible.builtin.apt: name: - lsb-release state: present @@ -20,27 +20,27 @@ register: lsb_release_installation_result - name: Reread ansible_lsb facts if lsb-release got installed - setup: filter=ansible_lsb* + ansible.builtin.setup: filter=ansible_lsb* when: lsb_release_installation_result.changed - - include_tasks: "{{ role_path }}/tasks/server_base/setup_debian.yml" + - ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_debian.yml" when: (ansible_os_family == 'Debian') and (ansible_lsb.id != 'Raspbian') - - include_tasks: "{{ role_path }}/tasks/server_base/setup_raspbian.yml" + - ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_raspbian.yml" when: (ansible_os_family == 'Debian') and (ansible_lsb.id == 'Raspbian') when: ansible_os_family == 'Debian' -- include_tasks: "{{ role_path }}/tasks/server_base/setup_archlinux.yml" +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_archlinux.yml" when: ansible_distribution == 'Archlinux' - name: Ensure Docker is started and autoruns - service: + ansible.builtin.service: name: docker state: started enabled: true - name: "Ensure {{ matrix_ntpd_service }} is started and autoruns" - service: + ansible.builtin.service: name: "{{ matrix_ntpd_service }}" state: started enabled: true diff --git a/roles/matrix-base/tasks/server_base/setup_archlinux.yml b/roles/matrix-base/tasks/server_base/setup_archlinux.yml index a4912a5d..c912e58f 100644 --- a/roles/matrix-base/tasks/server_base/setup_archlinux.yml +++ b/roles/matrix-base/tasks/server_base/setup_archlinux.yml @@ -5,12 +5,12 @@ name: - python-docker - python-dnspython - state: latest + state: present update_cache: true - name: Ensure Docker is installed pacman: name: - docker - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_debian.yml b/roles/matrix-base/tasks/server_base/setup_debian.yml index 5b169df7..271fab41 100644 --- a/roles/matrix-base/tasks/server_base/setup_debian.yml +++ b/roles/matrix-base/tasks/server_base/setup_debian.yml @@ -1,7 +1,7 @@ --- - name: Ensure APT usage dependencies are installed - apt: + ansible.builtin.apt: name: - apt-transport-https - ca-certificates @@ -10,32 +10,32 @@ update_cache: true - name: Ensure Docker's APT key is trusted - apt_key: - url: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg" + ansible.builtin.apt_key: + url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg" id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 state: present register: add_repository_key ignore_errors: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker repository is enabled - apt_repository: - repo: "deb [arch={{ matrix_debian_arch }}] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable" + ansible.builtin.apt_repository: + repo: "deb [arch={{ matrix_debian_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable" state: present update_cache: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure APT packages are installed - apt: + ansible.builtin.apt: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - apt: + ansible.builtin.apt: name: - "{{ matrix_docker_package_name }}" - - "python{{'3' if ansible_python.version.major == 3 else ''}}-docker" - state: latest - when: matrix_docker_installation_enabled|bool + - "python{{ '3' if ansible_python.version.major == 3 else '' }}-docker" + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_fedora.yml b/roles/matrix-base/tasks/server_base/setup_fedora.yml index 7369b6ad..2c7d528f 100644 --- a/roles/matrix-base/tasks/server_base/setup_fedora.yml +++ b/roles/matrix-base/tasks/server_base/setup_fedora.yml @@ -1,7 +1,7 @@ --- - name: Ensure Docker repository is enabled - template: + ansible.builtin.template: src: "{{ role_path }}/files/yum.repos.d/{{ item }}" dest: "/etc/yum.repos.d/docker-ce.repo" owner: "root" @@ -9,31 +9,31 @@ mode: 0644 with_items: - docker-ce-fedora.repo - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker's RPM key is trusted - rpm_key: + ansible.builtin.rpm_key: state: present key: https://download.docker.com/linux/fedora/gpg - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure yum packages are installed - yum: + ansible.builtin.yum: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - yum: + ansible.builtin.yum: name: - "{{ matrix_docker_package_name }}" - python3-pip - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool - name: Ensure Docker-Py is installed - pip: + ansible.builtin.pip: name: docker-py - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_raspbian.yml b/roles/matrix-base/tasks/server_base/setup_raspbian.yml index 6a09f2fe..54ea4d18 100644 --- a/roles/matrix-base/tasks/server_base/setup_raspbian.yml +++ b/roles/matrix-base/tasks/server_base/setup_raspbian.yml @@ -1,7 +1,7 @@ --- - name: Ensure APT usage dependencies are installed - apt: + ansible.builtin.apt: name: - apt-transport-https - ca-certificates @@ -10,32 +10,32 @@ update_cache: true - name: Ensure Docker's APT key is trusted - apt_key: + ansible.builtin.apt_key: url: https://download.docker.com/linux/raspbian/gpg id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 state: present register: add_repository_key ignore_errors: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker repository is enabled - apt_repository: + ansible.builtin.apt_repository: repo: "deb [arch={{ matrix_debian_arch }}] https://download.docker.com/linux/raspbian {{ ansible_distribution_release }} stable" state: present update_cache: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure APT packages are installed - apt: + ansible.builtin.apt: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - apt: + ansible.builtin.apt: name: - "{{ matrix_docker_package_name }}" - "python{{'3' if ansible_python.version.major == 3 else ''}}-docker" - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_redhat.yml b/roles/matrix-base/tasks/server_base/setup_redhat.yml index b4be1d08..4e5c97d4 100644 --- a/roles/matrix-base/tasks/server_base/setup_redhat.yml +++ b/roles/matrix-base/tasks/server_base/setup_redhat.yml @@ -1,31 +1,31 @@ --- - name: Ensure Docker repository is enabled - template: + ansible.builtin.template: src: "{{ role_path }}/files/yum.repos.d/docker-ce-centos.repo" dest: "/etc/yum.repos.d/docker-ce.repo" owner: "root" group: "root" mode: 0644 - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker's RPM key is trusted - rpm_key: + ansible.builtin.rpm_key: state: present key: https://download.docker.com/linux/centos/gpg - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure yum packages are installed - yum: + ansible.builtin.yum: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - yum: + ansible.builtin.yum: name: - "{{ matrix_docker_package_name }}" - docker-python - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_redhat8.yml b/roles/matrix-base/tasks/server_base/setup_redhat8.yml index d9dd6e23..932dbab5 100644 --- a/roles/matrix-base/tasks/server_base/setup_redhat8.yml +++ b/roles/matrix-base/tasks/server_base/setup_redhat8.yml @@ -1,44 +1,44 @@ --- - name: Ensure Docker repository is enabled - template: + ansible.builtin.template: src: "{{ role_path }}/files/yum.repos.d/docker-ce-centos.repo" dest: "/etc/yum.repos.d/docker-ce.repo" owner: "root" group: "root" mode: 0644 - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker's RPM key is trusted - rpm_key: + ansible.builtin.rpm_key: state: present key: https://download.docker.com/linux/centos/gpg - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure EPEL is installed - yum: + ansible.builtin.yum: name: - epel-release - state: latest + state: present update_cache: true - name: Ensure yum packages are installed - yum: + ansible.builtin.yum: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - yum: + ansible.builtin.yum: name: - "{{ matrix_docker_package_name }}" - python3-pip - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool - name: Ensure Docker-Py is installed - pip: + ansible.builtin.pip: name: docker-py - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 0fad2b3d..2e860987 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -1,7 +1,7 @@ --- - name: Ensure Matrix base path exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: "{{ matrix_base_data_path_mode }}" @@ -11,13 +11,13 @@ - "{{ matrix_base_data_path }}" - name: Preserve vars.yml on the server for easily restoring if it gets lost later on - copy: + ansible.builtin.copy: src: "{{ matrix_vars_yml_snapshotting_src }}" dest: "{{ matrix_base_data_path }}/vars.yml" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: '0660' - when: "matrix_vars_yml_snapshotting_enabled|bool" + when: "matrix_vars_yml_snapshotting_enabled | bool" - name: Ensure Matrix network is created in Docker docker_network: @@ -25,7 +25,7 @@ driver: bridge - name: Ensure matrix-remove-all script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-remove-all.j2" dest: "{{ matrix_local_bin_path }}/matrix-remove-all" mode: 0750 diff --git a/roles/matrix-base/tasks/setup_matrix_user.yml b/roles/matrix-base/tasks/setup_matrix_user.yml index 41604f87..0435b7a3 100644 --- a/roles/matrix-base/tasks/setup_matrix_user.yml +++ b/roles/matrix-base/tasks/setup_matrix_user.yml @@ -1,18 +1,18 @@ --- - name: Ensure Matrix group is created - group: + ansible.builtin.group: name: "{{ matrix_user_groupname }}" gid: "{{ omit if matrix_user_gid is none else matrix_user_gid }}" state: present register: matrix_group - name: Set Matrix Group GID Variable - set_fact: + ansible.builtin.set_fact: matrix_user_gid: "{{ matrix_group.gid }}" - name: Ensure Matrix user is created - user: + ansible.builtin.user: name: "{{ matrix_user_username }}" uid: "{{ omit if matrix_user_uid is none else matrix_user_uid }}" state: present @@ -23,5 +23,5 @@ register: matrix_user - name: Set Matrix Group UID Variable - set_fact: + ansible.builtin.set_fact: matrix_user_uid: "{{ matrix_user.uid }}" diff --git a/roles/matrix-base/tasks/setup_well_known.yml b/roles/matrix-base/tasks/setup_well_known.yml index 3f475950..d51e93d3 100644 --- a/roles/matrix-base/tasks/setup_well_known.yml +++ b/roles/matrix-base/tasks/setup_well_known.yml @@ -4,7 +4,7 @@ # # For running with another webserver, we recommend being part of the `matrix` group. - name: Ensure Matrix static-files path exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0755 @@ -14,24 +14,39 @@ - "{{ matrix_static_files_base_path }}/.well-known/matrix" - name: Ensure Matrix /.well-known/matrix/client file configured - copy: - content: "{{ matrix_well_known_matrix_client_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_well_known_matrix_client_configuration | to_nice_json }}" dest: "{{ matrix_static_files_base_path }}/.well-known/matrix/client" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Matrix /.well-known/matrix/server file configured - copy: - content: "{{ matrix_well_known_matrix_server_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_well_known_matrix_server_configuration | to_nice_json }}" dest: "{{ matrix_static_files_base_path }}/.well-known/matrix/server" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_well_known_matrix_server_enabled|bool + when: matrix_well_known_matrix_server_enabled | bool - name: Ensure Matrix /.well-known/matrix/server file deleted - file: + ansible.builtin.file: path: "{{ matrix_static_files_base_path }}/.well-known/matrix/server" state: absent - when: "not matrix_well_known_matrix_server_enabled|bool" + when: "not matrix_well_known_matrix_server_enabled | bool" + +- name: Ensure Matrix /.well-known/matrix/support file configured + ansible.builtin.copy: + content: "{{ matrix_well_known_matrix_support_configuration | to_nice_json }}" + dest: "{{ matrix_static_files_base_path }}/.well-known/matrix/support" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + when: matrix_well_known_matrix_support_enabled | bool + +- name: Ensure Matrix /.well-known/matrix/support file deleted + ansible.builtin.file: + path: "{{ matrix_static_files_base_path }}/.well-known/matrix/support" + state: absent + when: "not matrix_well_known_matrix_support_enabled | bool" diff --git a/roles/matrix-base/tasks/util/ensure_fuse_installed.yml b/roles/matrix-base/tasks/util/ensure_fuse_installed.yml index 7a3fde41..47d2d9e8 100644 --- a/roles/matrix-base/tasks/util/ensure_fuse_installed.yml +++ b/roles/matrix-base/tasks/util/ensure_fuse_installed.yml @@ -1,23 +1,23 @@ --- # This is for both RedHat 7 and 8 - name: Ensure fuse installed (RedHat) - yum: + ansible.builtin.yum: name: - fuse - state: latest + state: present when: ansible_os_family == 'RedHat' # This is for both Debian and Raspbian - name: Ensure fuse installed (Debian/Raspbian) - apt: + ansible.builtin.apt: name: - fuse - state: latest + state: present when: ansible_os_family == 'Debian' - name: Ensure fuse installed (Archlinux) pacman: name: - fuse3 - state: latest + state: present when: ansible_distribution == 'Archlinux' diff --git a/roles/matrix-base/tasks/util/ensure_openssl_installed.yml b/roles/matrix-base/tasks/util/ensure_openssl_installed.yml index 53fc9b03..ae22fb49 100644 --- a/roles/matrix-base/tasks/util/ensure_openssl_installed.yml +++ b/roles/matrix-base/tasks/util/ensure_openssl_installed.yml @@ -1,23 +1,23 @@ --- # This is for both RedHat 7 and 8 - name: Ensure openssl installed (RedHat) - yum: + ansible.builtin.yum: name: - openssl - state: latest + state: present when: ansible_os_family == 'RedHat' # This is for both Debian and Raspbian - name: Ensure openssl installed (Debian/Raspbian) - apt: + ansible.builtin.apt: name: - openssl - state: latest + state: present when: ansible_os_family == 'Debian' - name: Ensure openssl installed (Archlinux) pacman: name: - openssl - state: latest + state: present when: ansible_distribution == 'Archlinux' diff --git a/roles/matrix-base/templates/static-files/well-known/matrix-support.j2 b/roles/matrix-base/templates/static-files/well-known/matrix-support.j2 new file mode 100644 index 00000000..97e76012 --- /dev/null +++ b/roles/matrix-base/templates/static-files/well-known/matrix-support.j2 @@ -0,0 +1,7 @@ +#jinja2: lstrip_blocks: "True" +{ + "admins": {{ matrix_homeserver_admin_contacts|to_json }} + {% if matrix_homeserver_support_url %}, + "support_page": {{ matrix_homeserver_support_url|to_json }} + {% endif %} +} diff --git a/roles/matrix-bot-buscarron/defaults/main.yml b/roles/matrix-bot-buscarron/defaults/main.yml new file mode 100644 index 00000000..6d289bb9 --- /dev/null +++ b/roles/matrix-bot-buscarron/defaults/main.yml @@ -0,0 +1,118 @@ +--- +# buscarron is a helpdesk bot +# Project source code URL: https://gitlab.com/etke.cc/buscarron + +matrix_bot_buscarron_enabled: true + +matrix_bot_buscarron_container_image_self_build: false +matrix_bot_buscarron_docker_repo: "https://gitlab.com/etke.cc/buscarron.git" +matrix_bot_buscarron_docker_repo_version: "{{ matrix_bot_buscarron_version }}" +matrix_bot_buscarron_docker_src_files_path: "{{ matrix_base_data_path }}/buscarron/docker-src" + +matrix_bot_buscarron_version: v1.2.0 +matrix_bot_buscarron_docker_image: "{{ matrix_bot_buscarron_docker_image_name_prefix }}buscarron:{{ matrix_bot_buscarron_version }}" +matrix_bot_buscarron_docker_image_name_prefix: "{{ 'localhost/' if matrix_bot_buscarron_container_image_self_build else 'registry.gitlab.com/etke.cc/' }}" +matrix_bot_buscarron_docker_image_force_pull: "{{ matrix_bot_buscarron_docker_image.endswith(':latest') }}" + +matrix_bot_buscarron_base_path: "{{ matrix_base_data_path }}/buscarron" +matrix_bot_buscarron_config_path: "{{ matrix_bot_buscarron_base_path }}/config" +matrix_bot_buscarron_data_path: "{{ matrix_bot_buscarron_base_path }}/data" +matrix_bot_buscarron_data_store_path: "{{ matrix_bot_buscarron_data_path }}/store" + +# A list of extra arguments to pass to the container +matrix_bot_buscarron_container_extra_arguments: [] + +# List of systemd services that matrix-bot-buscarron.service depends on +matrix_bot_buscarron_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-bot-buscarron.service wants +matrix_bot_buscarron_systemd_wanted_services_list: [] + + +# Database-related configuration fields. +# +# To use SQLite, stick to these defaults. +# +# To use Postgres: +# - change the engine (`matrix_bot_buscarron_database_engine: 'postgres'`) +# - adjust your database credentials via the `matrix_bot_buscarron_database_*` variables +matrix_bot_buscarron_database_engine: 'sqlite' + +matrix_bot_buscarron_sqlite_database_path_local: "{{ matrix_bot_buscarron_data_path }}/bot.db" +matrix_bot_buscarron_sqlite_database_path_in_container: "/data/bot.db" + +matrix_bot_buscarron_database_username: 'buscarron' +matrix_bot_buscarron_database_password: 'some-password' +matrix_bot_buscarron_database_hostname: 'matrix-postgres' +matrix_bot_buscarron_database_port: 5432 +matrix_bot_buscarron_database_name: 'buscarron' + +matrix_bot_buscarron_database_connection_string: 'postgres://{{ matrix_bot_buscarron_database_username }}:{{ matrix_bot_buscarron_database_password }}@{{ matrix_bot_buscarron_database_hostname }}:{{ matrix_bot_buscarron_database_port }}/{{ matrix_bot_buscarron_database_name }}?sslmode=disable' + +matrix_bot_buscarron_storage_database: "{{ + { + 'sqlite': matrix_bot_buscarron_sqlite_database_path_in_container, + 'postgres': matrix_bot_buscarron_database_connection_string, + }[matrix_bot_buscarron_database_engine] +}}" + +matrix_bot_buscarron_database_dialect: "{{ + { + 'sqlite': 'sqlite3', + 'postgres': 'postgres', + }[matrix_bot_buscarron_database_engine] +}}" + + +# The bot's username. This user needs to be created manually beforehand. +# Also see `matrix_bot_buscarron_password`. +matrix_bot_buscarron_login: "bot.buscarron" + +# The password that the bot uses to authenticate. +matrix_bot_buscarron_password: '' + +# the homeserver URL, uses internal synapse container address by default +matrix_bot_buscarron_homeserver: "{{ matrix_homeserver_container_url }}" + +# forms configuration +matrix_bot_buscarron_forms: [] + +# Disable encryption +matrix_bot_buscarron_noencryption: + +# Sentry DSN +matrix_bot_buscarron_sentry: + +# Log level +matrix_bot_buscarron_loglevel: INFO + +# spam hosts/domains +matrix_bot_buscarron_spam_hosts: [] + +# spam email addresses +matrix_bot_buscarron_spam_emails: [] + +# spam email localparts +matrix_bot_buscarron_spam_localparts: [] + +# Ban duration in hours +matrix_bot_buscarron_ban_duration: 24 + +# Banlist size +matrix_bot_buscarron_ban_size: 10000 + +# Postmark token (confirmation emails) +matrix_bot_buscarron_pm_token: + +# Postmark sender signature +matrix_bot_buscarron_pm_from: + +# Postmark confirmation email's reply-to +matrix_bot_buscarron_pm_replyto: + +# Additional environment variables to pass to the buscarron container +# +# Example: +# matrix_bot_buscarron_environment_variables_extension: | +# BUSCARRON_LOGLEVEL=DEBUG +matrix_bot_buscarron_environment_variables_extension: '' diff --git a/roles/matrix-bot-buscarron/tasks/init.yml b/roles/matrix-bot-buscarron/tasks/init.yml new file mode 100644 index 00000000..a1f5751d --- /dev/null +++ b/roles/matrix-bot-buscarron/tasks/init.yml @@ -0,0 +1,5 @@ +--- + +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-buscarron.service'] }}" + when: matrix_bot_buscarron_enabled | bool diff --git a/roles/matrix-bot-buscarron/tasks/main.yml b/roles/matrix-bot-buscarron/tasks/main.yml new file mode 100644 index 00000000..e6712262 --- /dev/null +++ b/roles/matrix-bot-buscarron/tasks/main.yml @@ -0,0 +1,23 @@ +--- + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_buscarron_enabled | bool" + tags: + - setup-all + - setup-bot-buscarron + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_buscarron_enabled | bool" + tags: + - setup-all + - setup-bot-buscarron + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_buscarron_enabled | bool" + tags: + - setup-all + - setup-bot-buscarron diff --git a/roles/matrix-bot-buscarron/tasks/setup_install.yml b/roles/matrix-bot-buscarron/tasks/setup_install.yml new file mode 100644 index 00000000..0db7b728 --- /dev/null +++ b/roles/matrix-bot-buscarron/tasks/setup_install.yml @@ -0,0 +1,103 @@ +--- +- ansible.builtin.set_fact: + matrix_bot_buscarron_requires_restart: false + +- block: + - name: Check if an SQLite database already exists + ansible.builtin.stat: + path: "{{ matrix_bot_buscarron_sqlite_database_path_local }}" + register: matrix_bot_buscarron_sqlite_database_path_local_stat_result + + - block: + - ansible.builtin.set_fact: + matrix_postgres_db_migration_request: + src: "{{ matrix_bot_buscarron_sqlite_database_path_local }}" + dst: "{{ matrix_bot_buscarron_database_connection_string }}" + caller: "{{ role_path | basename }}" + engine_variable_name: 'matrix_bot_buscarron_database_engine' + engine_old: 'sqlite' + systemd_services_to_stop: ['matrix-bot-buscarron.service'] + + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres + + - ansible.builtin.set_fact: + matrix_bot_buscarron_requires_restart: true + when: "matrix_bot_buscarron_sqlite_database_path_local_stat_result.stat.exists | bool" + when: "matrix_bot_buscarron_database_engine == 'postgres'" + +- name: Ensure buscarron paths exist + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_bot_buscarron_config_path }}", when: true} + - {path: "{{ matrix_bot_buscarron_data_path }}", when: true} + - {path: "{{ matrix_bot_buscarron_data_store_path }}", when: true} + - {path: "{{ matrix_bot_buscarron_docker_src_files_path }}", when: true} + when: "item.when | bool" + +- name: Ensure buscarron environment variables file created + ansible.builtin.template: + src: "{{ role_path }}/templates/env.j2" + dest: "{{ matrix_bot_buscarron_config_path }}/env" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: 0640 + +- name: Ensure buscarron image is pulled + docker_image: + name: "{{ matrix_bot_buscarron_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_bot_buscarron_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_bot_buscarron_docker_image_force_pull }}" + when: "not matrix_bot_buscarron_container_image_self_build | bool" + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure buscarron repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_bot_buscarron_docker_repo }}" + version: "{{ matrix_bot_buscarron_docker_repo_version }}" + dest: "{{ matrix_bot_buscarron_docker_src_files_path }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_bot_buscarron_git_pull_results + when: "matrix_bot_buscarron_container_image_self_build | bool" + +- name: Ensure buscarron image is built + docker_image: + name: "{{ matrix_bot_buscarron_docker_image }}" + source: build + force_source: "{{ matrix_bot_buscarron_git_pull_results.changed 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_mailer_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_bot_buscarron_docker_src_files_path }}" + pull: true + when: "matrix_bot_buscarron_container_image_self_build | bool" + +- name: Ensure matrix-bot-buscarron.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-bot-buscarron.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service" + mode: 0644 + register: matrix_bot_buscarron_systemd_service_result + +- name: Ensure systemd reloaded after matrix-bot-buscarron.service installation + ansible.builtin.service: + daemon_reload: true + when: "matrix_bot_buscarron_systemd_service_result.changed | bool" + +- name: Ensure matrix-bot-buscarron.service restarted, if necessary + ansible.builtin.service: + name: "matrix-bot-buscarron.service" + state: restarted + when: "matrix_bot_buscarron_requires_restart | bool" diff --git a/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml b/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml new file mode 100644 index 00000000..ad9e78cd --- /dev/null +++ b/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml @@ -0,0 +1,36 @@ +--- + +- name: Check existence of matrix-buscarron service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service" + register: matrix_bot_buscarron_service_stat + +- name: Ensure matrix-buscarron is stopped + ansible.builtin.service: + name: matrix-bot-buscarron + state: stopped + enabled: false + daemon_reload: true + register: stopping_result + when: "matrix_bot_buscarron_service_stat.stat.exists | bool" + +- name: Ensure matrix-bot-buscarron.service doesn't exist + ansible.builtin.file: + path: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service" + state: absent + when: "matrix_bot_buscarron_service_stat.stat.exists | bool" + +- name: Ensure systemd reloaded after matrix-bot-buscarron.service removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_bot_buscarron_service_stat.stat.exists | bool" + +- name: Ensure Matrix buscarron paths don't exist + ansible.builtin.file: + path: "{{ matrix_bot_buscarron_base_path }}" + state: absent + +- name: Ensure buscarron Docker image doesn't exist + docker_image: + name: "{{ matrix_bot_buscarron_docker_image }}" + state: absent diff --git a/roles/matrix-bridge-mx-puppet-skype/tasks/validate_config.yml b/roles/matrix-bot-buscarron/tasks/validate_config.yml similarity index 63% rename from roles/matrix-bridge-mx-puppet-skype/tasks/validate_config.yml rename to roles/matrix-bot-buscarron/tasks/validate_config.yml index 7ed433b1..04238012 100644 --- a/roles/matrix-bridge-mx-puppet-skype/tasks/validate_config.yml +++ b/roles/matrix-bot-buscarron/tasks/validate_config.yml @@ -1,10 +1,9 @@ --- - 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_mx_puppet_skype_appservice_token" - - "matrix_mx_puppet_skype_homeserver_token" + - "matrix_bot_buscarron_password" diff --git a/roles/matrix-bot-buscarron/templates/env.j2 b/roles/matrix-bot-buscarron/templates/env.j2 new file mode 100644 index 00000000..42da0d34 --- /dev/null +++ b/roles/matrix-bot-buscarron/templates/env.j2 @@ -0,0 +1,29 @@ +BUSCARRON_LOGIN={{ matrix_bot_buscarron_login }} +BUSCARRON_PASSWORD={{ matrix_bot_buscarron_password }} +BUSCARRON_HOMESERVER={{ matrix_bot_buscarron_homeserver }} +BUSCARRON_DB_DSN={{ matrix_bot_buscarron_database_connection_string }} +BUSCARRON_DB_DIALECT={{ matrix_bot_buscarron_database_dialect }} +BUSCARRON_SPAM_HOSTS={{ matrix_bot_buscarron_spam_hosts|join(" ") }} +BUSCARRON_SPAM_EMAILS={{ matrix_bot_buscarron_spam_emails|join(" ") }} +BUSCARRON_SPAM_LOCALPARTS={{ matrix_bot_buscarron_spam_localparts|join(" ") }} +BUSCARRON_SENTRY={{ matrix_bot_buscarron_sentry }} +BUSCARRON_LOGLEVEL={{ matrix_bot_buscarron_loglevel }} +BUSCARRON_BAN_DURATION={{ matrix_bot_buscarron_ban_duration }} +BUSCARRON_BAN_SIZE={{ matrix_bot_buscarron_ban_size }} +BUSCARRON_PM_TOKEN={{ matrix_bot_buscarron_pm_token }} +BUSCARRON_PM_FROM={{ matrix_bot_buscarron_pm_from }} +BUSCARRON_PM_REPLYTO={{ matrix_bot_buscarron_pm_replyto }} +BUSCARRON_NOENCRYPTION={{ matrix_bot_buscarron_noencryption }} +{% set forms = [] %} +{% for form in matrix_bot_buscarron_forms -%}{{- forms.append(form.name) -}} +BUSCARRON_{{ form.name|upper }}_ROOM={{ form.room|default('') }} +BUSCARRON_{{ form.name|upper }}_REDIRECT={{ form.redirect|default('') }} +BUSCARRON_{{ form.name|upper }}_HASDOMAIN={{ form.hasdomain|default('') }} +BUSCARRON_{{ form.name|upper }}_RATELIMIT={{ form.ratelimit|default('') }} +BUSCARRON_{{ form.name|upper }}_EXTENSIONS={{ form.extensions|default('')|join(' ') }} +BUSCARRON_{{ form.name|upper }}_CONFIRMATION_SUBJECT={{ form.confirmation_subject|default('') }} +BUSCARRON_{{ form.name|upper }}_CONFIRMATION_BODY={{ form.confirmation_body|default('') }} +{% endfor %} +BUSCARRON_LIST={{ forms|join(" ") }} + +{{ matrix_bot_buscarron_environment_variables_extension }} diff --git a/roles/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 b/roles/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 new file mode 100644 index 00000000..fd6d0310 --- /dev/null +++ b/roles/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 @@ -0,0 +1,39 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Matrix web forms bot +{% for service in matrix_bot_buscarron_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_bot_buscarron_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-bot-buscarron 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-bot-buscarron 2>/dev/null || true' + +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-bot-buscarron \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --read-only \ + --network={{ matrix_docker_network }} \ + --env-file={{ matrix_bot_buscarron_config_path }}/env \ + --mount type=bind,src={{ matrix_bot_buscarron_data_path }},dst=/data \ + {% for arg in matrix_bot_buscarron_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + {{ matrix_bot_buscarron_docker_image }} + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-bot-buscarron 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-bot-buscarron 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-bot-buscarron + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-bot-go-neb/defaults/main.yml b/roles/matrix-bot-go-neb/defaults/main.yml index fa57b109..61c5d54d 100644 --- a/roles/matrix-bot-go-neb/defaults/main.yml +++ b/roles/matrix-bot-go-neb/defaults/main.yml @@ -1,6 +1,6 @@ --- # Go-NEB is a Matrix bot written in Go. It is the successor to Matrix-NEB, the original Matrix bot written in Python. -# See: https://github.com/matrix-org/go-neb +# Project source code URL: https://github.com/matrix-org/go-neb matrix_bot_go_neb_enabled: true matrix_bot_go_neb_version: latest @@ -224,8 +224,8 @@ matrix_bot_go_neb_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_bot_go_neb_configuration_yaml`. -matrix_bot_go_neb_configuration_extension: "{{ matrix_bot_go_neb_configuration_extension_yaml|from_yaml if matrix_bot_go_neb_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_bot_go_neb_configuration_extension: "{{ matrix_bot_go_neb_configuration_extension_yaml | from_yaml if matrix_bot_go_neb_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_bot_go_neb_configuration_yaml`. -matrix_bot_go_neb_configuration: "{{ matrix_bot_go_neb_configuration_yaml|from_yaml|combine(matrix_bot_go_neb_configuration_extension, recursive=True) }}" +matrix_bot_go_neb_configuration: "{{ matrix_bot_go_neb_configuration_yaml | from_yaml | combine(matrix_bot_go_neb_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-bot-go-neb/tasks/init.yml b/roles/matrix-bot-go-neb/tasks/init.yml index b046d494..9d5b4f89 100644 --- a/roles/matrix-bot-go-neb/tasks/init.yml +++ b/roles/matrix-bot-go-neb/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-go-neb.service'] }}" - when: matrix_bot_go_neb_enabled|bool + when: matrix_bot_go_neb_enabled | bool diff --git a/roles/matrix-bot-go-neb/tasks/main.yml b/roles/matrix-bot-go-neb/tasks/main.yml index 3c2ed9c5..27487ac5 100644 --- a/roles/matrix-bot-go-neb/tasks/main.yml +++ b/roles/matrix-bot-go-neb/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_go_neb_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_go_neb_enabled | bool" tags: - setup-all - setup-bot-go-neb -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_go_neb_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_go_neb_enabled | bool" tags: - setup-all - setup-bot-go-neb -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_go_neb_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_go_neb_enabled | bool" tags: - setup-all - setup-bot-go-neb diff --git a/roles/matrix-bot-go-neb/tasks/setup_install.yml b/roles/matrix-bot-go-neb/tasks/setup_install.yml index ef2dfbb0..a651c160 100644 --- a/roles/matrix-bot-go-neb/tasks/setup_install.yml +++ b/roles/matrix-bot-go-neb/tasks/setup_install.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_go_neb_requires_restart: false - name: Ensure go-neb paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,7 +14,7 @@ - {path: "{{ matrix_bot_go_neb_config_path }}", when: true} - {path: "{{ matrix_bot_go_neb_data_path }}", when: true} - {path: "{{ matrix_bot_go_neb_data_store_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure go-neb image is pulled docker_image: @@ -28,27 +28,27 @@ until: result is not failed - name: Ensure go-neb config installed - copy: - content: "{{ matrix_bot_go_neb_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_bot_go_neb_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_bot_go_neb_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-bot-go-neb.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-go-neb.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-go-neb.service" mode: 0644 register: matrix_bot_go_neb_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-go-neb.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_go_neb_systemd_service_result.changed|bool" + when: "matrix_bot_go_neb_systemd_service_result.changed | bool" - name: Ensure matrix-bot-go-neb.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-go-neb.service" state: restarted - when: "matrix_bot_go_neb_requires_restart|bool" + when: "matrix_bot_go_neb_requires_restart | bool" diff --git a/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml b/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml index a009badf..9794a90a 100644 --- a/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-go-neb service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-go-neb.service" register: matrix_bot_go_neb_service_stat - name: Ensure matrix-go-neb is stopped - service: + ansible.builtin.service: name: matrix-bot-go-neb state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_go_neb_service_stat.stat.exists|bool" + when: "matrix_bot_go_neb_service_stat.stat.exists | bool" - name: Ensure matrix-bot-go-neb.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-go-neb.service" state: absent - when: "matrix_bot_go_neb_service_stat.stat.exists|bool" + when: "matrix_bot_go_neb_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-go-neb.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_go_neb_service_stat.stat.exists|bool" + when: "matrix_bot_go_neb_service_stat.stat.exists | bool" - name: Ensure Matrix go-neb paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_go_neb_base_path }}" state: absent diff --git a/roles/matrix-bot-go-neb/tasks/validate_config.yml b/roles/matrix-bot-go-neb/tasks/validate_config.yml index 7b292250..72bc3cb4 100644 --- a/roles/matrix-bot-go-neb/tasks/validate_config.yml +++ b/roles/matrix-bot-go-neb/tasks/validate_config.yml @@ -1,13 +1,13 @@ --- - name: Fail if there's not at least 1 client - fail: + ansible.builtin.fail: msg: >- You need at least 1 client in the matrix_bot_go_neb_clients block. when: matrix_bot_go_neb_clients is not defined or matrix_bot_go_neb_clients[0] is not defined - name: Fail if there's not at least 1 service - fail: + ansible.builtin.fail: msg: >- You need at least 1 service in the matrix_bot_go_neb_services block. when: matrix_bot_go_neb_services is not defined or matrix_bot_go_neb_services[0] is not defined diff --git a/roles/matrix-bot-honoroit/defaults/main.yml b/roles/matrix-bot-honoroit/defaults/main.yml index 9e7cf2b5..fe0b0981 100644 --- a/roles/matrix-bot-honoroit/defaults/main.yml +++ b/roles/matrix-bot-honoroit/defaults/main.yml @@ -1,14 +1,15 @@ --- # honoroit is a helpdesk bot -# See: https://gitlab.com/etke.cc/honoroit +# Project source code URL: https://gitlab.com/etke.cc/honoroit matrix_bot_honoroit_enabled: true matrix_bot_honoroit_container_image_self_build: false matrix_bot_honoroit_docker_repo: "https://gitlab.com/etke.cc/honoroit.git" +matrix_bot_honoroit_docker_repo_version: "{{ matrix_bot_honoroit_version }}" matrix_bot_honoroit_docker_src_files_path: "{{ matrix_base_data_path }}/honoroit/docker-src" -matrix_bot_honoroit_version: v0.9.7 +matrix_bot_honoroit_version: v0.9.12 matrix_bot_honoroit_docker_image: "{{ matrix_bot_honoroit_docker_image_name_prefix }}honoroit:{{ matrix_bot_honoroit_version }}" matrix_bot_honoroit_docker_image_name_prefix: "{{ 'localhost/' if matrix_bot_honoroit_container_image_self_build else 'registry.gitlab.com/etke.cc/' }}" matrix_bot_honoroit_docker_image_force_pull: "{{ matrix_bot_honoroit_docker_image.endswith(':latest') }}" @@ -84,15 +85,27 @@ matrix_bot_honoroit_sentry: '' # Log level matrix_bot_honoroit_loglevel: '' +# Disable encryption +matrix_bot_honoroit_noencryption: false + # Max items in cache matrix_bot_honoroit_cachesize: '' +# List of ignored room IDs +matrix_bot_honoroit_ignoredrooms: [] + +# Ignore messages outside of threads +matrix_bot_honoroit_ignorenothread: false + # Text prefix: open matrix_bot_honoroit_text_prefix_open: '' # Text prefix: done matrix_bot_honoroit_text_prefix_done: '' +# Text: no encryption +matrix_bot_honoroit_text_noencryption: '' + # Text: greetings matrix_bot_honoroit_text_greetings: '' diff --git a/roles/matrix-bot-honoroit/tasks/init.yml b/roles/matrix-bot-honoroit/tasks/init.yml index 5ace015b..1b03373c 100644 --- a/roles/matrix-bot-honoroit/tasks/init.yml +++ b/roles/matrix-bot-honoroit/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-honoroit.service'] }}" - when: matrix_bot_honoroit_enabled|bool + when: matrix_bot_honoroit_enabled | bool diff --git a/roles/matrix-bot-honoroit/tasks/main.yml b/roles/matrix-bot-honoroit/tasks/main.yml index 7d66177c..5de468fe 100644 --- a/roles/matrix-bot-honoroit/tasks/main.yml +++ b/roles/matrix-bot-honoroit/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_honoroit_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_honoroit_enabled | bool" tags: - setup-all - setup-bot-honoroit -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_honoroit_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_honoroit_enabled | bool" tags: - setup-all - setup-bot-honoroit -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_honoroit_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_honoroit_enabled | bool" tags: - setup-all - setup-bot-honoroit diff --git a/roles/matrix-bot-honoroit/tasks/setup_install.yml b/roles/matrix-bot-honoroit/tasks/setup_install.yml index 584df9b7..9bb979fc 100644 --- a/roles/matrix-bot-honoroit/tasks/setup_install.yml +++ b/roles/matrix-bot-honoroit/tasks/setup_install.yml @@ -1,32 +1,34 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_honoroit_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_bot_honoroit_sqlite_database_path_local }}" register: matrix_bot_honoroit_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_bot_honoroit_sqlite_database_path_local }}" dst: "{{ matrix_bot_honoroit_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_bot_honoroit_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-bot-honoroit.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_bot_honoroit_requires_restart: true - when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_bot_honoroit_database_engine == 'postgres'" - name: Ensure honoroit paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -37,10 +39,10 @@ - {path: "{{ matrix_bot_honoroit_data_path }}", when: true} - {path: "{{ matrix_bot_honoroit_data_store_path }}", when: true} - {path: "{{ matrix_bot_honoroit_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure honoroit environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/env.j2" dest: "{{ matrix_bot_honoroit_config_path }}/env" owner: "{{ matrix_user_username }}" @@ -53,21 +55,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_honoroit_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_bot_honoroit_docker_image_force_pull }}" - when: "not matrix_bot_honoroit_container_image_self_build|bool" + when: "not matrix_bot_honoroit_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure honoroit repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_honoroit_docker_repo }}" + version: "{{ matrix_bot_honoroit_docker_repo_version }}" dest: "{{ matrix_bot_honoroit_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_honoroit_git_pull_results - when: "matrix_bot_honoroit_container_image_self_build|bool" + when: "matrix_bot_honoroit_container_image_self_build | bool" - name: Ensure honoroit image is built docker_image: @@ -79,22 +82,22 @@ dockerfile: Dockerfile path: "{{ matrix_bot_honoroit_docker_src_files_path }}" pull: true - when: "matrix_bot_honoroit_container_image_self_build|bool" + when: "matrix_bot_honoroit_container_image_self_build | bool" - name: Ensure matrix-bot-honoroit.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service" mode: 0644 register: matrix_bot_honoroit_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-honoroit.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_honoroit_systemd_service_result.changed|bool" + when: "matrix_bot_honoroit_systemd_service_result.changed | bool" - name: Ensure matrix-bot-honoroit.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-honoroit.service" state: restarted - when: "matrix_bot_honoroit_requires_restart|bool" + when: "matrix_bot_honoroit_requires_restart | bool" diff --git a/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml b/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml index 45bccabd..6ede0d1d 100644 --- a/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-honoroit service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service" register: matrix_bot_honoroit_service_stat - name: Ensure matrix-honoroit is stopped - service: + ansible.builtin.service: name: matrix-bot-honoroit state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_honoroit_service_stat.stat.exists|bool" + when: "matrix_bot_honoroit_service_stat.stat.exists | bool" - name: Ensure matrix-bot-honoroit.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service" state: absent - when: "matrix_bot_honoroit_service_stat.stat.exists|bool" + when: "matrix_bot_honoroit_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-honoroit.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_honoroit_service_stat.stat.exists|bool" + when: "matrix_bot_honoroit_service_stat.stat.exists | bool" - name: Ensure Matrix honoroit paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_honoroit_base_path }}" state: absent diff --git a/roles/matrix-bot-honoroit/tasks/validate_config.yml b/roles/matrix-bot-honoroit/tasks/validate_config.yml index 562bf9fb..0057e3c2 100644 --- a/roles/matrix-bot-honoroit/tasks/validate_config.yml +++ b/roles/matrix-bot-honoroit/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bot-honoroit/templates/env.j2 b/roles/matrix-bot-honoroit/templates/env.j2 index 7f1eef5b..c8d10c6a 100644 --- a/roles/matrix-bot-honoroit/templates/env.j2 +++ b/roles/matrix-bot-honoroit/templates/env.j2 @@ -8,8 +8,12 @@ HONOROIT_PREFIX={{ matrix_bot_honoroit_prefix }} HONOROIT_SENTRY={{ matrix_bot_honoroit_sentry }} HONOROIT_LOGLEVEL={{ matrix_bot_honoroit_loglevel }} HONOROIT_CACHESIZE={{ matrix_bot_honoroit_cachesize }} +HONOROIT_NOENCRYPTION={{ matrix_bot_honoroit_noencryption }} +HONOROIT_IGNORENOTHREAD={{ matrix_bot_honoroit_ignorenothread }} +HONOROIT_IGNOREDROOMS={{ matrix_bot_honoroit_ignoredrooms|join(' ') }} HONOROIT_TEXT_PREFIX_OPEN={{ matrix_bot_honoroit_text_prefix_open }} HONOROIT_TEXT_PREFIX_DONE={{ matrix_bot_honoroit_text_prefix_done }} +HONOROIT_TEXT_NOENCRYPTION={{ matrix_bot_honoroit_text_noencryption }} HONOROIT_TEXT_GREETINGS={{ matrix_bot_honoroit_text_greetings }} HONOROIT_TEXT_INVITE={{ matrix_bot_honoroit_text_invite }} HONOROIT_TEXT_JOIN={{ matrix_bot_honoroit_text_join }} diff --git a/roles/matrix-bot-matrix-registration-bot/defaults/main.yml b/roles/matrix-bot-matrix-registration-bot/defaults/main.yml new file mode 100644 index 00000000..d8e52b71 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/defaults/main.yml @@ -0,0 +1,50 @@ +--- +# matrix-registration-bot creates and manages registration tokens for a matrix server +# Project source code URL: https://github.com/moan0s/matrix-registration-bot + +matrix_bot_matrix_registration_bot_enabled: true +matrix_bot_matrix_registration_bot_container_image_self_build: false +matrix_bot_matrix_registration_bot_docker_repo: "https://github.com/moan0s/matrix-registration-bot.git" +matrix_bot_matrix_registration_bot_docker_repo_version: "{{ matrix_bot_matrix_registration_bot_version if matrix_bot_matrix_registration_bot_version != 'latest' else 'main' }}" +matrix_bot_matrix_registration_bot_docker_src_files_path: "{{ matrix_bot_matrix_registration_bot_base_path }}/docker-src" + +matrix_bot_matrix_registration_bot_version: latest +matrix_bot_matrix_registration_bot_docker_image: "{{ matrix_container_global_registry_prefix }}moanos/matrix-registration-bot:{{ matrix_bot_matrix_registration_bot_version }}" +matrix_bot_matrix_registration_bot_docker_image_force_pull: "{{ matrix_bot_matrix_registration_bot_docker_image.endswith(':latest') }}" + +matrix_bot_matrix_registration_bot_base_path: "{{ matrix_base_data_path }}/matrix-registration-bot" +matrix_bot_matrix_registration_bot_config_path: "{{ matrix_bot_matrix_registration_bot_base_path }}/config" +matrix_bot_matrix_registration_bot_data_path: "{{ matrix_bot_matrix_registration_bot_base_path }}/data" + +matrix_bot_matrix_registration_bot_bot_server: "https://{{ matrix_server_fqn_matrix }}" +matrix_bot_matrix_registration_bot_api_base_url: "https://{{ matrix_server_fqn_matrix }}" + +# The access token that the bot uses to communicate in Matrix chats +# This does not necessarily need to be a privileged (admin) access token. +matrix_bot_matrix_registration_bot_bot_access_token: '' + +# The access token that the bot uses to call the Matrix API for creating registration tokens. +# This needs to be a privileged (admin) access token. +# By default, we assume `matrix_bot_matrix_registration_bot_bot_access_token` is such a privileged token and we use it as is. +# If necessary, you can define your own other access token here, which might even be for a different Matrix user. +matrix_bot_matrix_registration_bot_api_token: "{{ matrix_bot_matrix_registration_bot_bot_access_token }}" + +matrix_bot_matrix_registration_bot_logging_level: info +matrix_bot_matrix_registration_environment_variables_extension: '' + +# A list of extra arguments to pass to the container +matrix_bot_matrix_registration_bot_container_extra_arguments: [] + +# List of systemd services that matrix-bot-matrix-registration-bot.service depends on +matrix_bot_matrix_registration_bot_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-bot-matrix-registration-bot.service wants +matrix_bot_matrix_registration_bot_systemd_wanted_services_list: [] + +# The bot's username. This user needs to be created manually beforehand. +# Also see `matrix_bot_matrix_registration_bot_user_password`. +matrix_bot_matrix_registration_bot_matrix_user_id_localpart: "bot.matrix-registration-bot" + +matrix_bot_matrix_registration_bot_matrix_user_id: '@{{ matrix_bot_matrix_registration_bot_matrix_user_id_localpart }}:{{ matrix_domain }}' + +matrix_bot_matrix_registration_bot_matrix_homeserver_url: "{{ matrix_homeserver_container_url }}" diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/init.yml b/roles/matrix-bot-matrix-registration-bot/tasks/init.yml new file mode 100644 index 00000000..91b1f095 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/tasks/init.yml @@ -0,0 +1,5 @@ +--- + +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-matrix-registration-bot.service'] }}" + when: matrix_bot_matrix_registration_bot_enabled | bool diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/main.yml b/roles/matrix-bot-matrix-registration-bot/tasks/main.yml new file mode 100644 index 00000000..cc162e99 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/tasks/main.yml @@ -0,0 +1,23 @@ +--- + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_matrix_registration_bot_enabled | bool" + tags: + - setup-all + - setup-bot-matrix-registration-bot + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_matrix_registration_bot_enabled | bool" + tags: + - setup-all + - setup-bot-matrix-registration-bot + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_matrix_registration_bot_enabled | bool" + tags: + - setup-all + - setup-bot-matrix-registration-bot diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml b/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml new file mode 100644 index 00000000..d4522321 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml @@ -0,0 +1,74 @@ +--- + +- name: Ensure matrix-registration-bot paths exist + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_bot_matrix_registration_bot_config_path }}", when: true} + - - {path: "{{ matrix_bot_matrix_registration_bot_data_path }}", when: true} + - {path: "{{ matrix_bot_matrix_registration_bot_docker_src_files_path }}", when: true} + when: "item.when | bool" + +- name: Ensure matrix-registration-bot configuration file created + ansible.builtin.template: + src: "{{ role_path }}/templates/config/config.yml.j2" + dest: "{{ matrix_bot_matrix_registration_bot_config_path }}/config.yml" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: 0640 + +- name: Ensure matrix-registration-bot image is pulled + docker_image: + name: "{{ matrix_bot_matrix_registration_bot_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_bot_matrix_registration_bot_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_bot_matrix_registration_bot_docker_image_force_pull }}" + when: "not matrix_bot_matrix_registration_bot_container_image_self_build | bool" + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure matrix-registration-bot repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_bot_matrix_registration_bot_docker_repo }}" + version: "{{ matrix_bot_matrix_registration_bot_docker_repo_version }}" + dest: "{{ matrix_bot_matrix_registration_bot_docker_src_files_path }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_bot_matrix_registration_bot_git_pull_results + when: "matrix_bot_matrix_registration_bot_container_image_self_build | bool" + +- name: Ensure matrix-registration-bot image is built + docker_image: + name: "{{ matrix_bot_matrix_registration_bot_docker_image }}" + source: build + force_source: "{{ matrix_bot_matrix_registration_bot_git_pull_results.changed 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_mailer_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_bot_matrix_registration_bot_docker_src_files_path }}" + pull: true + when: "matrix_bot_matrix_registration_bot_container_image_self_build | bool" + +- name: Ensure matrix-bot-matrix-registration-bot.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-bot-matrix-registration-bot.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-bot-matrix-registration-bot.service" + mode: 0644 + register: matrix_bot_matrix_registration_bot_systemd_service_result + +- name: Ensure systemd reloaded after matrix-bot-matrix-registration-bot.service installation + ansible.builtin.service: + daemon_reload: true + when: "matrix_bot_matrix_registration_bot_systemd_service_result.changed | bool" + +- name: Ensure matrix-bot-matrix-registration-bot.service restarted, if necessary + ansible.builtin.service: + name: "matrix-bot-matrix-registration-bot.service" + state: restarted diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml b/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml new file mode 100644 index 00000000..426eefc1 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml @@ -0,0 +1,36 @@ +--- + +- name: Check existence of matrix-matrix-registration-bot service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-bot-matrix-registration-bot.service" + register: matrix_bot_matrix_registration_bot_service_stat + +- name: Ensure matrix-matrix-registration-bot is stopped + ansible.builtin.service: + name: matrix-bot-matrix-registration-bot + state: stopped + enabled: false + daemon_reload: true + register: stopping_result + when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists | bool" + +- name: Ensure matrix-bot-matrix-registration-bot.service doesn't exist + ansible.builtin.file: + path: "{{ matrix_systemd_path }}/matrix-bot-matrix-registration-bot.service" + state: absent + when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists | bool" + +- name: Ensure systemd reloaded after matrix-bot-matrix-registration-bot.service removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists | bool" + +- name: Ensure Matrix matrix-registration-bot paths don't exist + ansible.builtin.file: + path: "{{ matrix_bot_matrix_registration_bot_base_path }}" + state: absent + +- name: Ensure matrix-registration-bot Docker image doesn't exist + docker_image: + name: "{{ matrix_bot_matrix_registration_bot_docker_image }}" + state: absent diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml b/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml new file mode 100644 index 00000000..39e97cde --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml @@ -0,0 +1,10 @@ +--- + +- name: Fail if required settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - "matrix_bot_matrix_registration_bot_bot_access_token" + - "matrix_bot_matrix_registration_bot_api_token" diff --git a/roles/matrix-bot-matrix-registration-bot/templates/config/config.yml.j2 b/roles/matrix-bot-matrix-registration-bot/templates/config/config.yml.j2 new file mode 100644 index 00000000..756efb01 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/templates/config/config.yml.j2 @@ -0,0 +1,12 @@ +bot: + server: {{ matrix_bot_matrix_registration_bot_bot_server|to_json }} + username: {{ matrix_bot_matrix_registration_bot_matrix_user_id_localpart|to_json }} + access_token: {{ matrix_bot_matrix_registration_bot_bot_access_token|to_json }} +api: + # API endpoint of the registration tokens + base_url: {{ matrix_bot_matrix_registration_bot_api_base_url|to_json }} + # Access token of an administrator on the server + token: {{ matrix_bot_matrix_registration_bot_api_token|to_json }} +logging: + level: {{ matrix_bot_matrix_registration_bot_logging_level|to_json }} + diff --git a/roles/matrix-bot-matrix-registration-bot/templates/systemd/matrix-bot-matrix-registration-bot.service.j2 b/roles/matrix-bot-matrix-registration-bot/templates/systemd/matrix-bot-matrix-registration-bot.service.j2 new file mode 100644 index 00000000..e1aa8954 --- /dev/null +++ b/roles/matrix-bot-matrix-registration-bot/templates/systemd/matrix-bot-matrix-registration-bot.service.j2 @@ -0,0 +1,37 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Matrix registration bot +{% for service in matrix_bot_matrix_registration_bot_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_bot_matrix_registration_bot_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-bot-matrix-registration-bot 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-bot-matrix-registration-bot 2>/dev/null || true' + +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-bot-matrix-registration-bot \ + --log-driver=none \ + --cap-drop=ALL \ + -e "CONFIG_PATH=/config/config.yml" \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --read-only \ + --mount type=bind,src={{ matrix_bot_matrix_registration_bot_config_path }},dst=/config,ro \ + --mount type=bind,src={{ matrix_bot_matrix_registration_bot_data_path }},dst=/data \ + --network={{ matrix_docker_network }} \ + {{ matrix_bot_matrix_registration_bot_docker_image }} + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-bot-matrix-registration-bot 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-bot-matrix-registration-bot 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-bot-matrix-registration-bot + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml b/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml index 76b153e7..610a43a3 100644 --- a/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml +++ b/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml @@ -1,11 +1,12 @@ --- # matrix-reminder-bot is a bot for one-off and recurring reminders -# See: https://github.com/anoadragon453/matrix-reminder-bot +# Project source code URL: https://github.com/anoadragon453/matrix-reminder-bot matrix_bot_matrix_reminder_bot_enabled: true matrix_bot_matrix_reminder_bot_container_image_self_build: false matrix_bot_matrix_reminder_bot_docker_repo: "https://github.com/anoadragon453/matrix-reminder-bot.git" +matrix_bot_matrix_reminder_bot_docker_repo_version: "{{ matrix_bot_matrix_reminder_bot_version }}" matrix_bot_matrix_reminder_bot_docker_src_files_path: "{{ matrix_base_data_path }}/matrix-reminder-bot/docker-src" matrix_bot_matrix_reminder_bot_version: release-v0.2.1 @@ -17,6 +18,8 @@ matrix_bot_matrix_reminder_bot_config_path: "{{ matrix_bot_matrix_reminder_bot_b matrix_bot_matrix_reminder_bot_data_path: "{{ matrix_bot_matrix_reminder_bot_base_path }}/data" matrix_bot_matrix_reminder_bot_data_store_path: "{{ matrix_bot_matrix_reminder_bot_data_path }}/store" +matrix_bot_matrix_reminder_bot_command_prefix: "!" + # A list of extra arguments to pass to the container matrix_bot_matrix_reminder_bot_container_extra_arguments: [] @@ -91,8 +94,8 @@ matrix_bot_matrix_reminder_bot_configuration_extension_yaml: | # matrix: # device_name: My-Reminder-Bot -matrix_bot_matrix_reminder_bot_configuration_extension: "{{ matrix_bot_matrix_reminder_bot_configuration_extension_yaml|from_yaml if matrix_bot_matrix_reminder_bot_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_bot_matrix_reminder_bot_configuration_extension: "{{ matrix_bot_matrix_reminder_bot_configuration_extension_yaml | from_yaml if matrix_bot_matrix_reminder_bot_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_bot_matrix_reminder_bot_configuration_yaml`. -matrix_bot_matrix_reminder_bot_configuration: "{{ matrix_bot_matrix_reminder_bot_configuration_yaml|from_yaml|combine(matrix_bot_matrix_reminder_bot_configuration_extension, recursive=True) }}" +matrix_bot_matrix_reminder_bot_configuration: "{{ matrix_bot_matrix_reminder_bot_configuration_yaml | from_yaml | combine(matrix_bot_matrix_reminder_bot_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml index 41496955..0a5ba482 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-matrix-reminder-bot.service'] }}" - when: matrix_bot_matrix_reminder_bot_enabled|bool + when: matrix_bot_matrix_reminder_bot_enabled | bool diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml index d9a1df7e..19c3823f 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_matrix_reminder_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_matrix_reminder_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-reminder-bot -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_matrix_reminder_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_matrix_reminder_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-reminder-bot -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_matrix_reminder_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_matrix_reminder_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-reminder-bot diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml index d7f4706f..0ad895af 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml @@ -1,33 +1,35 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_matrix_reminder_bot_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}" register: matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}" dst: "{{ matrix_bot_matrix_reminder_bot_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_bot_matrix_reminder_bot_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-bot-matrix-reminder-bot.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_bot_matrix_reminder_bot_requires_restart: true - when: "matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_bot_matrix_reminder_bot_database_engine == 'postgres'" - name: Ensure matrix-reminder-bot paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -38,7 +40,7 @@ - {path: "{{ matrix_bot_matrix_reminder_bot_data_path }}", when: true} - {path: "{{ matrix_bot_matrix_reminder_bot_data_store_path }}", when: true} - {path: "{{ matrix_bot_matrix_reminder_bot_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure matrix-reminder-bot image is pulled docker_image: @@ -46,21 +48,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_matrix_reminder_bot_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_bot_matrix_reminder_bot_docker_image_force_pull }}" - when: "not matrix_bot_matrix_reminder_bot_container_image_self_build|bool" + when: "not matrix_bot_matrix_reminder_bot_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-reminder-bot repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_matrix_reminder_bot_docker_repo }}" + version: "{{ matrix_bot_matrix_reminder_bot_docker_repo_version }}" dest: "{{ matrix_bot_matrix_reminder_bot_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_matrix_reminder_bot_git_pull_results - when: "matrix_bot_matrix_reminder_bot_container_image_self_build|bool" + when: "matrix_bot_matrix_reminder_bot_container_image_self_build | bool" - name: Ensure matrix-reminder-bot image is built docker_image: @@ -72,30 +75,30 @@ dockerfile: docker/Dockerfile path: "{{ matrix_bot_matrix_reminder_bot_docker_src_files_path }}" pull: true - when: "matrix_bot_matrix_reminder_bot_container_image_self_build|bool" + when: "matrix_bot_matrix_reminder_bot_container_image_self_build | bool" - name: Ensure matrix-reminder-bot config installed - copy: - content: "{{ matrix_bot_matrix_reminder_bot_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_bot_matrix_reminder_bot_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_bot_matrix_reminder_bot_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-bot-matrix-reminder-bot.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-matrix-reminder-bot.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-matrix-reminder-bot.service" mode: 0644 register: matrix_bot_matrix_reminder_bot_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-matrix-reminder-bot.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_matrix_reminder_bot_systemd_service_result.changed|bool" + when: "matrix_bot_matrix_reminder_bot_systemd_service_result.changed | bool" - name: Ensure matrix-bot-matrix-reminder-bot.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-matrix-reminder-bot.service" state: restarted - when: "matrix_bot_matrix_reminder_bot_requires_restart|bool" + when: "matrix_bot_matrix_reminder_bot_requires_restart | bool" diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml index eb7543c5..d8926df7 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-matrix-reminder-bot service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-matrix-reminder-bot.service" register: matrix_bot_matrix_reminder_bot_service_stat - name: Ensure matrix-matrix-reminder-bot is stopped - service: + ansible.builtin.service: name: matrix-bot-matrix-reminder-bot state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists | bool" - name: Ensure matrix-bot-matrix-reminder-bot.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-matrix-reminder-bot.service" state: absent - when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-matrix-reminder-bot.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists | bool" - name: Ensure Matrix matrix-reminder-bot paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_matrix_reminder_bot_base_path }}" state: absent diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml index 8963a312..54f38dd5 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -10,7 +10,7 @@ - "matrix_bot_matrix_reminder_bot_reminders_timezone" - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). diff --git a/roles/matrix-bot-matrix-reminder-bot/templates/config.yaml.j2 b/roles/matrix-bot-matrix-reminder-bot/templates/config.yaml.j2 index 59643958..338bffba 100644 --- a/roles/matrix-bot-matrix-reminder-bot/templates/config.yaml.j2 +++ b/roles/matrix-bot-matrix-reminder-bot/templates/config.yaml.j2 @@ -1,5 +1,5 @@ # The string to prefix bot commands with -command_prefix: "!" +command_prefix: "{{ matrix_bot_matrix_reminder_bot_command_prefix }}" # Options for connecting to the bot's Matrix account matrix: diff --git a/roles/matrix-bot-maubot/defaults/main.yml b/roles/matrix-bot-maubot/defaults/main.yml new file mode 100644 index 00000000..0a73d92e --- /dev/null +++ b/roles/matrix-bot-maubot/defaults/main.yml @@ -0,0 +1,69 @@ +--- + +# maubot is a plugin-based Matrix bot system. +# Project source code URL: https://mau.dev/maubot/maubot + +matrix_bot_maubot_enabled: true +matrix_bot_maubot_container_image_self_build: false +matrix_bot_maubot_docker_repo: "https://mau.dev/maubot/maubot.git" +matrix_bot_maubot_docker_src_files_path: "{{ matrix_bot_maubot_base_path }}/docker-src" +matrix_bot_maubot_docker_repo_version: "{{ 'master' if matrix_bot_maubot_version == 'latest' else matrix_bot_maubot_version }}" + + +matrix_bot_maubot_version: v0.3.1 +matrix_bot_maubot_docker_image: "dock.mau.dev/maubot/maubot:{{ matrix_bot_maubot_version }}" +matrix_bot_maubot_docker_image_force_pull: "{{ matrix_bot_maubot_docker_image.endswith(':latest') }}" + +matrix_bot_maubot_base_path: "{{ matrix_base_data_path }}/maubot" +matrix_bot_maubot_data_path: "{{ matrix_bot_maubot_base_path }}/data" +matrix_bot_maubot_config_path: "{{ matrix_bot_maubot_base_path }}/config" + +matrix_bot_maubot_bot_server_public_url: "https://{{ matrix_server_fqn_matrix }}" +matrix_bot_maubot_proxy_management_interface: true + +matrix_bot_maubot_database_engine: sqlite +matrix_bot_maubot_sqlite_database_path_local: "{{ matrix_bot_maubot_data_path }}/maubot.db" +matrix_bot_maubot_sqlite_database_path_in_container: "/data/maubot.db" + +matrix_bot_maubot_database_username: matrix_bot_maubot +matrix_bot_maubot_database_password: ~ +matrix_bot_maubot_database_hostname: 'matrix-postgres' +matrix_bot_maubot_database_port: 5432 +matrix_bot_maubot_database_name: matrix_bot_maubot + +matrix_bot_maubot_database_connection_string: postgres://{{ matrix_bot_maubot_database_username }}:{{ matrix_bot_maubot_database_password }}@{{ matrix_bot_maubot_database_hostname }}:{{ matrix_bot_maubot_database_port }}/{{ matrix_bot_maubot_database_name }}?sslmode=disable + +matrix_bot_maubot_database_uri: "{{ + { + 'sqlite': ('sqlite:///' + matrix_bot_maubot_sqlite_database_path_in_container), + 'postgres': matrix_bot_maubot_database_connection_string, + }[matrix_bot_maubot_database_engine] + }}" + + +# Defines the port number where the management interface is +# To actually expose the management interface outside of the container, use `matrix_bot_maubot_management_interface_http_bind_port` +matrix_bot_maubot_management_interface_port: 29316 + +# Controls whether the maubot container exposes its HTTP management interface port (tcp/29316 in the container). +# +# Takes an ":" or "" value (e.g. "127.0.0.1:29316"), or empty string to not expose. +# If you'll be setting this at all, it should be defined in terms of `matrix_bot_maubot_management_interface_port`. +# Example: +# matrix_bot_maubot_management_interface_http_bind_port: "127.0.0.1:{{ matrix_bot_maubot_management_interface_port }}" +matrix_bot_maubot_management_interface_http_bind_port: '' + + +matrix_bot_maubot_unshared_secret: 'generate' + +# Specifies the default log level for all bot loggers. +matrix_bot_maubot_logging_level: WARNING + +# A list of extra arguments to pass to the container +matrix_bot_maubot_container_extra_arguments: [] + +# List of systemd services that matrix-bot-maubot.service depends on +matrix_bot_maubot_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-bot-maubot.service wants +matrix_bot_maubot_systemd_wanted_services_list: [] diff --git a/roles/matrix-bot-maubot/tasks/init.yml b/roles/matrix-bot-maubot/tasks/init.yml new file mode 100644 index 00000000..251d0b4a --- /dev/null +++ b/roles/matrix-bot-maubot/tasks/init.yml @@ -0,0 +1,47 @@ +--- + +- name: Add maubot to the systemd service list + ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-maubot.service'] }}" + when: matrix_bot_maubot_enabled | bool + +- name: Configure nginx for maubot + block: + - name: Generate Maubot proxying configuration for matrix-nginx-proxy + ansible.builtin.set_fact: + matrix_bot_maubot_matrix_nginx_proxy_configuration: | + location ~ ^/(_matrix/maubot/.*) { + {% 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-bot-maubot:{{ matrix_bot_maubot_management_interface_port }}/$1"; + proxy_pass http://$backend; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + {% else %} + {# Generic configuration for use outside of our container setup #} + proxy_pass http://127.0.0.1:{{ matrix_bot_maubot_management_interface_port }}/$1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + {% endif %} + } + when: matrix_bot_maubot_proxy_management_interface | bool + + - name: Register Maubot's 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_bot_maubot_matrix_nginx_proxy_configuration] + }} + when: matrix_bot_maubot_proxy_management_interface|bool + + - name: Warn about reverse-proxying if matrix-nginx-proxy not used + ansible.builtin.debug: + msg: >- + NOTE: You've enabled Maubot but are not using the matrix-nginx-proxy + reverse proxy. + Please make sure that you're proxying the `/_matrix/maubot` + URL endpoint to the matrix-maubot container. + when: "matrix_bot_maubot_enabled | bool and matrix_bot_maubot_proxy_management_interface | bool and matrix_nginx_proxy_enabled is not defined" diff --git a/roles/matrix-bridge-mx-puppet-skype/tasks/main.yml b/roles/matrix-bot-maubot/tasks/main.yml similarity index 53% rename from roles/matrix-bridge-mx-puppet-skype/tasks/main.yml rename to roles/matrix-bot-maubot/tasks/main.yml index 0793e994..c67e25ee 100644 --- a/roles/matrix-bridge-mx-puppet-skype/tasks/main.yml +++ b/roles/matrix-bot-maubot/tasks/main.yml @@ -5,19 +5,19 @@ - always - import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_skype_enabled|bool" + when: "run_setup|bool and matrix_bot_maubot_enabled|bool" tags: - setup-all - - setup-mx-puppet-skype + - setup-bot-maubot - import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_skype_enabled|bool" + when: "run_setup|bool and matrix_bot_maubot_enabled|bool" tags: - setup-all - - setup-mx-puppet-skype + - setup-bot-maubot - import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_skype_enabled|bool" + when: "run_setup|bool and not matrix_bot_maubot_enabled|bool" tags: - setup-all - - setup-mx-puppet-skype + - setup-bot-maubot diff --git a/roles/matrix-bot-maubot/tasks/setup_install.yml b/roles/matrix-bot-maubot/tasks/setup_install.yml new file mode 100644 index 00000000..185a2988 --- /dev/null +++ b/roles/matrix-bot-maubot/tasks/setup_install.yml @@ -0,0 +1,73 @@ +--- + +- name: Ensure maubot paths exist + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0755 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_bot_maubot_base_path }}", when: true} + - {path: "{{ matrix_bot_maubot_config_path }}", when: true} + - {path: "{{ matrix_bot_maubot_data_path }}", when: true} + - {path: "{{ matrix_bot_maubot_data_path }}/plugins", when: true} + - {path: "{{ matrix_bot_maubot_data_path }}/dbs", when: true} + - {path: "{{ matrix_bot_maubot_data_path }}/trash", when: true} + - {path: "{{ matrix_bot_maubot_docker_src_files_path }}", when: "{{ matrix_bot_maubot_container_image_self_build }}"} + when: "item.when|bool" + +- name: Ensure maubot configuration file created + ansible.builtin.template: + src: "{{ role_path }}/templates/config/config.yaml.j2" + dest: "{{ matrix_bot_maubot_config_path }}/config.yaml" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: "u=rwx" + +- name: Ensure maubot image is pulled + docker_image: + name: "{{ matrix_bot_maubot_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_bot_maubot_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_bot_maubot_docker_image_force_pull }}" + when: "not matrix_bot_maubot_container_image_self_build|bool" + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure maubot repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_bot_maubot_docker_repo }}" + version: "{{ matrix_bot_maubot_docker_repo_version }}" + dest: "{{ matrix_bot_maubot_docker_src_files_path }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_bot_maubot_git_pull_results + when: "matrix_bot_maubot_container_image_self_build|bool" + +- name: Ensure maubot image is built + docker_image: + name: "{{ matrix_bot_maubot_docker_image }}" + source: build + force_source: "{{ matrix_bot_maubot_git_pull_results.changed 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_mailer_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_bot_maubot_docker_src_files_path }}" + pull: true + when: "matrix_bot_maubot_container_image_self_build|bool" + +- name: Ensure matrix-bot-maubot.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-bot-maubot.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-bot-maubot.service" + mode: 0644 + register: matrix_bot_maubot_systemd_service_result + +- name: Ensure systemd reloaded after matrix-bot-maubot.service installation + ansible.builtin.service: + daemon_reload: true + when: "matrix_bot_maubot_systemd_service_result.changed|bool" diff --git a/roles/matrix-bot-maubot/tasks/setup_uninstall.yml b/roles/matrix-bot-maubot/tasks/setup_uninstall.yml new file mode 100644 index 00000000..0be7089c --- /dev/null +++ b/roles/matrix-bot-maubot/tasks/setup_uninstall.yml @@ -0,0 +1,36 @@ +--- + +- name: Check existence of matrix-maubot service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-bot-maubot.service" + register: matrix_bot_maubot_service_stat + +- name: Ensure matrix-bot-maubot is stopped + ansible.builtin.service: + name: matrix-bot-maubot + state: stopped + enabled: false + daemon_reload: true + register: stopping_result + when: "matrix_bot_maubot_service_stat.stat.exists|bool" + +- name: Ensure matrix-bot-maubot.service doesn't exist + ansible.builtin.file: + path: "{{ matrix_systemd_path }}/matrix-bot-maubot.service" + state: absent + when: "matrix_bot_maubot_service_stat.stat.exists|bool" + +- name: Ensure systemd reloaded after matrix-bot-maubot.service removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_bot_maubot_service_stat.stat.exists|bool" + +- name: Ensure Matrix maubot paths don't exist + ansible.builtin.file: + path: "{{ matrix_bot_maubot_base_path }}" + state: absent + +- name: Ensure maubot Docker image doesn't exist + docker_image: + name: "{{ matrix_bot_maubot_docker_image }}" + state: absent diff --git a/roles/matrix-bot-maubot/tasks/validate_config.yml b/roles/matrix-bot-maubot/tasks/validate_config.yml new file mode 100644 index 00000000..5b28d9c0 --- /dev/null +++ b/roles/matrix-bot-maubot/tasks/validate_config.yml @@ -0,0 +1,10 @@ +--- + +- name: Fail if required settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - matrix_bot_maubot_unshared_secret + - matrix_bot_maubot_admins diff --git a/roles/matrix-bot-maubot/templates/config/config.yaml.j2 b/roles/matrix-bot-maubot/templates/config/config.yaml.j2 new file mode 100644 index 00000000..49bbcb87 --- /dev/null +++ b/roles/matrix-bot-maubot/templates/config/config.yaml.j2 @@ -0,0 +1,110 @@ +# The full URI to the database. SQLite and Postgres are fully supported. +# Other DBMSes supported by SQLAlchemy may or may not work. +# Format examples: +# SQLite: sqlite:///filename.db +# Postgres: postgresql://username:password@hostname/dbname +database: {{ matrix_bot_maubot_database_uri|to_json }} + +# Separate database URL for the crypto database. "default" means use the same database as above. +crypto_database: + type: default + +# Additional arguments for asyncpg.create_pool() or sqlite3.connect() +# https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool +# https://docs.python.org/3/library/sqlite3.html#sqlite3.connect +# For sqlite, min_size is used as the connection thread pool size and max_size is ignored. +database_opts: + min_size: 1 + max_size: 10 +plugin_directories: + # The directory where uploaded new plugins should be stored. + upload: /data/plugins + # The directories from which plugins should be loaded. + # Duplicate plugin IDs will be moved to the trash. + load: + - /data/plugins + trash: /data/trash + +# Configuration for storing plugin databases +plugin_databases: + # Some plugins still require sqlite, so configure a path here. + # postgres will be used if supported. + sqlite: /data/dbs + postgres: default + +server: + # The IP and port to listen to. + hostname: 0.0.0.0 + port: {{ matrix_bot_maubot_management_interface_port|to_json }} + # Public base URL where the server is visible. + public_url: {{ matrix_bot_maubot_bot_server_public_url|to_json }} + # The base management API path. + base_path: /_matrix/maubot/v1 + # The base path for the UI. + ui_base_path: /_matrix/maubot + # The base path for plugin endpoints. The instance ID will be appended directly. + plugin_base_path: /_matrix/maubot/plugin/ + # Override path from where to load UI resources. + # Set to false to using pkg_resources to find the path. + override_resource_path: /opt/maubot/frontend + # The base appservice API path. Use / for legacy appservice API and /_matrix/app/v1 for v1. + appservice_base_path: /_matrix/app/v1 + # The shared secret to sign API access tokens. + # Set to "generate" to generate and save a new token at startup. + unshared_secret: {{ matrix_bot_maubot_unshared_secret|to_json }} + +# Known homeservers. This is required for the `mbc auth` command and also allows +# more convenient access from the management UI. This is not required to create +# clients in the management UI, since you can also just type the homeserver URL +# into the box there. +homeservers: + {{ matrix_domain }}: + # Client-server API URL + url: "https://{{ matrix_server_fqn_matrix }}" + # registration_shared_secret from synapse config + # You can leave this empty if you don't have access to the homeserver. + # When this is empty, `mbc auth --register` won't work, but `mbc auth` (login) will. + secret: {{ matrix_bot_maubot_registration_shared_secret|to_json }} + +# List of administrator users. Plaintext passwords will be bcrypted on startup. Set empty password +# to prevent normal login. Root is a special user that can't have a password and will always exist. +admins: {{ matrix_bot_maubot_admins | combine( {"root": ""} )|to_json }} + +api_features: + login: true + plugin: true + plugin_upload: true + instance: true + instance_database: true + client: true + client_proxy: true + client_auth: true + dev_open: true + log: true + +# Python logging configuration. +# +# See section 16.7.2 of the Python documentation for more info: +# https://docs.python.org/3.6/library/logging.config.html#configuration-dictionary-schema +logging: + version: 1 + formatters: + colored: + (): maubot.lib.color_log.ColorFormatter + format: '[%(asctime)s] [%(levelname)s@%(name)s] %(message)s' + normal: + format: '[%(asctime)s] [%(levelname)s@%(name)s] %(message)s' + handlers: + console: + class: logging.StreamHandler + formatter: colored + loggers: + maubot: + level: {{ matrix_bot_maubot_logging_level|to_json }} + mau: + level: {{ matrix_bot_maubot_logging_level|to_json }} + aiohttp: + level: {{ matrix_bot_maubot_logging_level|to_json }} + root: + level: {{ matrix_bot_maubot_logging_level|to_json }} + handlers: [console] diff --git a/roles/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 b/roles/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 new file mode 100644 index 00000000..a9e03986 --- /dev/null +++ b/roles/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 @@ -0,0 +1,43 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Maubot +{% for service in matrix_bot_maubot_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_bot_maubot_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-bot-maubot 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-bot-maubot 2>/dev/null || true' + +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-bot-maubot \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --read-only \ + --cap-drop=ALL \ + --mount type=bind,src={{ matrix_bot_maubot_config_path }},dst=/config,ro \ + --mount type=bind,src={{ matrix_bot_maubot_data_path }},dst=/data \ + {% for arg in matrix_bot_maubot_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + --network={{ matrix_docker_network }} \ + {% if matrix_bot_maubot_management_interface_http_bind_port %} + -p {{ matrix_bot_maubot_management_interface_http_bind_port }}:{{ matrix_bot_maubot_management_interface_port }} \ + {% endif %} + {{ matrix_bot_maubot_docker_image }} \ + python3 -m maubot -c /config/config.yaml --no-update + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-bot-maubot 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-bot-maubot 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-bot-maubot + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-bot-mjolnir/defaults/main.yml b/roles/matrix-bot-mjolnir/defaults/main.yml index 0093576c..0be97eae 100644 --- a/roles/matrix-bot-mjolnir/defaults/main.yml +++ b/roles/matrix-bot-mjolnir/defaults/main.yml @@ -1,10 +1,10 @@ --- # A moderation tool for Matrix -# See: https://github.com/matrix-org/mjolnir +# Project source code URL: https://github.com/matrix-org/mjolnir matrix_bot_mjolnir_enabled: true -matrix_bot_mjolnir_version: "v1.4.1" +matrix_bot_mjolnir_version: "v1.5.0" matrix_bot_mjolnir_container_image_self_build: false matrix_bot_mjolnir_container_image_self_build_repo: "https://github.com/matrix-org/mjolnir.git" @@ -52,8 +52,8 @@ matrix_bot_mjolnir_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_bot_mjolnir_configuration_yaml`. -matrix_bot_mjolnir_configuration_extension: "{{ matrix_bot_mjolnir_configuration_extension_yaml|from_yaml if matrix_bot_mjolnir_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_bot_mjolnir_configuration_extension: "{{ matrix_bot_mjolnir_configuration_extension_yaml | from_yaml if matrix_bot_mjolnir_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_bot_mjolnir_configuration_yaml`. -matrix_bot_mjolnir_configuration: "{{ matrix_bot_mjolnir_configuration_yaml|from_yaml|combine(matrix_bot_mjolnir_configuration_extension, recursive=True) }}" +matrix_bot_mjolnir_configuration: "{{ matrix_bot_mjolnir_configuration_yaml | from_yaml | combine(matrix_bot_mjolnir_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-bot-mjolnir/tasks/init.yml b/roles/matrix-bot-mjolnir/tasks/init.yml index e09964ec..2b605342 100644 --- a/roles/matrix-bot-mjolnir/tasks/init.yml +++ b/roles/matrix-bot-mjolnir/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: + ansible.builtin.fail: msg: "To self-build the Mjolnir image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_bot_mjolnir_container_image_self_build and matrix_bot_mjolnir_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-mjolnir.service'] }}" - when: matrix_bot_mjolnir_enabled|bool + when: matrix_bot_mjolnir_enabled | bool diff --git a/roles/matrix-bot-mjolnir/tasks/main.yml b/roles/matrix-bot-mjolnir/tasks/main.yml index a2a20914..867201a2 100644 --- a/roles/matrix-bot-mjolnir/tasks/main.yml +++ b/roles/matrix-bot-mjolnir/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_mjolnir_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_mjolnir_enabled | bool" tags: - setup-all - setup-bot-mjolnir -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_mjolnir_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_mjolnir_enabled | bool" tags: - setup-all - setup-bot-mjolnir -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_mjolnir_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_mjolnir_enabled | bool" tags: - setup-all - setup-bot-mjolnir diff --git a/roles/matrix-bot-mjolnir/tasks/setup_install.yml b/roles/matrix-bot-mjolnir/tasks/setup_install.yml index 66f2806a..08ac9d03 100644 --- a/roles/matrix-bot-mjolnir/tasks/setup_install.yml +++ b/roles/matrix-bot-mjolnir/tasks/setup_install.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_mjolnir_requires_restart: false - name: Ensure matrix-bot-mjolnir paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -15,7 +15,7 @@ - {path: "{{ matrix_bot_mjolnir_config_path }}", when: true} - {path: "{{ matrix_bot_mjolnir_data_path }}", when: true} - {path: "{{ matrix_bot_mjolnir_docker_src_files_path }}", when: "{{ matrix_bot_mjolnir_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure mjolnir Docker image is pulled docker_image: @@ -23,14 +23,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_mjolnir_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_bot_mjolnir_docker_image_force_pull }}" - when: "not matrix_bot_mjolnir_container_image_self_build|bool" + when: "not matrix_bot_mjolnir_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure mjolnir repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_mjolnir_container_image_self_build_repo }}" dest: "{{ matrix_bot_mjolnir_docker_src_files_path }}" version: "{{ matrix_bot_mjolnir_docker_image.split(':')[1] }}" @@ -38,7 +38,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_mjolnir_git_pull_results - when: "matrix_bot_mjolnir_container_image_self_build|bool" + when: "matrix_bot_mjolnir_container_image_self_build | bool" - name: Ensure mjolnir Docker image is built docker_image: @@ -49,30 +49,30 @@ dockerfile: Dockerfile path: "{{ matrix_bot_mjolnir_docker_src_files_path }}" pull: true - when: "matrix_bot_mjolnir_container_image_self_build|bool" + when: "matrix_bot_mjolnir_container_image_self_build | bool" - name: Ensure matrix-bot-mjolnir config installed - copy: - content: "{{ matrix_bot_mjolnir_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_bot_mjolnir_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_bot_mjolnir_config_path }}/production.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-bot-mjolnir.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-mjolnir.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-mjolnir.service" mode: 0644 register: matrix_bot_mjolnir_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-mjolnir.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_mjolnir_systemd_service_result.changed|bool" + when: "matrix_bot_mjolnir_systemd_service_result.changed | bool" - name: Ensure matrix-bot-mjolnir.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-mjolnir.service" state: restarted - when: "matrix_bot_mjolnir_requires_restart|bool" + when: "matrix_bot_mjolnir_requires_restart | bool" diff --git a/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml b/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml index 93585977..5c7f4c89 100644 --- a/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-bot-mjolnir service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-mjolnir.service" register: matrix_bot_mjolnir_service_stat - name: Ensure matrix-bot-mjolnir is stopped - service: + ansible.builtin.service: name: matrix-bot-mjolnir state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_mjolnir_service_stat.stat.exists|bool" + when: "matrix_bot_mjolnir_service_stat.stat.exists | bool" - name: Ensure matrix-bot-mjolnir.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-mjolnir.service" state: absent - when: "matrix_bot_mjolnir_service_stat.stat.exists|bool" + when: "matrix_bot_mjolnir_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-mjolnir.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_mjolnir_service_stat.stat.exists|bool" + when: "matrix_bot_mjolnir_service_stat.stat.exists | bool" - name: Ensure matrix-bot-mjolnir paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_mjolnir_base_path }}" state: absent diff --git a/roles/matrix-bot-mjolnir/tasks/validate_config.yml b/roles/matrix-bot-mjolnir/tasks/validate_config.yml index cb961baf..63289d7b 100644 --- a/roles/matrix-bot-mjolnir/tasks/validate_config.yml +++ b/roles/matrix-bot-mjolnir/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required variables are undefined - fail: + ansible.builtin.fail: msg: "The `{{ item }}` variable must be defined and have a non-null value." with_items: - "matrix_bot_mjolnir_access_token" diff --git a/roles/matrix-bridge-appservice-discord/defaults/main.yml b/roles/matrix-bridge-appservice-discord/defaults/main.yml index b2ef2cdf..9f6109ed 100644 --- a/roles/matrix-bridge-appservice-discord/defaults/main.yml +++ b/roles/matrix-bridge-appservice-discord/defaults/main.yml @@ -1,6 +1,6 @@ --- # matrix-appservice-discord is a Matrix <-> Discord bridge -# See: https://github.com/Half-Shot/matrix-appservice-discord +# Project source code URL: https://github.com/Half-Shot/matrix-appservice-discord matrix_appservice_discord_enabled: true @@ -39,10 +39,10 @@ matrix_appservice_discord_appservice_url: 'http://matrix-appservice-discord:9005 matrix_appservice_discord_bridge_domain: "{{ matrix_domain }}" # As of right now, the homeserver URL must be a public URL. See below. -matrix_appservice_discord_bridge_homeserverUrl: "{{ matrix_homeserver_url }}" -matrix_appservice_discord_bridge_disablePresence: false -matrix_appservice_discord_bridge_enableSelfServiceBridging: false -matrix_appservice_discord_bridge_disablePortalBridging: false +matrix_appservice_discord_bridge_homeserverUrl: "{{ matrix_homeserver_url }}" # noqa var-naming +matrix_appservice_discord_bridge_disablePresence: false # noqa var-naming +matrix_appservice_discord_bridge_enableSelfServiceBridging: false # noqa var-naming +matrix_appservice_discord_bridge_disablePortalBridging: false # noqa var-naming # Database-related configuration fields. # @@ -65,7 +65,7 @@ matrix_appservice_discord_database_name: 'matrix_appservice_discord' # These 2 variables are what actually ends up in the bridge configuration. # It's best if you don't change them directly, but rather redefine the sub-variables that constitute them. matrix_appservice_discord_database_filename: "{{ matrix_appservice_discord_sqlite_database_path_in_container }}" -matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservice_discord_database_username }}:{{ matrix_appservice_discord_database_password }}@{{ matrix_appservice_discord_database_hostname }}:{{ matrix_appservice_discord_database_port }}/{{ matrix_appservice_discord_database_name }}' +matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservice_discord_database_username }}:{{ matrix_appservice_discord_database_password }}@{{ matrix_appservice_discord_database_hostname }}:{{ matrix_appservice_discord_database_port }}/{{ matrix_appservice_discord_database_name }}' # noqa var-naming # Tells whether the bot should make use of "Privileged Gateway Intents". @@ -74,7 +74,7 @@ matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservic # by triggering all Intent checkboxes on a page like this: `https://discord.com/developers/applications/694448564151123988/bot` # # Learn more: https://gist.github.com/advaith1/e69bcc1cdd6d0087322734451f15aa2f -matrix_appservice_discord_auth_usePrivilegedIntents: false +matrix_appservice_discord_auth_usePrivilegedIntents: false # noqa var-naming matrix_appservice_discord_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" @@ -87,9 +87,9 @@ matrix_appservice_discord_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_appservice_discord_configuration_yaml`. -matrix_appservice_discord_configuration_extension: "{{ matrix_appservice_discord_configuration_extension_yaml|from_yaml if matrix_appservice_discord_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_appservice_discord_configuration_extension: "{{ matrix_appservice_discord_configuration_extension_yaml | from_yaml if matrix_appservice_discord_configuration_extension_yaml | from_yaml is mapping else {} }}" -matrix_appservice_discord_configuration: "{{ matrix_appservice_discord_configuration_yaml|from_yaml|combine(matrix_appservice_discord_configuration_extension, recursive=True) }}" +matrix_appservice_discord_configuration: "{{ matrix_appservice_discord_configuration_yaml | from_yaml | combine(matrix_appservice_discord_configuration_extension, recursive=True) }}" matrix_appservice_discord_registration_yaml: | #jinja2: lstrip_blocks: "True" @@ -99,14 +99,14 @@ matrix_appservice_discord_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_discord_.*:{{ matrix_appservice_discord_homeserver_domain|regex_escape }}' + regex: '@_discord_.*:{{ matrix_appservice_discord_homeserver_domain | regex_escape }}' aliases: - exclusive: true - regex: '#_discord_.*:{{ matrix_appservice_discord_homeserver_domain|regex_escape }}' + regex: '#_discord_.*:{{ matrix_appservice_discord_homeserver_domain | regex_escape }}' url: {{ matrix_appservice_discord_appservice_url }} sender_localpart: _discord_bot rate_limited: false protocols: - discord -matrix_appservice_discord_registration: "{{ matrix_appservice_discord_registration_yaml|from_yaml }}" +matrix_appservice_discord_registration: "{{ matrix_appservice_discord_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-discord/tasks/init.yml b/roles/matrix-bridge-appservice-discord/tasks/init.yml index e16a6979..b9d875da 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/init.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/init.yml @@ -2,24 +2,28 @@ # 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-appservice-discord role needs to execute before the matrix-synapse role. - when: "matrix_appservice_discord_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_appservice_discord_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-discord.service'] }}" - when: matrix_appservice_discord_enabled|bool + when: matrix_appservice_discord_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([]) }} - + - ["--mount type=bind,src={{ matrix_appservice_discord_config_path }}/registration.yaml,dst=/matrix-appservice-discord-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_appservice_discord_config_path }}/registration.yaml,dst=/matrix-appservice-discord-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-appservice-discord-registration.yaml"] }} - when: matrix_appservice_discord_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-appservice-discord-registration.yaml"] + }} + when: matrix_appservice_discord_enabled | bool diff --git a/roles/matrix-bridge-appservice-discord/tasks/main.yml b/roles/matrix-bridge-appservice-discord/tasks/main.yml index 5df7bfe2..7ab8f3a6 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/main.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_discord_enabled | bool" tags: - setup-all - setup-appservice-discord -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_discord_enabled | bool" tags: - setup-all - setup-appservice-discord -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_discord_enabled | bool" tags: - setup-all - setup-appservice-discord diff --git a/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml b/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml index a06d38ac..af17613c 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml @@ -1,29 +1,31 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_appservice_discord_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_discord_sqlite_database_path_local }}" register: matrix_appservice_discord_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_appservice_discord_sqlite_database_path_local }}" dst: "{{ matrix_appservice_discord_database_connString }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_appservice_discord_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-appservice-discord.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_appservice_discord_requires_restart: true - when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_appservice_discord_database_engine == 'postgres'" - name: Ensure Appservice Discord image is pulled @@ -38,7 +40,7 @@ until: result is not failed - name: Ensure AppService Discord paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -50,12 +52,12 @@ - "{{ matrix_appservice_discord_data_path }}" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_discord_base_path }}/discord.db" register: matrix_appservice_discord_stat_db - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped - service: + ansible.builtin.service: name: matrix-appservice-discord state: stopped enabled: false @@ -64,7 +66,7 @@ when: "matrix_appservice_discord_stat_db.stat.exists" - name: (Data relocation) Move AppService Discord discord.db file to ./data directory - command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}" + ansible.builtin.command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}" with_items: - discord.db - user-store.db @@ -72,16 +74,16 @@ when: "matrix_appservice_discord_stat_db.stat.exists" - name: Ensure AppService Discord config.yaml installed - copy: - content: "{{ matrix_appservice_discord_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_discord_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_discord_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure AppService Discord registration.yaml installed - copy: - content: "{{ matrix_appservice_discord_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_discord_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" @@ -90,7 +92,7 @@ # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated. # We intentionally suppress Ansible changes. - name: Generate AppService Discord invite link - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen --user={{ matrix_user_uid }}:{{ matrix_user_gid }} --cap-drop=ALL @@ -101,19 +103,19 @@ changed_when: false - name: Ensure matrix-appservice-discord.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service" mode: 0644 register: matrix_appservice_discord_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-discord.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_discord_systemd_service_result.changed" - name: Ensure matrix-appservice-discord.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-appservice-discord.service" state: restarted - when: "matrix_appservice_discord_requires_restart|bool" + when: "matrix_appservice_discord_requires_restart | bool" diff --git a/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml index ab56c26b..83588d1c 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-discord service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-discord.service" register: matrix_appservice_discord_service_stat - name: Ensure matrix-appservice-discord is stopped - service: + ansible.builtin.service: name: matrix-appservice-discord state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_discord_service_stat.stat.exists" - name: Ensure matrix-appservice-discord.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-discord.service" state: absent when: "matrix_appservice_discord_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-discord.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_discord_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml b/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml index 73253ba0..901b760b 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_appservice_discord_homeserver_domain" - name: (Deprecation) Catch and report renamed appservice-discord variables - fail: + 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 }}`). @@ -22,5 +22,5 @@ - {'old': 'matrix_appservice_discord_container_expose_client_server_api_port', 'new': ''} - name: Require a valid database engine - fail: msg="`matrix_appservice_discord_database_engine` needs to be either 'sqlite' or 'postgres'" + ansible.builtin.fail: msg="`matrix_appservice_discord_database_engine` needs to be either 'sqlite' or 'postgres'" when: "matrix_appservice_discord_database_engine not in ['sqlite', 'postgres']" diff --git a/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 b/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 index 569a3030..a530af2e 100644 --- a/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 +++ b/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 @@ -34,7 +34,7 @@ bridge: determineCodeLanguage: false # Authentication configuration for the discord bot. auth: - clientID: {{ matrix_appservice_discord_client_id|string|to_json }} + clientID: {{ matrix_appservice_discord_client_id | string|to_json }} botToken: {{ matrix_appservice_discord_bot_token|to_json }} # You must enable "Privileged Gateway Intents" in your bot settings on discord.com (e.g. https://discord.com/developers/applications/12345/bot) # for this to work diff --git a/roles/matrix-bridge-appservice-irc/defaults/main.yml b/roles/matrix-bridge-appservice-irc/defaults/main.yml index 5dfe3623..93a8e084 100644 --- a/roles/matrix-bridge-appservice-irc/defaults/main.yml +++ b/roles/matrix-bridge-appservice-irc/defaults/main.yml @@ -1,15 +1,19 @@ --- # Matrix Appservice IRC is a Matrix <-> IRC bridge -# See: https://github.com/matrix-org/matrix-appservice-irc +# Project source code URL: https://github.com/matrix-org/matrix-appservice-irc matrix_appservice_irc_enabled: true matrix_appservice_irc_container_image_self_build: false matrix_appservice_irc_docker_repo: "https://github.com/matrix-org/matrix-appservice-irc.git" +matrix_appservice_irc_docker_repo_version: "{{ 'master' if matrix_appservice_irc_version == 'latest' else matrix_appservice_irc_version }}" matrix_appservice_irc_docker_src_files_path: "{{ matrix_base_data_path }}/appservice-irc/docker-src" -matrix_appservice_irc_version: release-0.33.0 -matrix_appservice_irc_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-irc:{{ matrix_appservice_irc_version }}" +# matrix_appservice_irc_version used to contain the full Docker image tag (e.g. `release-X.X.X`). +# It's a bare version number now. We try to somewhat retain compatibility below. +matrix_appservice_irc_version: 0.34.0 +matrix_appservice_irc_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-irc:{{ matrix_appservice_irc_docker_image_tag }}" +matrix_appservice_irc_docker_image_tag: "{{ 'latest' if matrix_appservice_irc_version == 'latest' else ('release-' + matrix_appservice_irc_version) }}" matrix_appservice_irc_docker_image_force_pull: "{{ matrix_appservice_irc_docker_image.endswith(':latest') }}" matrix_appservice_irc_base_path: "{{ matrix_base_data_path }}/appservice-irc" @@ -19,7 +23,7 @@ matrix_appservice_irc_data_path: "{{ matrix_appservice_irc_base_path }}/data" matrix_appservice_irc_homeserver_url: "{{ matrix_homeserver_container_url }}" matrix_appservice_irc_homeserver_media_url: 'https://{{ matrix_server_fqn_matrix }}' matrix_appservice_irc_homeserver_domain: '{{ matrix_domain }}' -matrix_appservice_irc_homeserver_enablePresence: true +matrix_appservice_irc_homeserver_enablePresence: true # noqa var-naming matrix_appservice_irc_appservice_address: 'http://matrix-appservice-irc:9999' matrix_appservice_irc_database_engine: nedb @@ -34,14 +38,15 @@ matrix_appservice_irc_database_name: matrix_appservice_irc matrix_appservice_irc_database_connection_string: 'postgresql://{{ matrix_appservice_irc_database_username }}:{{ matrix_appservice_irc_database_password }}@{{ matrix_appservice_irc_database_hostname }}:{{ matrix_appservice_irc_database_port }}/{{ matrix_appservice_irc_database_name }}?sslmode=disable' # This is what actually goes into `database.connectionString` for the bridge. -matrix_appservice_irc_database_connectionString: "{{ - { - 'nedb': 'nedb:///data', - 'postgres': matrix_appservice_irc_database_connection_string, - }[matrix_appservice_irc_database_engine] -}}" +matrix_appservice_irc_database_connectionString: |- # noqa var-naming + {{ + { + 'nedb': 'nedb:///data', + 'postgres': matrix_appservice_irc_database_connection_string, + }[matrix_appservice_irc_database_engine] + }} -matrix_appservice_irc_ircService_servers: [] +matrix_appservice_irc_ircService_servers: [] # noqa var-naming # Example of `matrix_appservice_irc_ircService_servers` with one server (and all its options): # @@ -382,9 +387,9 @@ matrix_appservice_irc_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_appservice_irc_configuration_yaml`. -matrix_appservice_irc_configuration_extension: "{{ matrix_appservice_irc_configuration_extension_yaml|from_yaml if matrix_appservice_irc_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_appservice_irc_configuration_extension: "{{ matrix_appservice_irc_configuration_extension_yaml | from_yaml if matrix_appservice_irc_configuration_extension_yaml | from_yaml is mapping else {} }}" -matrix_appservice_irc_configuration: "{{ matrix_appservice_irc_configuration_yaml|from_yaml|combine(matrix_appservice_irc_configuration_extension, recursive=True) }}" +matrix_appservice_irc_configuration: "{{ matrix_appservice_irc_configuration_yaml | from_yaml | combine(matrix_appservice_irc_configuration_extension, recursive=True) }}" # The original registration.yaml file generated by AppService IRC is merged with this config override, # to produce the final registration.yaml file ultimately used by both the bridge and the homeserver. @@ -399,4 +404,4 @@ matrix_appservice_irc_registration_override_yaml: | as_token: "{{ matrix_appservice_irc_appservice_token }}" hs_token: "{{ matrix_appservice_irc_homeserver_token }}" -matrix_appservice_irc_registration_override: "{{ matrix_appservice_irc_registration_override_yaml|from_yaml }}" +matrix_appservice_irc_registration_override: "{{ matrix_appservice_irc_registration_override_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-irc/tasks/init.yml b/roles/matrix-bridge-appservice-irc/tasks/init.yml index 5e181412..9713e9b7 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/init.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/init.yml @@ -2,31 +2,35 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the matrix-appservice-irc image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_appservice_irc_container_image_self_build and matrix_appservice_irc_enabled" # 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-appservice-irc role needs to execute before the matrix-synapse role. - when: "matrix_appservice_irc_enabled|bool and matrix_synapse_role_executed|default(False)" + when: "matrix_appservice_irc_enabled | bool and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-irc.service'] }}" - when: matrix_appservice_irc_enabled|bool + when: matrix_appservice_irc_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([]) }} - + - ["--mount type=bind,src={{ matrix_appservice_irc_config_path }}/registration.yaml,dst=/matrix-appservice-irc-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_appservice_irc_config_path }}/registration.yaml,dst=/matrix-appservice-irc-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-appservice-irc-registration.yaml"] }} - when: matrix_appservice_irc_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-appservice-irc-registration.yaml"] + }} + when: matrix_appservice_irc_enabled | bool diff --git a/roles/matrix-bridge-appservice-irc/tasks/main.yml b/roles/matrix-bridge-appservice-irc/tasks/main.yml index 339615ea..41d2017b 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/main.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_irc_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_irc_enabled | bool" tags: - setup-all - setup-appservice-irc -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_irc_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_irc_enabled | bool" tags: - setup-all - setup-appservice-irc -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_irc_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_irc_enabled | bool" tags: - setup-all - setup-appservice-irc diff --git a/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml b/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml index d7fcaa07..d5f4eefd 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml @@ -1,46 +1,46 @@ --- - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Check existence of matrix-appservice-irc service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" register: matrix_appservice_irc_service_stat - name: Ensure matrix-appservice-irc is stopped - service: + ansible.builtin.service: name: matrix-appservice-irc state: stopped when: "matrix_appservice_irc_service_stat.stat.exists" - name: Import appservice-irc NeDB database into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -52,19 +52,23 @@ {{ matrix_appservice_irc_docker_image }} -c '/usr/local/bin/node /app/lib/scripts/migrate-db-to-pgres.js --dbdir /data --privateKey /data/passkey.pem --connectionString {{ matrix_appservice_irc_database_connection_string }}' + register: matrix_appservice_irc_import_nedb_to_postgres_result + changed_when: matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0 - name: Archive NeDB database files - command: + ansible.builtin.command: cmd: "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup" with_items: - rooms.db - users.db + register: matrix_appservice_irc_import_nedb_to_postgres_move_result + changed_when: matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0 - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your appservice-irc database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_irc_data_path }}/*.db` to `{{ matrix_appservice_irc_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files." diff --git a/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml b/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml index 1ae0b3fa..6b7fc92d 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml @@ -1,9 +1,9 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" - name: Ensure Appservice IRC paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,47 +14,53 @@ - {path: "{{ matrix_appservice_irc_config_path }}", when: true} - {path: "{{ matrix_appservice_irc_data_path }}", when: true} - {path: "{{ matrix_appservice_irc_docker_src_files_path }}", when: "{{ matrix_appservice_irc_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Check if an old passkey file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_irc_base_path }}/passkey.pem" register: matrix_appservice_irc_stat_passkey - block: - name: (Data relocation) Ensure matrix-appservice-irc.service is stopped - service: + ansible.builtin.service: name: matrix-appservice-irc state: stopped daemon_reload: true failed_when: false - name: (Data relocation) Move AppService IRC passkey.pem file to ./data directory - command: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem" + ansible.builtin.command: + cmd: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem" + register: matrix_appservice_irc_move_passkey_result + changed_when: matrix_appservice_irc_move_passkey_result.rc == 0 - name: (Data relocation) Move AppService IRC database files to ./data directory - command: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}" + ansible.builtin.command: + cmd: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}" + register: matrix_appservice_irc_move_dbs_result + changed_when: matrix_appservice_irc_move_dbs_result.rc == 0 with_items: - rooms.db - users.db failed_when: false when: "matrix_appservice_irc_stat_passkey.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_appservice_irc_requires_restart: false - block: - name: Check if a nedb database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_irc_data_path }}/users.db" register: matrix_appservice_irc_nedb_database_path_local_stat_result - block: - - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" + - ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" - - set_fact: + - ansible.builtin.set_fact: matrix_appservice_irc_requires_restart: true - when: "matrix_appservice_irc_nedb_database_path_local_stat_result.stat.exists|bool" + when: "matrix_appservice_irc_nedb_database_path_local_stat_result.stat.exists | bool" when: "matrix_appservice_irc_database_engine == 'postgres'" - name: Ensure Appservice IRC image is pulled @@ -63,21 +69,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_appservice_irc_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_appservice_irc_docker_image_force_pull }}" - when: "matrix_appservice_irc_enabled|bool and not matrix_appservice_irc_container_image_self_build|bool" + when: "matrix_appservice_irc_enabled | bool and not matrix_appservice_irc_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-appservice-irc repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_appservice_irc_docker_repo }}" + version: "{{ matrix_appservice_irc_docker_repo_version }}" dest: "{{ matrix_appservice_irc_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_appservice_irc_git_pull_results - when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool" + when: "matrix_appservice_irc_enabled | bool and matrix_appservice_irc_container_image_self_build | bool" - name: Ensure matrix-appservice-irc Docker image is built docker_image: @@ -89,23 +96,23 @@ dockerfile: Dockerfile path: "{{ matrix_appservice_irc_docker_src_files_path }}" pull: true - when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool and matrix_appservice_irc_git_pull_results.changed" + when: "matrix_appservice_irc_enabled | bool and matrix_appservice_irc_container_image_self_build | bool and matrix_appservice_irc_git_pull_results.changed" - name: Ensure Matrix Appservice IRC config installed - copy: - content: "{{ matrix_appservice_irc_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_irc_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_irc_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Check if Appservice IRC passkey exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_irc_data_path }}/passkey.pem" register: irc_passkey_file - name: Generate Appservice IRC passkey if it doesn't exist - shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048" + ansible.builtin.shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048" become: true become_user: "{{ matrix_user_username }}" when: "not irc_passkey_file.stat.exists" @@ -113,7 +120,7 @@ # In the past, we used to generate the passkey.pem file with root, so permissions may not be okay. # Fix it. - name: (Migration) Ensure Appservice IRC passkey permissions are okay - file: + ansible.builtin.file: path: "{{ matrix_appservice_irc_data_path }}/passkey.pem" mode: 0644 owner: "{{ matrix_user_username }}" @@ -139,7 +146,7 @@ # an up-to-date file, and we fix it up with some static values later on, # to produce a final registration.yaml file, as we desire. - name: Generate Appservice IRC registration-template.yaml - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name matrix-appservice-irc-gen --user={{ matrix_user_uid }}:{{ matrix_user_gid }} --cap-drop=ALL @@ -157,46 +164,46 @@ changed_when: false - name: Read Appservice IRC registration-template.yaml - slurp: + ansible.builtin.slurp: src: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml" register: matrix_appservice_irc_registration_template_slurp - name: Remove unnecessary Appservice IRC registration-template.yaml - file: + ansible.builtin.file: path: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml" state: absent changed_when: false - name: Parse registration-template.yaml - set_fact: + ansible.builtin.set_fact: matrix_appservice_irc_registration_template: "{{ matrix_appservice_irc_registration_template_slurp['content'] | b64decode | from_yaml }}" - name: Combine registration-template.yaml and own registration override config - set_fact: - matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template|combine(matrix_appservice_irc_registration_override, recursive=True) }}" + ansible.builtin.set_fact: + matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template | combine(matrix_appservice_irc_registration_override, recursive=True) }}" - name: Ensure Appservice IRC registration.yaml installed - copy: - content: "{{ matrix_appservice_irc_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_irc_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_irc_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-appservice-irc.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-irc.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" mode: 0644 register: matrix_appservice_irc_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-irc.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_irc_systemd_service_result.changed" - name: Ensure matrix-appservice-irc.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-appservice-irc.service" state: restarted - when: "matrix_appservice_irc_requires_restart|bool" + when: "matrix_appservice_irc_requires_restart | bool" diff --git a/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml index a4d95df5..176317de 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-irc service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" register: matrix_appservice_irc_service_stat - name: Ensure matrix-appservice-irc is stopped - service: + ansible.builtin.service: name: matrix-appservice-irc state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_irc_service_stat.stat.exists" - name: Ensure matrix-appservice-irc.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" state: absent when: "matrix_appservice_irc_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-irc.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_irc_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml b/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml index 303f2640..f101e6fe 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -17,7 +17,7 @@ # # This is a safety check to ensure we fail earlier and in a nicer way. - name: Fail if no additional configuration provided - fail: + ansible.builtin.fail: msg: >- Your Appservice IRC configuration is incomplete (lacking an `ircService.servers` configuration). You need to define one or more servers by either using `matrix_appservice_irc_ircService_servers` @@ -26,7 +26,7 @@ when: "matrix_appservice_irc_configuration.ircService.servers|length == 0" - name: (Deprecation) Catch and report renamed appservice-irc variables - fail: + 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 }}`). diff --git a/roles/matrix-bridge-appservice-kakaotalk/defaults/main.yml b/roles/matrix-bridge-appservice-kakaotalk/defaults/main.yml new file mode 100644 index 00000000..f27f75c5 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/defaults/main.yml @@ -0,0 +1,200 @@ +--- +# matrix-appservice-kakaotalk is a Matrix <-> Kakaotalk bridge +# Project source code URL: https://src.miscworks.net/fair/matrix-appservice-kakaotalk/ + +matrix_appservice_kakaotalk_enabled: true + +# No images are published for neither of the container images (appservice or node), so we're self-building everything. +matrix_appservice_kakaotalk_container_image_self_build: true +# matrix_appservice_kakaotalk_container_image_self_build_repo: "https://src.miscworks.net/fair/matrix-appservice-kakaotalk.git" +# +# hnarjis' fork is used instead of upstream (fair's), because upstream is currently broken. +# The following error happens when chatting up the bot without this fix: +# [2022-07-25 09:04:53,784] [ERROR@mau.as] Exception in Matrix event handler +# Traceback (most recent call last): +# File "/usr/lib/python3.9/site-packages/mautrix/appservice/as_handler.py", line 239, in try_handle +# await handler_func(event) +# File "/usr/lib/python3.9/site-packages/mautrix/bridge/matrix.py", line 820, in int_handle_event +# await self.int_handle_invite(evt) +# File "/usr/lib/python3.9/site-packages/mautrix/bridge/matrix.py", line 441, in int_handle_invite +# inviter = await self.bridge.get_user(evt.sender) +# File "/usr/lib/python3.9/site-packages/matrix_appservice_kakaotalk/__main__.py", line 112, in get_user +# return await User.get_by_mxid(user_id, create=create) +# File "/usr/lib/python3.9/site-packages/mautrix/util/async_getter_lock.py", line 60, in wrapper +# return await fn(cls, *args, **kwargs) +# File "/usr/lib/python3.9/site-packages/matrix_appservice_kakaotalk/user.py", line 227, in get_by_mxid +# user = cls(mxid) +# TypeError: __init__() missing 2 required positional arguments: 'force_login' and 'was_connected' +matrix_appservice_kakaotalk_container_image_self_build_repo: "https://src.miscworks.net/hnarjis/matrix-appservice-kakaotalk.git" +matrix_appservice_kakaotalk_container_image_self_build_repo_version: "{{ 'master' if matrix_appservice_kakaotalk_version == 'latest' else matrix_appservice_kakaotalk_version }}" + +matrix_appservice_kakaotalk_node_version: "{{ matrix_appservice_kakaotalk_version }}" +matrix_appservice_kakaotalk_node_docker_image: "{{ matrix_appservice_kakaotalk_node_docker_image_prefix }}fair/matrix-appservice-kakaotalk-node:{{ matrix_appservice_kakaotalk_node_version }}" +matrix_appservice_kakaotalk_node_docker_image_prefix: "localhost/" +matrix_appservice_kakaotalk_node_docker_image_force_pull: "{{ matrix_appservice_kakaotalk_node_docker_image.endswith(':latest') }}" + +matrix_appservice_kakaotalk_version: 86c038fd2ffee5e0aebf65136f085cce7e38b54e +matrix_appservice_kakaotalk_docker_image: "{{ matrix_appservice_kakaotalk_docker_image_name_prefix }}fair/matrix-appservice-kakaotalk:{{ matrix_appservice_kakaotalk_version }}" +matrix_appservice_kakaotalk_docker_image_name_prefix: "localhost/" +matrix_appservice_kakaotalk_docker_image_force_pull: "{{ matrix_appservice_kakaotalk_docker_image.endswith(':latest') }}" + +matrix_appservice_kakaotalk_base_path: "{{ matrix_base_data_path }}/appservice-kakaotalk" +matrix_appservice_kakaotalk_config_path: "{{ matrix_appservice_kakaotalk_base_path }}/config" +matrix_appservice_kakaotalk_data_path: "{{ matrix_appservice_kakaotalk_base_path }}/data" +matrix_appservice_kakaotalk_docker_src_files_path: "{{ matrix_appservice_kakaotalk_base_path }}/docker-src" + +matrix_appservice_kakaotalk_command_prefix: "!kt" + +matrix_appservice_kakaotalk_homeserver_address: "{{ matrix_homeserver_container_url }}" +matrix_appservice_kakaotalk_homeserver_domain: '{{ matrix_domain }}' +matrix_appservice_kakaotalk_appservice_address: 'http://matrix-appservice-kakaotalk:11115' + + +# A list of extra arguments to pass to the appservice-kakaotalk container +matrix_appservice_kakaotalk_container_extra_arguments: [] + +# List of systemd services that matrix-appservice-kakaotalk.service depends on. +matrix_appservice_kakaotalk_systemd_required_services_list: ['docker.service', 'matrix-appservice-kakaotalk-node.service'] + +# List of systemd services that matrix-appservice-kakaotalk.service wants +matrix_appservice_kakaotalk_systemd_wanted_services_list: [] + + +# A list of extra arguments to pass to the appservice-kakaotalk-node container +matrix_appservice_kakaotalk_node_container_extra_arguments: [] + +# List of systemd services that matrix-appservice-kakaotalk-node.service depends on. +matrix_appservice_kakaotalk_node_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-appservice-kakaotalk-node.service wants +matrix_appservice_kakaotalk_node_systemd_wanted_services_list: [] + + +matrix_appservice_kakaotalk_appservice_token: '' +matrix_appservice_kakaotalk_homeserver_token: '' + +# Whether or not created rooms should have federation enabled. +# If false, created portal rooms will never be federated. +matrix_appservice_kakaotalk_federate_rooms: true + +# Database-related configuration fields. +# +# To use SQLite: +# - change the engine (`matrix_appservice_kakaotalk_database_engine: 'sqlite'`) +# To use Postgres: +# - adjust your database credentials via the `matrix_appservice_kakaotalk_database_*` variables +matrix_appservice_kakaotalk_database_engine: 'postgres' + +matrix_appservice_kakaotalk_sqlite_database_path_local: "{{ matrix_appservice_kakaotalk_data_path }}/appservice-kakaotalk.db" +matrix_appservice_kakaotalk_sqlite_database_path_in_container: "/data/appservice-kakaotalk.db" + +matrix_appservice_kakaotalk_database_username: 'matrix_appservice_kakaotalk' +matrix_appservice_kakaotalk_database_password: 'some-password' +matrix_appservice_kakaotalk_database_hostname: 'matrix-postgres' +matrix_appservice_kakaotalk_database_port: 5432 +matrix_appservice_kakaotalk_database_name: 'matrix_appservice_kakaotalk' + +matrix_appservice_kakaotalk_database_connection_string: 'postgres://{{ matrix_appservice_kakaotalk_database_username }}:{{ matrix_appservice_kakaotalk_database_password }}@{{ matrix_appservice_kakaotalk_database_hostname }}:{{ matrix_appservice_kakaotalk_database_port }}/{{ matrix_appservice_kakaotalk_database_name }}' + +matrix_appservice_kakaotalk_appservice_database: "{{ + { + 'sqlite': ('sqlite:///' + matrix_appservice_kakaotalk_sqlite_database_path_in_container), + 'postgres': matrix_appservice_kakaotalk_database_connection_string, + }[matrix_appservice_kakaotalk_database_engine] +}}" + + +# Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). +# Also see: matrix_appservice_kakaotalk_bridge_login_shared_secret_map +matrix_appservice_kakaotalk_login_shared_secret: '' + +matrix_appservice_kakaotalk_bridge_login_shared_secret_map: "{{ {matrix_appservice_kakaotalk_homeserver_domain: matrix_appservice_kakaotalk_login_shared_secret} if matrix_appservice_kakaotalk_login_shared_secret else {} }}" + +matrix_appservice_kakaotalk_bridge_permissions: | + {{ + {matrix_appservice_kakaotalk_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + +matrix_appservice_kakaotalk_appservice_bot_username: kakaotalkbot +matrix_appservice_kakaotalk_user_prefix: 'kakaotalk_' + +# End-to-bridge encryption configuration +matrix_appservice_kakaotalk_bridge_encryption_allow: false +matrix_appservice_kakaotalk_bridge_encryption_default: "{{ matrix_appservice_kakaotalk_bridge_encryption_allow }}" + +# Specifies the default log level for all bridge loggers. +matrix_appservice_kakaotalk_logging_level: WARNING + + +# Default configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_appservice_kakaotalk_configuration_extension_yaml`) +# or completely replace this variable with your own template. +matrix_appservice_kakaotalk_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" + +matrix_appservice_kakaotalk_configuration_extension_yaml: | + # Your custom YAML configuration goes here. + # This configuration extends the default starting configuration (`matrix_appservice_kakaotalk_configuration_yaml`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_appservice_kakaotalk_configuration_yaml`. + +matrix_appservice_kakaotalk_configuration_extension: "{{ matrix_appservice_kakaotalk_configuration_extension_yaml | from_yaml if matrix_appservice_kakaotalk_configuration_extension_yaml | from_yaml is mapping else {} }}" + +# Holds the final configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_appservice_kakaotalk_configuration_yaml`. +matrix_appservice_kakaotalk_configuration: "{{ matrix_appservice_kakaotalk_configuration_yaml | from_yaml | combine(matrix_appservice_kakaotalk_configuration_extension, recursive=True) }}" + + +# Default configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_appservice_kakaotalk_node_configuration_extension_yaml`) +# or completely replace this variable with your own template. +# +# The side-effect of this lookup is that Ansible would even parse the JSON for us, returning a dict. +# This is unlike what it does when looking up YAML template files (no automatic parsing there). +matrix_appservice_kakaotalk_node_configuration_default: "{{ lookup('template', 'templates/node-config.json.j2') }}" + +# Your custom JSON configuration for appservice-kakaotalk-node should go to `matrix_appservice_kakaotalk_node_configuration_extension_json`. +# This configuration extends the default starting configuration (`matrix_appservice_kakaotalk_node_configuration_default`). +# +# You can override individual variables from the default configuration, or introduce new ones. +# +# If you need something more special, you can take full control by +# completely redefining `matrix_appservice_kakaotalk_node_configuration_default`. +# +# Example configuration extension follows: +# +# matrix_appservice_kakaotalk_node_configuration_extension_json: | +# { +# "register_timeout": 5000 +# } +matrix_appservice_kakaotalk_node_configuration_extension_json: '{}' + +matrix_appservice_kakaotalk_node_configuration_extension: "{{ matrix_appservice_kakaotalk_node_configuration_extension_json | from_json if matrix_appservice_kakaotalk_node_configuration_extension_json | from_json is mapping else {} }}" + +# Holds the final appservice-kakaotalk-node configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_appservice_kakaotalk_node_configuration_default`. +matrix_appservice_kakaotalk_node_configuration: "{{ matrix_appservice_kakaotalk_node_configuration_default | combine(matrix_appservice_kakaotalk_node_configuration_extension, recursive=True) }}" + + +matrix_appservice_kakaotalk_registration_yaml: | + id: appservice-kakaotalk + as_token: {{ matrix_appservice_kakaotalk_appservice_token | to_json }} + hs_token: {{ matrix_appservice_kakaotalk_homeserver_token | to_json }} + namespaces: + users: + - exclusive: true + regex: '^@{{ matrix_appservice_kakaotalk_user_prefix | regex_escape }}.*:{{ matrix_appservice_kakaotalk_homeserver_domain | regex_escape }}$' + - exclusive: true + regex: '^@{{ matrix_appservice_kakaotalk_appservice_bot_username | regex_escape }}:{{ matrix_appservice_kakaotalk_homeserver_domain | regex_escape }}$' + url: {{ matrix_appservice_kakaotalk_appservice_address | to_json }} + sender_localpart: _appservice_kakaotalk + rate_limited: false + +matrix_appservice_kakaotalk_registration: "{{ matrix_appservice_kakaotalk_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-kakaotalk/tasks/init.yml b/roles/matrix-bridge-appservice-kakaotalk/tasks/init.yml new file mode 100644 index 00000000..c2679b35 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/tasks/init.yml @@ -0,0 +1,28 @@ +--- +# See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 +# and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 +- name: Fail if trying to self-build on Ansible < 2.8 + ansible.builtin.fail: + msg: "To self-build the appservice-kakaotalk image, you should use Ansible 2.8 or higher. See docs/ansible.md" + when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_appservice_kakaotalk_container_image_self_build and matrix_appservice_kakaotalk_enabled" + +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-kakaotalk.service', 'matrix-appservice-kakaotalk-node.service'] }}" + when: matrix_appservice_kakaotalk_enabled | bool + +# If the matrix-synapse role is not used, these variables may not exist. +- ansible.builtin.set_fact: + matrix_synapse_container_extra_arguments: > + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_appservice_kakaotalk_config_path }}/registration.yaml,dst=/matrix-appservice-kakaotalk-registration.yaml,ro"] + }} + + matrix_synapse_app_service_config_files: > + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-appservice-kakaotalk-registration.yaml"] + }} + when: matrix_appservice_kakaotalk_enabled | bool diff --git a/roles/matrix-bridge-appservice-kakaotalk/tasks/main.yml b/roles/matrix-bridge-appservice-kakaotalk/tasks/main.yml new file mode 100644 index 00000000..dfb286f2 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/tasks/main.yml @@ -0,0 +1,23 @@ +--- + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_kakaotalk_enabled | bool" + tags: + - setup-all + - setup-appservice-kakaotalk + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_kakaotalk_enabled | bool" + tags: + - setup-all + - setup-appservice-kakaotalk + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_kakaotalk_enabled | bool" + tags: + - setup-all + - setup-appservice-kakaotalk diff --git a/roles/matrix-bridge-appservice-kakaotalk/tasks/setup_install.yml b/roles/matrix-bridge-appservice-kakaotalk/tasks/setup_install.yml new file mode 100644 index 00000000..def73c59 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/tasks/setup_install.yml @@ -0,0 +1,125 @@ +--- + +# 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 + ansible.builtin.fail: + msg: >- + The matrix-bridge-matrix-appservice-kakaotalk role needs to execute before the matrix-synapse role. + when: "matrix_synapse_role_executed | default(False)" + +- name: Ensure matrix-appservice-kakaotalk image is pulled + docker_image: + name: "{{ matrix_appservice_kakaotalk_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_appservice_kakaotalk_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_appservice_kakaotalk_docker_image_force_pull }}" + when: not matrix_appservice_kakaotalk_container_image_self_build + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure matrix-appservice-kakaotalk-node image is pulled + docker_image: + name: "{{ matrix_appservice_kakaotalk_node_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_appservice_kakaotalk_node_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_appservice_kakaotalk_node_docker_image_force_pull }}" + when: not matrix_appservice_kakaotalk_container_image_self_build + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure matrix-appservice-kakaotalk paths exist + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_appservice_kakaotalk_base_path }}", when: true} + - {path: "{{ matrix_appservice_kakaotalk_config_path }}", when: true} + - {path: "{{ matrix_appservice_kakaotalk_data_path }}", when: true} + - {path: "{{ matrix_appservice_kakaotalk_docker_src_files_path }}", when: "{{ matrix_appservice_kakaotalk_container_image_self_build }}"} + when: item.when | bool + +- name: Ensure matrix-appservice-kakaotalk repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_appservice_kakaotalk_container_image_self_build_repo }}" + dest: "{{ matrix_appservice_kakaotalk_docker_src_files_path }}" + version: "{{ matrix_appservice_kakaotalk_container_image_self_build_repo_version }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_appservice_kakaotalk_git_pull_results + when: "matrix_appservice_kakaotalk_container_image_self_build | bool" + +- name: Ensure matrix-appservice-kakaotalk-node Docker image is built + docker_image: + name: "{{ matrix_appservice_kakaotalk_node_docker_image }}" + source: build + force_source: "{{ matrix_appservice_kakaotalk_git_pull_results.changed 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_appservice_kakaotalk_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_appservice_kakaotalk_docker_src_files_path }}/node" + pull: true + when: "matrix_appservice_kakaotalk_container_image_self_build | bool" + +- name: Ensure matrix-appservice-kakaotalk Docker image is built + docker_image: + name: "{{ matrix_appservice_kakaotalk_docker_image }}" + source: build + force_source: "{{ matrix_appservice_kakaotalk_git_pull_results.changed 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_appservice_kakaotalk_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_appservice_kakaotalk_docker_src_files_path }}" + pull: true + when: "matrix_appservice_kakaotalk_container_image_self_build | bool" + +- name: Ensure matrix-appservice-kakaotalk-node config.json installed + ansible.builtin.copy: + content: "{{ matrix_appservice_kakaotalk_node_configuration | to_nice_json }}" + dest: "{{ matrix_appservice_kakaotalk_config_path }}/node-config.json" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-appservice-kakaotalk config.yaml installed + ansible.builtin.copy: + content: "{{ matrix_appservice_kakaotalk_configuration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_appservice_kakaotalk_config_path }}/config.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-appservice-kakaotalk registration.yaml installed + ansible.builtin.copy: + content: "{{ matrix_appservice_kakaotalk_registration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_appservice_kakaotalk_config_path }}/registration.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-appservice-kakaotalk-node.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-appservice-kakaotalk-node.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-appservice-kakaotalk-node.service" + mode: 0644 + register: matrix_appservice_kakaotalk_node_systemd_service_result + +- name: Ensure matrix-appservice-kakaotalk.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-appservice-kakaotalk.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-appservice-kakaotalk.service" + mode: 0644 + register: matrix_appservice_kakaotalk_systemd_service_result + +- name: Ensure systemd reloaded after matrix-appservice-kakaotalk.service or matrix-appservice-kakaotalk-node.service installation + ansible.builtin.service: + daemon_reload: true + when: matrix_appservice_kakaotalk_node_systemd_service_result.changed or matrix_appservice_kakaotalk_systemd_service_result.changed diff --git a/roles/matrix-bridge-appservice-kakaotalk/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-kakaotalk/tasks/setup_uninstall.yml new file mode 100644 index 00000000..fb11c383 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/tasks/setup_uninstall.yml @@ -0,0 +1,41 @@ +--- + +- name: Check existence of matrix-appservice-kakaotalk service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-appservice-kakaotalk.service" + register: matrix_appservice_kakaotalk_service_stat + +- name: Ensure matrix-appservice-kakaotalk is stopped + ansible.builtin.service: + name: matrix-appservice-kakaotalk + state: stopped + enabled: false + daemon_reload: true + when: "matrix_appservice_kakaotalk_service_stat.stat.exists" + +- name: Check existence of matrix-appservice-kakaotalk-node service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-appservice-kakaotalk-node.service" + register: matrix_appservice_kakaotalk_node_service_stat + +- name: Ensure matrix-appservice-kakaotalk-node is stopped + ansible.builtin.service: + name: matrix-appservice-kakaotalk-node + state: stopped + enabled: false + daemon_reload: true + when: "matrix_appservice_kakaotalk_node_service_stat.stat.exists" + +- name: Ensure matrix-appservice-kakaotalk.service files don't exist + ansible.builtin.file: + path: "{{ item }}" + state: absent + with_items: + - "{{ matrix_systemd_path }}/matrix-appservice-kakaotalk-node.service" + - "{{ matrix_systemd_path }}/matrix-appservice-kakaotalk.service" + when: "matrix_appservice_kakaotalk_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-appservice-kakaotalk service files removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_appservice_kakaotalk_service_stat.stat.exists or matrix_appservice_kakaotalk_node_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-kakaotalk/tasks/validate_config.yml b/roles/matrix-bridge-appservice-kakaotalk/tasks/validate_config.yml new file mode 100644 index 00000000..4f838e7a --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/tasks/validate_config.yml @@ -0,0 +1,10 @@ +--- + +- name: Fail if required settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - "matrix_appservice_kakaotalk_appservice_token" + - "matrix_appservice_kakaotalk_homeserver_token" diff --git a/roles/matrix-bridge-appservice-kakaotalk/templates/config.yaml.j2 b/roles/matrix-bridge-appservice-kakaotalk/templates/config.yaml.j2 new file mode 100644 index 00000000..1bb87cb4 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/templates/config.yaml.j2 @@ -0,0 +1,276 @@ +# Homeserver details +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: {{ matrix_appservice_kakaotalk_homeserver_address | to_json }} + # The domain of the homeserver (for MXIDs, etc). + domain: {{ matrix_appservice_kakaotalk_homeserver_domain | to_json }} + # Whether or not to verify the SSL certificate of the homeserver. + # Only applies if address starts with https:// + verify_ssl: true + # Whether or not the homeserver supports asmux-specific endpoints, + # such as /_matrix/client/unstable/net.maunium.asmux/dms for atomically + # updating m.direct. + asmux: false + # Number of retries for all HTTP requests if the homeserver isn't reachable. + http_retry_count: 4 + # The URL to push real-time bridge status to. + # If set, the bridge will make POST requests to this URL whenever a user's MQTT connection state changes. + # The bridge will use the appservice as_token to authorize requests. + status_endpoint: null + # Endpoint for reporting per-message status. + message_send_checkpoint_endpoint: null + # Whether asynchronous uploads via MSC2246 should be enabled for media. + # Requires a media repo that supports MSC2246. + async_media: false + +# Application service host/registration related details +# Changing these values requires regeneration of the registration. +appservice: + # The address that the homeserver can use to connect to this appservice. + address: {{ matrix_appservice_kakaotalk_appservice_address | to_json }} + + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 + port: 11115 + # The maximum body size of appservice API requests (from the homeserver) in mebibytes + # Usually 1 is enough, but on high-traffic bridges you might need to increase this to avoid 413s + max_body_size: 1 + + # The full URI to the database. SQLite and Postgres are supported. + # Format examples: + # SQLite: sqlite:///filename.db + # Postgres: postgres://username:password@hostname/dbname + database: {{ matrix_appservice_kakaotalk_appservice_database | to_json }} + # Additional arguments for asyncpg.create_pool() or sqlite3.connect() + # https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool + # https://docs.python.org/3/library/sqlite3.html#sqlite3.connect + # For sqlite, min_size is used as the connection thread pool size and max_size is ignored. + database_opts: + min_size: 5 + max_size: 10 + + # The unique ID of this appservice. + id: appservice-kakaotalk + # Username of the appservice bot. + bot_username: {{ matrix_appservice_kakaotalk_appservice_bot_username | to_json }} + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + bot_displayname: KakaoTalk bridge bot + bot_avatar: + + # Whether or not to receive ephemeral events via appservice transactions. + # Requires MSC2409 support (i.e. Synapse 1.22+). + # You should disable bridge -> sync_with_custom_puppets when this is enabled. + ephemeral_events: false + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: {{ matrix_appservice_kakaotalk_appservice_token | to_json }} + hs_token: {{ matrix_appservice_kakaotalk_homeserver_token | to_json }} + +# Prometheus telemetry config. Requires prometheus-client to be installed. +metrics: + enabled: false + listen_port: 8000 + +# Manhole config. +manhole: + # Whether or not opening the manhole is allowed. + enabled: false + # The path for the unix socket. + path: /var/tmp/matrix-appservice-kakaotalk.manhole + # The list of UIDs who can be added to the whitelist. + # If empty, any UIDs can be specified in the open-manhole command. + whitelist: + - 0 + +# Config for things that are directly sent to KakaoTalk. +kakaotalk: + device_name: "KakaoTalk Bridge" + +# Bridge config +bridge: + # Localpart template of MXIDs for KakaoTalk users. + # {userid} is replaced with the user ID of the KakaoTalk user. + username_template: "{{ matrix_appservice_kakaotalk_user_prefix }}{userid}" + # Displayname template for KakaoTalk users. + # {displayname} is replaced with the display name of the KakaoTalk user. + displayname_template: "{displayname} (KT)" + + # The prefix for commands. Only required in non-management rooms. + command_prefix: {{ matrix_appservice_kakaotalk_command_prefix | to_json }} + + # Number of chats to sync (and create portals for) on startup/login. + # Set to 0 to disable automatic syncing, or -1 to sync as much as possible. + initial_chat_sync: 20 + # Whether or not the KakaoTalk users of logged in Matrix users should be + # invited to private chats when the user sends a message from another client. + invite_own_puppet_to_pm: false + # Whether or not to use /sync to get presence, read receipts and typing notifications + # when double puppeting is enabled + sync_with_custom_puppets: true + # Whether or not to update the m.direct account data event when double puppeting is enabled. + # Note that updating the m.direct event is not atomic (except with mautrix-asmux) + # and is therefore prone to race conditions. + sync_direct_chat_list: false + # Servers to always allow double puppeting from + double_puppet_server_map: {} + # Allow using double puppeting from any server with a valid client .well-known file. + double_puppet_allow_discovery: false + # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth + # + # If set, custom puppets will be enabled automatically for local users + # instead of users having to find an access token and run `login-matrix` + # manually. + # If using this for other servers than the bridge's server, + # you must also set the URL in the double_puppet_server_map. + login_shared_secret_map: {{ matrix_appservice_kakaotalk_bridge_login_shared_secret_map | to_json }} + # Whether or not to update avatars when syncing all contacts at startup. + update_avatar_initial_sync: true + # End-to-bridge encryption support options. These require matrix-nio to be installed with pip + # and login_shared_secret to be configured in order to get a device for the bridge bot. + # + # Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal + # application service. + encryption: + # Allow encryption, work in group chat rooms with e2ee enabled + allow: {{ matrix_appservice_kakaotalk_bridge_encryption_allow | to_json }} + # Default to encryption, force-enable encryption in all portals the bridge creates + # This will cause the bridge bot to be in private chats for the encryption to work properly. + default: {{ matrix_appservice_kakaotalk_bridge_encryption_default| to_json }} + # Options for automatic key sharing. + key_sharing: + # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. + # You must use a client that supports requesting keys from other users to use this feature. + allow: false + # Require the requesting device to have a valid cross-signing signature? + # This doesn't require that the bridge has verified the device, only that the user has verified it. + # Not yet implemented. + require_cross_signing: false + # Require devices to be verified by the bridge? + # Verification by the bridge is not yet implemented. + require_verification: true + # Whether or not the bridge should send a read receipt from the bridge bot when a message has + # been sent to KakaoTalk. + delivery_receipts: false + # Whether to allow inviting arbitrary mxids to portal rooms + allow_invites: false + # Whether or not created rooms should have federation enabled. + # If false, created portal rooms will never be federated. + federate_rooms: {{ matrix_appservice_kakaotalk_federate_rooms | to_json }} + # Settings for backfilling messages from KakaoTalk. + backfill: + # Whether or not the KakaoTalk users of logged in Matrix users should be + # invited to private chats when backfilling history from KakaoTalk. This is + # usually needed to prevent rate limits and to allow timestamp massaging. + invite_own_puppet: true + # Maximum number of messages to backfill initially. + # Set to 0 to disable backfilling when creating portal, or -1 to backfill as much as possible. + initial_limit: 0 + # Maximum number of messages to backfill if messages were missed while + # the bridge was disconnected. + # Set to 0 to disable backfilling missed messages, or -1 to backfill as much as possible. + missed_limit: 1000 + # If using double puppeting, should notifications be disabled + # while the initial backfill is in progress? + disable_notifications: false + # The number of seconds that a disconnection can last without triggering an automatic re-sync + # and missed message backfilling when reconnecting. + # Set to 0 to always re-sync, or -1 to never re-sync automatically. + resync_max_disconnected_time: 5 + # Should users remain logged in after being disconnected from chatroom updates? + # This is a convenience feature, but might make the bridge look more suspicious to KakaoTalk. + remain_logged_in_on_disconnect: true + # May the bridge restore user logins with session tokens instead of requiring a password? + # This is a convenience feature, but might make the bridge look more suspicious to KakaoTalk. + # Note that password-based login will be tried first for users who have saved their password. + allow_token_relogin: true + # Should the bridge connect users to chatroom updates after a token-based login? + # This will disconnect any KakaoTalk PC/bridge sessions that were started since the last connection. + # This is a convenience feature, but might make the bridge look more suspicious to KakaoTalk. + reconnect_on_token_relogin: true + # Should the bridge do a resync for connected users on startup? + sync_on_startup: true + # Whether or not temporary disconnections should send notices to the notice room. + # If this is false, disconnections will never send messages and connections will only send + # messages if it was disconnected for more than resync_max_disconnected_time seconds. + temporary_disconnect_notices: true + # Disable bridge notices entirely + disable_bridge_notices: false + # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. + # This field will automatically be changed back to false after it, + # except if the config file is not writable. + resend_bridge_info: false + # Whether or not mute status and tags should only be bridged when the portal room is created. + tag_only_on_create: true + # If set to true, downloading media from the CDN will use a plain aiohttp client without the usual headers or + # other configuration. This may be useful if you don't want to use the default proxy for large files. + sandbox_media_download: false + + # Permissions for using the bridge. + # Permitted values: + # relay - Allowed to be relayed through the bridge, no access to commands. + # user - Use the bridge with puppeting. + # admin - Use and administrate the bridge. + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: {{ matrix_appservice_kakaotalk_bridge_permissions | to_json }} + + relay: + # Whether relay mode should be allowed. If allowed, `!kt set-relay` can be used to turn any + # authenticated user into a relaybot for that chat. + enabled: false + # The formats to use when sending messages to KakaoTalk via a relay user. + # + # Available variables: + # $sender_displayname - The display name of the sender (e.g. Example User) + # $sender_username - The username (Matrix ID localpart) of the sender (e.g. exampleuser) + # $sender_mxid - The Matrix ID of the sender (e.g. @exampleuser:example.com) + # $message - The message content + message_formats: + m.text: '$sender_displayname: $message' + m.notice: '$sender_displayname: $message' + m.emote: '* $sender_displayname $message' + m.file: 'File from $sender_displayname: $message' + m.image: 'Image from $sender_displayname: $message' + m.audio: 'Audio from $sender_displayname: $message' + m.video: 'Video from $sender_displayname: $message' + m.location: '$sender_displayname sent a location' + +rpc: + connection: + # Either unix or tcp + type: tcp + # Only for type: unix + # path: /rpc/rpc.sock + # Only for type: tcp + host: matrix-appservice-kakaotalk-node + port: 8000 + +# Python logging configuration. +# +# See section 16.7.2 of the Python documentation for more info: +# https://docs.python.org/3.6/library/logging.config.html#configuration-dictionary-schema +logging: + version: 1 + formatters: + colored: + (): matrix_appservice_kakaotalk.util.ColorFormatter + format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s" + normal: + format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s" + handlers: + console: + class: logging.StreamHandler + formatter: colored + loggers: + mau: + level: {{ matrix_appservice_kakaotalk_logging_level | to_json }} + paho: + level: {{ matrix_appservice_kakaotalk_logging_level | to_json }} + aiohttp: + level: {{ matrix_appservice_kakaotalk_logging_level | to_json }} + root: + level: {{ matrix_appservice_kakaotalk_logging_level | to_json }} + handlers: [console] diff --git a/roles/matrix-bridge-appservice-kakaotalk/templates/node-config.json.j2 b/roles/matrix-bridge-appservice-kakaotalk/templates/node-config.json.j2 new file mode 100644 index 00000000..82709138 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/templates/node-config.json.j2 @@ -0,0 +1,13 @@ +{ + "listen": { + "type": "tcp", + "host": "0.0.0.0", + "port": 8000, + "force": false + }, + "register_timeout": 3000, + "logging_keys": { + "request": ["mxid"], + "response": ["status"] + } +} diff --git a/roles/matrix-bridge-appservice-kakaotalk/templates/systemd/matrix-appservice-kakaotalk-node.service.j2 b/roles/matrix-bridge-appservice-kakaotalk/templates/systemd/matrix-appservice-kakaotalk-node.service.j2 new file mode 100644 index 00000000..1a526ee6 --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/templates/systemd/matrix-appservice-kakaotalk-node.service.j2 @@ -0,0 +1,38 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=appservice-kakaotalk-node bridge helper +{% for service in matrix_appservice_kakaotalk_node_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_appservice_kakaotalk_node_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-appservice-kakaotalk-node 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-appservice-kakaotalk-node 2>/dev/null || true' + +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-appservice-kakaotalk-node \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_docker_network }} \ + --mount type=bind,src={{ matrix_appservice_kakaotalk_config_path }}/node-config.json,dst=/config.json,ro \ + {% for arg in matrix_appservice_kakaotalk_node_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + {{ matrix_appservice_kakaotalk_node_docker_image }} \ + node src/main.js --config /config.json + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-appservice-kakaotalk-node 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-appservice-kakaotalk-node 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-appservice-kakaotalk-node + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-bridge-appservice-kakaotalk/templates/systemd/matrix-appservice-kakaotalk.service.j2 b/roles/matrix-bridge-appservice-kakaotalk/templates/systemd/matrix-appservice-kakaotalk.service.j2 new file mode 100644 index 00000000..83a8d4dc --- /dev/null +++ b/roles/matrix-bridge-appservice-kakaotalk/templates/systemd/matrix-appservice-kakaotalk.service.j2 @@ -0,0 +1,42 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=appservice-kakaotalk bridge +{% for service in matrix_appservice_kakaotalk_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_appservice_kakaotalk_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-appservice-kakaotalk 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-appservice-kakaotalk 2>/dev/null || true' + +# 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-appservice-kakaotalk \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_docker_network }} \ + --mount type=bind,src={{ matrix_appservice_kakaotalk_config_path }},dst=/config,ro \ + --mount type=bind,src={{ matrix_appservice_kakaotalk_data_path }},dst=/data \ + {% for arg in matrix_appservice_kakaotalk_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + {{ matrix_appservice_kakaotalk_docker_image }} \ + python3 -m matrix_appservice_kakaotalk -c /config/config.yaml --no-update + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-appservice-kakaotalk 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-appservice-kakaotalk 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-appservice-kakaotalk + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-bridge-appservice-slack/defaults/main.yml b/roles/matrix-bridge-appservice-slack/defaults/main.yml index e303f834..71fca8e6 100644 --- a/roles/matrix-bridge-appservice-slack/defaults/main.yml +++ b/roles/matrix-bridge-appservice-slack/defaults/main.yml @@ -1,15 +1,19 @@ --- # matrix-appservice-slack is a Matrix <-> Slack bridge -# See: https://github.com/matrix-org/matrix-appservice-slack +# Project source code URL: https://github.com/matrix-org/matrix-appservice-slack matrix_appservice_slack_enabled: true matrix_appservice_slack_container_image_self_build: false matrix_appservice_slack_docker_repo: "https://github.com/matrix-org/matrix-appservice-slack.git" +matrix_appservice_slack_docker_repo_version: "{{ 'master' if matrix_appservice_slack_version == 'latest' else matrix_appservice_slack_version }}" matrix_appservice_slack_docker_src_files_path: "{{ matrix_base_data_path }}/appservice-slack/docker-src" -matrix_appservice_slack_version: release-1.10.0 -matrix_appservice_slack_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-slack:{{ matrix_appservice_slack_version }}" +# matrix_appservice_slack_version used to contain the full Docker image tag (e.g. `release-X.X.X`). +# It's a bare version number now. We try to somewhat retain compatibility below. +matrix_appservice_slack_version: 1.11.0 +matrix_appservice_slack_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-slack:{{ matrix_appservice_slack_docker_image_tag }}" +matrix_appservice_slack_docker_image_tag: "{{ 'latest' if matrix_appservice_slack_version == 'latest' else ('release-' + matrix_appservice_slack_version) }}" matrix_appservice_slack_docker_image_force_pull: "{{ matrix_appservice_slack_docker_image.endswith(':latest') }}" matrix_appservice_slack_base_path: "{{ matrix_base_data_path }}/appservice-slack" @@ -63,12 +67,13 @@ matrix_appservice_slack_database_name: matrix_appservice_slack matrix_appservice_slack_database_connection_string: 'postgresql://{{ matrix_appservice_slack_database_username }}:{{ matrix_appservice_slack_database_password }}@{{ matrix_appservice_slack_database_hostname }}:{{ matrix_appservice_slack_database_port }}/{{ matrix_appservice_slack_database_name }}?sslmode=disable' # This is what actually goes into `database.connectionString` for the bridge. -matrix_appservice_slack_database_connectionString: "{{ - { - 'nedb': 'nedb:///data', - 'postgres': matrix_appservice_slack_database_connection_string, - }[matrix_appservice_slack_database_engine] -}}" +matrix_appservice_slack_database_connectionString: |- # noqa var-naming + {{ + { + 'nedb': 'nedb:///data', + 'postgres': matrix_appservice_slack_database_connection_string, + }[matrix_appservice_slack_database_engine] + }} matrix_appservice_slack_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" @@ -95,9 +100,9 @@ matrix_appservice_slack_configuration_extension_yaml: | # - "./debug.log": "info" #- "./error.log": "error" -matrix_appservice_slack_configuration_extension: "{{ matrix_appservice_slack_configuration_extension_yaml|from_yaml if matrix_appservice_slack_configuration_extension_yaml|from_yaml else {} }}" +matrix_appservice_slack_configuration_extension: "{{ matrix_appservice_slack_configuration_extension_yaml | from_yaml if matrix_appservice_slack_configuration_extension_yaml | from_yaml else {} }}" -matrix_appservice_slack_configuration: "{{ matrix_appservice_slack_configuration_yaml|from_yaml|combine(matrix_appservice_slack_configuration_extension, recursive=True) }}" +matrix_appservice_slack_configuration: "{{ matrix_appservice_slack_configuration_yaml | from_yaml | combine(matrix_appservice_slack_configuration_extension, recursive=True) }}" matrix_appservice_slack_registration_yaml: | id: "{{ matrix_appservice_slack_id_token }}" @@ -111,9 +116,9 @@ matrix_appservice_slack_registration_yaml: | - exclusive: false regex: '#{{ matrix_appservice_slack_user_prefix }}.*' rooms: [] - url: "{{matrix_appservice_slack_appservice_url}}:{{ matrix_appservice_slack_matrix_port }}" + url: "{{ matrix_appservice_slack_appservice_url }}:{{ matrix_appservice_slack_matrix_port }}" sender_localpart: slackbot rate_limited: true protocols: null -matrix_appservice_slack_registration: "{{ matrix_appservice_slack_registration_yaml|from_yaml }}" +matrix_appservice_slack_registration: "{{ matrix_appservice_slack_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-slack/tasks/init.yml b/roles/matrix-bridge-appservice-slack/tasks/init.yml index 8cbc7182..e11125ed 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/init.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/init.yml @@ -2,58 +2,62 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the matrix-appservice-slack image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_appservice_slack_container_image_self_build and matrix_appservice_slack_enabled" # 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-appservice-slack role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-slack.service'] }}" - when: matrix_appservice_slack_enabled|bool + when: matrix_appservice_slack_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([]) }} - + - ["--mount type=bind,src={{ matrix_appservice_slack_config_path }}/slack-registration.yaml,dst=/matrix-appservice-slack-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_appservice_slack_config_path }}/slack-registration.yaml,dst=/matrix-appservice-slack-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-appservice-slack-registration.yaml"] }} - when: matrix_appservice_slack_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-appservice-slack-registration.yaml"] + }} + when: matrix_appservice_slack_enabled | bool # 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-appservice-slack role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Slack Appservice's 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-appservice-slack role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix Appservice Slack proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_appservice_slack_matrix_nginx_proxy_configuration: | location {{ matrix_appservice_slack_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_appservice_slack_appservice_url }}:{{ matrix_appservice_slack_slack_port }}"; @@ -65,23 +69,23 @@ } - name: Register Slack Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_appservice_slack_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_appservice_slack_enabled|bool + when: matrix_appservice_slack_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix Slack bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ something }}` URL endpoint to the matrix-appservice-slack container. You can expose the container's port using the `matrix_appservice_slack_container_http_host_bind_port` variable. - when: "matrix_appservice_slack_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_appservice_slack_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-appservice-slack/tasks/main.yml b/roles/matrix-bridge-appservice-slack/tasks/main.yml index 06c3abb6..cd83f61f 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/main.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_slack_enabled | bool" tags: - setup-all - setup-appservice-slack -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_slack_enabled | bool" tags: - setup-all - setup-appservice-slack -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_slack_enabled | bool" tags: - setup-all - setup-appservice-slack diff --git a/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml b/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml index 0bea65bc..b9aca080 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml @@ -1,40 +1,40 @@ --- - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Ensure matrix-appservice-slack is stopped - service: + ansible.builtin.service: name: matrix-appservice-slack state: stopped - name: Import appservice-slack NeDB database into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -46,10 +46,14 @@ {{ matrix_appservice_slack_docker_image }} -c '/usr/local/bin/node /usr/src/app/lib/scripts/migrateToPostgres.js --dbdir /data --connectionString {{ matrix_appservice_slack_database_connection_string }}' + register: matrix_appservice_slack_import_nedb_to_postgres_result + changed_when: matrix_appservice_slack_import_nedb_to_postgres_result.rc == 0 - name: Archive NeDB database files - command: + ansible.builtin.command: cmd: "mv {{ matrix_appservice_slack_data_path }}/{{ item }} {{ matrix_appservice_slack_data_path }}/{{ item }}.backup" + register: matrix_appservice_slack_import_nedb_to_postgres_move_result + changed_when: matrix_appservice_slack_import_nedb_to_postgres_move_result.rc == 0 with_items: - teams.db - room-store.db @@ -57,10 +61,10 @@ - event-store.db - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your appservice-slack database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_slack_data_path }}/*.db` to `{{ matrix_appservice_slack_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files." diff --git a/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml b/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml index 42aa020c..a2921d98 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure AppService Slack paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -12,23 +12,23 @@ - {path: "{{ matrix_appservice_slack_config_path }}", when: true} - {path: "{{ matrix_appservice_slack_data_path }}", when: true} - {path: "{{ matrix_appservice_slack_docker_src_files_path }}", when: "{{ matrix_appservice_slack_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool -- set_fact: +- ansible.builtin.set_fact: matrix_appservice_slack_requires_restart: false - block: - name: Check if a nedb database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_slack_data_path }}/teams.db" register: matrix_appservice_slack_nedb_database_path_local_stat_result - block: - - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" + - ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" - - set_fact: + - ansible.builtin.set_fact: matrix_appservice_slack_requires_restart: true - when: "matrix_appservice_slack_nedb_database_path_local_stat_result.stat.exists|bool" + when: "matrix_appservice_slack_nedb_database_path_local_stat_result.stat.exists | bool" when: "matrix_appservice_slack_database_engine == 'postgres'" - name: Ensure Appservice Slack image is pulled @@ -37,21 +37,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_appservice_slack_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_appservice_slack_docker_image_force_pull }}" - when: "not matrix_appservice_slack_container_image_self_build|bool" + when: "not matrix_appservice_slack_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-appservice-slack repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_appservice_slack_docker_repo }}" + version: "{{ matrix_appservice_slack_docker_repo_version }}" dest: "{{ matrix_appservice_slack_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_appservice_slack_git_pull_results - when: "matrix_appservice_slack_container_image_self_build|bool" + when: "matrix_appservice_slack_container_image_self_build | bool" - name: Ensure matrix-appservice-slack Docker image is built docker_image: @@ -63,38 +64,38 @@ dockerfile: Dockerfile path: "{{ matrix_appservice_slack_docker_src_files_path }}" pull: true - when: "matrix_appservice_slack_container_image_self_build|bool and matrix_appservice_slack_git_pull_results.changed" + when: "matrix_appservice_slack_container_image_self_build | bool and matrix_appservice_slack_git_pull_results.changed" - name: Ensure Matrix Appservice Slack config installed - copy: - content: "{{ matrix_appservice_slack_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_slack_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_slack_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure appservice-slack registration.yaml installed - copy: - content: "{{ matrix_appservice_slack_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_slack_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_slack_config_path }}/slack-registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-appservice-slack.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-slack.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-slack.service" mode: 0644 register: matrix_appservice_slack_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-slack.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_slack_systemd_service_result.changed" - name: Ensure matrix-appservice-slack.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-appservice-slack.service" state: restarted - when: "matrix_appservice_slack_requires_restart|bool" + when: "matrix_appservice_slack_requires_restart | bool" diff --git a/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml index dffe78b3..fa1aaf26 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-slack service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-slack.service" register: matrix_appservice_slack_service_stat - name: Ensure matrix-appservice-slack is stopped - service: + ansible.builtin.service: name: matrix-appservice-slack state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_slack_service_stat.stat.exists" - name: Ensure matrix-appservice-slack.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-slack.service" state: absent when: "matrix_appservice_slack_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-slack.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_slack_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml b/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml index 1866c312..e00eb6d4 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_appservice_slack_id_token" - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). diff --git a/roles/matrix-bridge-appservice-slack/templates/config.yaml.j2 b/roles/matrix-bridge-appservice-slack/templates/config.yaml.j2 index 96e68967..911dd75e 100644 --- a/roles/matrix-bridge-appservice-slack/templates/config.yaml.j2 +++ b/roles/matrix-bridge-appservice-slack/templates/config.yaml.j2 @@ -9,6 +9,21 @@ homeserver: url: "{{ matrix_appservice_slack_homeserver_url }}" media_url: "{{ matrix_appservice_slack_homeserver_media_url }}" +# Real Time Messaging API (RTM) +# Optional if slack_hook_port and inbound_uri_prefix are defined, required otherwise. +# +rtm: + # Use the RTM API to listen for requests, which does not require + # the bridge to listen on the hook port. + # You should leave this enabled, unless you plan to use the + # bridge exclusively for webhooks. + # + enable: true + + # Logging level specific to RTM traffic. + # + log_level: "silent" + {% if matrix_appservice_slack_database_engine == 'nedb' %} dbdir: "/data" {% else %} diff --git a/roles/matrix-bridge-appservice-webhooks/defaults/main.yml b/roles/matrix-bridge-appservice-webhooks/defaults/main.yml index 223b9c0b..f181f095 100644 --- a/roles/matrix-bridge-appservice-webhooks/defaults/main.yml +++ b/roles/matrix-bridge-appservice-webhooks/defaults/main.yml @@ -1,6 +1,6 @@ --- # matrix-appservice-webhooks is a Matrix <-> webhook bridge -# See: https://github.com/redoonetworks/matrix-appservice-webhooks +# Project source code URL: https://github.com/redoonetworks/matrix-appservice-webhooks matrix_appservice_webhooks_enabled: true @@ -61,9 +61,9 @@ matrix_appservice_webhooks_configuration_yaml: "{{ lookup('template', 'templates matrix_appservice_webhooks_configuration_extension_yaml: | # -matrix_appservice_webhooks_configuration_extension: "{{ matrix_appservice_webhooks_configuration_extension_yaml|from_yaml if matrix_appservice_webhooks_configuration_extension_yaml|from_yaml else {} }}" +matrix_appservice_webhooks_configuration_extension: "{{ matrix_appservice_webhooks_configuration_extension_yaml | from_yaml if matrix_appservice_webhooks_configuration_extension_yaml | from_yaml else {} }}" -matrix_appservice_webhooks_configuration: "{{ matrix_appservice_webhooks_configuration_yaml|from_yaml|combine(matrix_appservice_webhooks_configuration_extension, recursive=True) }}" +matrix_appservice_webhooks_configuration: "{{ matrix_appservice_webhooks_configuration_yaml | from_yaml | combine(matrix_appservice_webhooks_configuration_extension, recursive=True) }}" matrix_appservice_webhooks_registration_yaml: | id: "{{ matrix_appservice_webhooks_id_token }}" @@ -80,4 +80,4 @@ matrix_appservice_webhooks_registration_yaml: | rate_limited: false protocols: null -matrix_appservice_webhooks_registration: "{{ matrix_appservice_webhooks_registration_yaml|from_yaml }}" +matrix_appservice_webhooks_registration: "{{ matrix_appservice_webhooks_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/init.yml b/roles/matrix-bridge-appservice-webhooks/tasks/init.yml index b888c51f..8a12a686 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/init.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/init.yml @@ -2,50 +2,54 @@ # 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-appservice-webhooks role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-webhooks.service'] }}" - when: matrix_appservice_webhooks_enabled|bool + when: matrix_appservice_webhooks_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([]) }} - + - ["--mount type=bind,src={{ matrix_appservice_webhooks_config_path }}/webhooks-registration.yaml,dst=/matrix-appservice-webhooks-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_appservice_webhooks_config_path }}/webhooks-registration.yaml,dst=/matrix-appservice-webhooks-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-appservice-webhooks-registration.yaml"] }} - when: matrix_appservice_webhooks_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-appservice-webhooks-registration.yaml"] + }} + when: matrix_appservice_webhooks_enabled | bool # 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-appservice-webhooks role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append webhooks Appservice's 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-appservice-webhooks role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix Appservice webhooks proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_appservice_webhooks_matrix_nginx_proxy_configuration: | - {% if matrix_nginx_proxy_enabled|default(False) %} + {% if matrix_nginx_proxy_enabled | default(False) %} {# Use the embedded DNS resolver in Docker containers to discover the service #} location ~ ^{{ matrix_appservice_webhooks_public_endpoint }}/(.*)$ { resolver 127.0.0.11 valid=5s; @@ -60,23 +64,23 @@ {% endif %} - name: Register webhooks Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_appservice_webhooks_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_appservice_webhooks_enabled|bool + when: matrix_appservice_webhooks_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix webhooks bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_appservice_webhooks_public_endpoint }}` URL endpoint to the matrix-appservice-webhooks container. You can expose the container's port using the `matrix_appservice_webhooks_container_http_host_bind_port` variable. - when: "matrix_appservice_webhooks_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_appservice_webhooks_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/main.yml b/roles/matrix-bridge-appservice-webhooks/tasks/main.yml index 26a7e24c..30f05469 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/main.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_webhooks_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_webhooks_enabled | bool" tags: - setup-all - setup-appservice-webhooks -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_webhooks_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_webhooks_enabled | bool" tags: - setup-all - setup-appservice-webhooks -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_webhooks_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_webhooks_enabled | bool" tags: - setup-all - setup-appservice-webhooks diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml b/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml index 274f54c5..603f9d1d 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure AppService webhooks paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -12,7 +12,7 @@ - {path: "{{ matrix_appservice_webhooks_config_path }}", when: true} - {path: "{{ matrix_appservice_webhooks_data_path }}", when: true} - {path: "{{ matrix_appservice_webhooks_docker_src_files_path }}", when: "{{ matrix_appservice_webhooks_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Appservice webhooks image is pulled docker_image: @@ -20,7 +20,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_appservice_webhooks_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_appservice_webhooks_docker_image_force_pull }}" - when: "not matrix_appservice_webhooks_container_image_self_build|bool" + when: "not matrix_appservice_webhooks_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -28,7 +28,7 @@ - block: - name: Ensure Appservice webhooks repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_appservice_webhooks_container_image_self_build_repo }}" dest: "{{ matrix_appservice_webhooks_docker_src_files_path }}" version: "{{ matrix_appservice_webhooks_container_image_self_build_repo_version }}" @@ -47,18 +47,18 @@ dockerfile: "{{ matrix_appservice_webhooks_container_image_self_build_repo_dockerfile_path }}" path: "{{ matrix_appservice_webhooks_docker_src_files_path }}" pull: true - when: "matrix_appservice_webhooks_container_image_self_build|bool" + when: "matrix_appservice_webhooks_container_image_self_build | bool" - name: Ensure Matrix Appservice webhooks config is installed - copy: - content: "{{ matrix_appservice_webhooks_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_webhooks_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_webhooks_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Matrix Appservice webhooks schema.yml template exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/schema.yml.j2" dest: "{{ matrix_appservice_webhooks_config_path }}/schema.yml" mode: 0644 @@ -66,7 +66,7 @@ group: "{{ matrix_user_groupname }}" - name: Ensure Matrix Appservice webhooks database.json template exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/database.json.j2" dest: "{{ matrix_appservice_webhooks_data_path }}/database.json" mode: 0644 @@ -74,21 +74,21 @@ group: "{{ matrix_user_groupname }}" - name: Ensure appservice-webhooks registration.yaml installed - copy: - content: "{{ matrix_appservice_webhooks_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_webhooks_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_webhooks_config_path }}/webhooks-registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-appservice-webhooks.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-webhooks.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-webhooks.service" mode: 0644 register: matrix_appservice_webhooks_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-webhooks.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_webhooks_systemd_service_result.changed" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml index 38235652..2b3c29d5 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-webhooks service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-webhooks.service" register: matrix_appservice_webhooks_service_stat - name: Ensure matrix-appservice-webhooks is stopped - service: + ansible.builtin.service: name: matrix-appservice-webhooks state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_webhooks_service_stat.stat.exists" - name: Ensure matrix-appservice-webhooks.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-webhooks.service" state: absent when: "matrix_appservice_webhooks_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-webhooks.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_webhooks_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml b/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml index 48f63e68..d7f45c6f 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-beeper-linkedin/defaults/main.yml b/roles/matrix-bridge-beeper-linkedin/defaults/main.yml index e622522d..fc2cc898 100644 --- a/roles/matrix-bridge-beeper-linkedin/defaults/main.yml +++ b/roles/matrix-bridge-beeper-linkedin/defaults/main.yml @@ -1,6 +1,6 @@ --- # beeper-linkedin is a Matrix <-> LinkedIn bridge -# See: https://gitlab.com/beeper/linkedin +# Project source code URL: https://gitlab.com/beeper/linkedin matrix_beeper_linkedin_enabled: true @@ -25,6 +25,16 @@ matrix_beeper_linkedin_homeserver_address: "{{ matrix_homeserver_container_url } matrix_beeper_linkedin_homeserver_domain: "{{ matrix_domain }}" matrix_beeper_linkedin_appservice_address: "http://matrix-beeper-linkedin:29319" +matrix_beeper_linkedin_bridge_presence: true + +matrix_beeper_linkedin_command_prefix: "!li" + +matrix_beeper_linkedin_bridge_permissions: | + {{ + {matrix_beeper_linkedin_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # A list of extra arguments to pass to the container matrix_beeper_linkedin_container_extra_arguments: [] @@ -68,6 +78,9 @@ matrix_beeper_linkedin_appservice_database_uri: "{{ # Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). matrix_beeper_linkedin_login_shared_secret: '' +# Specifies the default log level for all bridge loggers. +matrix_beeper_linkedin_logging_level: WARNING + # Default beeper-linkedin configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -84,11 +97,11 @@ matrix_beeper_linkedin_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_beeper_linkedin_configuration_yaml`. -matrix_beeper_linkedin_configuration_extension: "{{ matrix_beeper_linkedin_configuration_extension_yaml|from_yaml if matrix_beeper_linkedin_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_beeper_linkedin_configuration_extension: "{{ matrix_beeper_linkedin_configuration_extension_yaml | from_yaml if matrix_beeper_linkedin_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_beeper_linkedin_configuration_yaml`. -matrix_beeper_linkedin_configuration: "{{ matrix_beeper_linkedin_configuration_yaml|from_yaml|combine(matrix_beeper_linkedin_configuration_extension, recursive=True) }}" +matrix_beeper_linkedin_configuration: "{{ matrix_beeper_linkedin_configuration_yaml | from_yaml | combine(matrix_beeper_linkedin_configuration_extension, recursive=True) }}" matrix_beeper_linkedin_registration_yaml: | id: linkedin @@ -100,10 +113,10 @@ matrix_beeper_linkedin_registration_yaml: | rate_limited: false namespaces: users: - - regex: '^@linkedin_.+:{{ matrix_beeper_linkedin_homeserver_domain|regex_escape }}$' + - regex: '^@linkedin_.+:{{ matrix_beeper_linkedin_homeserver_domain | regex_escape }}$' exclusive: true - exclusive: true - regex: '^@{{ matrix_beeper_linkedin_appservice_bot_username|regex_escape }}:{{ matrix_beeper_linkedin_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_beeper_linkedin_appservice_bot_username | regex_escape }}:{{ matrix_beeper_linkedin_homeserver_domain | regex_escape }}$' de.sorunome.msc2409.push_ephemeral: true -matrix_beeper_linkedin_registration: "{{ matrix_beeper_linkedin_registration_yaml|from_yaml }}" +matrix_beeper_linkedin_registration: "{{ matrix_beeper_linkedin_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/init.yml b/roles/matrix-bridge-beeper-linkedin/tasks/init.yml index 977db925..14137b70 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/init.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/init.yml @@ -1,18 +1,22 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-beeper-linkedin.service'] }}" - when: matrix_beeper_linkedin_enabled|bool + when: matrix_beeper_linkedin_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([]) }} - + - ["--mount type=bind,src={{ matrix_beeper_linkedin_config_path }}/registration.yaml,dst=/matrix-beeper-linkedin-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_beeper_linkedin_config_path }}/registration.yaml,dst=/matrix-beeper-linkedin-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-beeper-linkedin-registration.yaml"] }} - when: matrix_beeper_linkedin_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-beeper-linkedin-registration.yaml"] + }} + when: matrix_beeper_linkedin_enabled | bool diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/main.yml b/roles/matrix-bridge-beeper-linkedin/tasks/main.yml index 920265fb..8f295d2c 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/main.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/main.yml @@ -1,22 +1,22 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_beeper_linkedin_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_beeper_linkedin_enabled | bool" tags: - setup-all - setup-beeper-linkedin -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" when: "run_setup and matrix_beeper_linkedin_enabled" tags: - setup-all - setup-beeper-linkedin -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" when: "run_setup and not matrix_beeper_linkedin_enabled" tags: - setup-all diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml b/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml index 74f80314..9df4d75b 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml @@ -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-beeper-linkedin role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure Beeper LinkedIn paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -19,7 +19,7 @@ - {path: "{{ matrix_beeper_linkedin_config_path }}", when: true} - {path: "{{ matrix_beeper_linkedin_data_path }}", when: true} - {path: "{{ matrix_beeper_linkedin_docker_src_files_path }}", when: "{{ matrix_beeper_linkedin_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Beeper LinkedIn image is pulled @@ -28,7 +28,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_beeper_linkedin_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_beeper_linkedin_docker_image_force_pull }}" - when: "not matrix_beeper_linkedin_container_image_self_build|bool" + when: "not matrix_beeper_linkedin_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -36,7 +36,7 @@ - block: - name: Ensure Beeper LinkedIn repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_beeper_linkedin_container_image_self_build_repo }}" dest: "{{ matrix_beeper_linkedin_docker_src_files_path }}" version: "{{ matrix_beeper_linkedin_container_image_self_build_branch }}" @@ -48,14 +48,17 @@ # Building the container image (using the default Dockerfile) requires that a docker-requirements.txt file be generated. # See: https://gitlab.com/beeper/linkedin/-/blob/94442db17ccb9769b377cdb8e4bf1cb3955781d7/.gitlab-ci.yml#L30-40 - name: Ensure docker-requirements.txt is generated before building Beeper LinkedIn Docker Image - command: | - {{ matrix_host_command_docker }} run \ - --rm \ - --entrypoint=/bin/sh \ - --mount type=bind,src={{ matrix_beeper_linkedin_docker_src_files_path }},dst=/work \ - -w /work \ - docker.io/python:3.9.6-buster \ - -c "pip install poetry && poetry export --without-hashes -E e2be -E images -E metrics | sed 's/==.*//g' > docker-requirements.txt" + ansible.builtin.command: + cmd: | + {{ matrix_host_command_docker }} run + --rm + --entrypoint=/bin/sh + --mount type=bind,src={{ matrix_beeper_linkedin_docker_src_files_path }},dst=/work + -w /work + docker.io/python:3.9.6-buster + -c "pip install poetry && poetry export --without-hashes -E e2be -E images -E metrics | sed 's/==.*//g' > docker-requirements.txt" + register: matrix_beeper_linkedin_generate_docker_requirements_result + changed_when: matrix_beeper_linkedin_generate_docker_requirements_result.rc == 0 - name: Ensure Beeper LinkedIn Docker image is built docker_image: @@ -69,32 +72,32 @@ pull: true args: TARGETARCH: "{{ matrix_architecture }}" - when: "matrix_beeper_linkedin_container_image_self_build|bool" + when: "matrix_beeper_linkedin_container_image_self_build | bool" - name: Ensure beeper-linkedin config.yaml installed - copy: - content: "{{ matrix_beeper_linkedin_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_beeper_linkedin_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_beeper_linkedin_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure beeper-linkedin registration.yaml installed - copy: - content: "{{ matrix_beeper_linkedin_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_beeper_linkedin_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_beeper_linkedin_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-beeper-linkedin.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-beeper-linkedin.service.j2" dest: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service" mode: 0644 register: matrix_beeper_linkedin_systemd_service_result - name: Ensure systemd reloaded after matrix-beeper-linkedin.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_beeper_linkedin_systemd_service_result.changed" diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml b/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml index befa2f61..25dbf82b 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-beeper-linkedin service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service" register: matrix_beeper_linkedin_service_stat - name: Ensure matrix-beeper-linkedin is stopped - service: + ansible.builtin.service: name: matrix-beeper-linkedin state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_beeper_linkedin_service_stat.stat.exists" - name: Ensure matrix-beeper-linkedin.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service" state: absent when: "matrix_beeper_linkedin_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-beeper-linkedin.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_beeper_linkedin_service_stat.stat.exists" diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml b/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml index d808de08..61489b7c 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-beeper-linkedin/templates/config.yaml.j2 b/roles/matrix-bridge-beeper-linkedin/templates/config.yaml.j2 index 4fb6b055..a30f2425 100644 --- a/roles/matrix-bridge-beeper-linkedin/templates/config.yaml.j2 +++ b/roles/matrix-bridge-beeper-linkedin/templates/config.yaml.j2 @@ -56,7 +56,7 @@ appservice: # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty # to leave display name/avatar as-is. displayname: LinkedIn bridge bot - avatar: mxc://sumnerevans.com/XMtwdeUBnxYvWNFFrfeTSHqB + avatar: mxc://sumnerevans.com/XMtwdeUBnxYvWNFFrfeTSHqB # Whether or not to receive ephemeral events via appservice transactions. # Requires MSC2409 support (i.e. Synapse 1.22+). @@ -226,7 +226,7 @@ bridge: # The prefix for commands. Only required in non-management rooms. - command_prefix: "!li" + command_prefix: "{{ matrix_beeper_linkedin_command_prefix }}" # Permissions for using the bridge. # Permitted values: @@ -236,8 +236,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - "{{ matrix_beeper_linkedin_homeserver_domain }}": user + permissions: {{ matrix_beeper_linkedin_bridge_permissions|to_json }} @@ -256,12 +255,12 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: {{ matrix_beeper_linkedin_logging_level|to_json }} paho: - level: INFO + level: {{ matrix_beeper_linkedin_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_beeper_linkedin_logging_level|to_json }} root: - level: DEBUG - handlers: [ console] + level: {{ matrix_beeper_linkedin_logging_level|to_json }} + handlers: [console] diff --git a/roles/matrix-bridge-go-skype-bridge/defaults/main.yml b/roles/matrix-bridge-go-skype-bridge/defaults/main.yml new file mode 100644 index 00000000..a6f7aa9d --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/defaults/main.yml @@ -0,0 +1,140 @@ +--- +# Go Skype Bridge is a Matrix <-> Skype bridge +# Project source code URL: https://github.com/kelaresg/go-skype-bridge + +matrix_go_skype_bridge_enabled: true + +matrix_go_skype_bridge_container_image_self_build: false +matrix_go_skype_bridge_container_image_self_build_repo: "https://github.com/kelaresg/go-skype-bridge.git" +matrix_go_skype_bridge_container_image_self_build_branch: "{{ 'master' if matrix_go_skype_bridge_version == 'latest' else matrix_go_skype_bridge_version }}" + +matrix_go_skype_bridge_version: latest +matrix_go_skype_bridge_docker_image: "{{ matrix_go_skype_bridge_docker_image_name_prefix }}nodefyme/go-skype-bridge:{{ matrix_go_skype_bridge_version }}" +matrix_go_skype_bridge_docker_image_name_prefix: "{{ 'localhost/' if matrix_go_skype_bridge_container_image_self_build else matrix_container_global_registry_prefix }}" +matrix_go_skype_bridge_docker_image_force_pull: "{{ matrix_go_skype_bridge_docker_image.endswith(':latest') }}" + +matrix_go_skype_bridge_base_path: "{{ matrix_base_data_path }}/go-skype-bridge" +matrix_go_skype_bridge_config_path: "{{ matrix_go_skype_bridge_base_path }}/config" +matrix_go_skype_bridge_data_path: "{{ matrix_go_skype_bridge_base_path }}/data" +matrix_go_skype_bridge_docker_src_files_path: "{{ matrix_go_skype_bridge_base_path }}/docker-src" + +matrix_go_skype_bridge_homeserver_address: "{{ matrix_homeserver_container_url }}" +matrix_go_skype_bridge_homeserver_domain: "{{ matrix_domain }}" +matrix_go_skype_bridge_appservice_address: 'http://matrix-go-skype-bridge:8080' + +# A list of extra arguments to pass to the container +matrix_go_skype_bridge_container_extra_arguments: [] + +# List of systemd services that matrix-go-skype-bridge.service depends on. +matrix_go_skype_bridge_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-go-skype-bridge.service wants +matrix_go_skype_bridge_systemd_wanted_services_list: [] + +matrix_go_skype_bridge_appservice_token: '' +matrix_go_skype_bridge_homeserver_token: '' + +matrix_go_skype_bridge_appservice_bot_username: skypebridgebot + +matrix_go_skype_bridge_command_prefix: "!skype" + +# Whether or not created rooms should have federation enabled. +# If false, created portal rooms will never be federated. +matrix_go_skype_bridge_federate_rooms: true + +# Database-related configuration fields. +# +# To use SQLite, stick to these defaults. +# +# To use Postgres: +# - change the engine (`matrix_go_skype_bridge_database_engine: 'postgres'`) +# - adjust your database credentials via the `matrix_go_skype_bridge_database_*` variables +matrix_go_skype_bridge_database_engine: 'sqlite' + +matrix_go_skype_bridge_sqlite_database_path_local: "{{ matrix_go_skype_bridge_data_path }}/go-skype-bridge.db" +matrix_go_skype_bridge_sqlite_database_path_in_container: "/data/go-skype-bridge.db" + +matrix_go_skype_bridge_database_username: 'matrix_go_skype_bridge' +matrix_go_skype_bridge_database_password: 'some-password' +matrix_go_skype_bridge_database_hostname: 'matrix-postgres' +matrix_go_skype_bridge_database_port: 5432 +matrix_go_skype_bridge_database_name: 'matrix_go_skype_bridge' + +matrix_go_skype_bridge_database_connection_string: 'postgresql://{{ matrix_go_skype_bridge_database_username }}:{{ matrix_go_skype_bridge_database_password }}@{{ matrix_go_skype_bridge_database_hostname }}:{{ matrix_go_skype_bridge_database_port }}/{{ matrix_go_skype_bridge_database_name }}?sslmode=disable' + +matrix_go_skype_bridge_appservice_database_type: "{{ + { + 'sqlite': 'sqlite3', + 'postgres':'postgres', + }[matrix_go_skype_bridge_database_engine] +}}" + +matrix_go_skype_bridge_appservice_database_uri: "{{ + { + 'sqlite': matrix_go_skype_bridge_sqlite_database_path_in_container, + 'postgres': matrix_go_skype_bridge_database_connection_string, + }[matrix_go_skype_bridge_database_engine] +}}" + +# Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). +matrix_go_skype_bridge_login_shared_secret: '' +matrix_go_skype_bridge_bridge_login_shared_secret_map: + "{{ {matrix_go_skype_bridge_homeserver_domain: matrix_go_skype_bridge_login_shared_secret} if matrix_go_skype_bridge_login_shared_secret else {} }}" + +# Servers to always allow double puppeting from +matrix_go_skype_bridge_bridge_double_puppet_server_map: + "{{ matrix_go_skype_bridge_homeserver_domain : matrix_go_skype_bridge_homeserver_address }}" + +# Enable End-to-bridge encryption +matrix_go_skype_bridge_bridge_encryption_allow: false +matrix_go_skype_bridge_bridge_encryption_default: "{{ matrix_go_skype_bridge_bridge_encryption_allow }}" + +# Minimum severity of journal log messages. +# Options: debug, info, warn, error, fatal +matrix_go_skype_bridge_log_level: 'warn' + +matrix_go_skype_bridge_bridge_permissions: | + {{ + {matrix_go_skype_bridge_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + +# Default go-skype-bridge configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_go_skype_bridge_configuration_extension_yaml`) +# or completely replace this variable with your own template. +matrix_go_skype_bridge_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" + +matrix_go_skype_bridge_configuration_extension_yaml: | + # Your custom YAML configuration goes here. + # This configuration extends the default starting configuration (`matrix_go_skype_bridge_configuration_yaml`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_go_skype_bridge_configuration_yaml`. + +matrix_go_skype_bridge_configuration_extension: "{{ matrix_go_skype_bridge_configuration_extension_yaml | from_yaml if matrix_go_skype_bridge_configuration_extension_yaml | from_yaml is mapping else {} }}" + +# Holds the final configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_go_skype_bridge_configuration_yaml`. +matrix_go_skype_bridge_configuration: "{{ matrix_go_skype_bridge_configuration_yaml | from_yaml | combine(matrix_go_skype_bridge_configuration_extension, recursive=True) }}" + +matrix_go_skype_bridge_registration_yaml: | + id: skype + url: {{ matrix_go_skype_bridge_appservice_address }} + as_token: "{{ matrix_go_skype_bridge_appservice_token }}" + hs_token: "{{ matrix_go_skype_bridge_homeserver_token }}" + # See https://github.com/mautrix/signal/issues/43 + sender_localpart: _bot_{{ matrix_go_skype_bridge_appservice_bot_username }} + rate_limited: false + namespaces: + users: + - regex: '^@skype-(.*):{{ matrix_go_skype_bridge_homeserver_domain | regex_escape }}$' + exclusive: true + - exclusive: true + regex: '^@{{ matrix_go_skype_bridge_appservice_bot_username | regex_escape }}:{{ matrix_go_skype_bridge_homeserver_domain | regex_escape }}$' + de.sorunome.msc2409.push_ephemeral: true + +matrix_go_skype_bridge_registration: "{{ matrix_go_skype_bridge_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/init.yml b/roles/matrix-bridge-go-skype-bridge/tasks/init.yml new file mode 100644 index 00000000..9b826556 --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/tasks/init.yml @@ -0,0 +1,21 @@ +--- +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-go-skype-bridge.service'] }}" + when: matrix_go_skype_bridge_enabled | bool + +# If the matrix-synapse role is not used, these variables may not exist. +- ansible.builtin.set_fact: + matrix_synapse_container_extra_arguments: > + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_go_skype_bridge_config_path }}/registration.yaml,dst=/matrix-go-skype-bridge-registration.yaml,ro"] + }} + + matrix_synapse_app_service_config_files: > + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-go-skype-bridge-registration.yaml"] + }} + when: matrix_go_skype_bridge_enabled | bool diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/main.yml b/roles/matrix-bridge-go-skype-bridge/tasks/main.yml new file mode 100644 index 00000000..39f4b2e5 --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/tasks/main.yml @@ -0,0 +1,23 @@ +--- + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_go_skype_bridge_enabled | bool" + tags: + - setup-all + - setup-go-skype-bridge + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_go_skype_bridge_enabled | bool" + tags: + - setup-all + - setup-go-skype-bridge + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_go_skype_bridge_enabled | bool" + tags: + - setup-all + - setup-go-skype-bridge diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml b/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml new file mode 100644 index 00000000..7403ff5c --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml @@ -0,0 +1,149 @@ +--- + +# 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 + ansible.builtin.fail: + msg: >- + The matrix-bridge-go-skype-bridge role needs to execute before the matrix-synapse role. + when: "matrix_synapse_role_executed | default(False)" + +- ansible.builtin.set_fact: + matrix_go_skype_bridge_requires_restart: false + +- block: + - name: Check if an SQLite database already exists + ansible.builtin.stat: + path: "{{ matrix_go_skype_bridge_sqlite_database_path_local }}" + register: matrix_go_skype_bridge_sqlite_database_path_local_stat_result + + - block: + - ansible.builtin.set_fact: + matrix_postgres_db_migration_request: + src: "{{ matrix_go_skype_bridge_sqlite_database_path_local }}" + dst: "{{ matrix_go_skype_bridge_database_connection_string }}" + caller: "{{ role_path | basename }}" + engine_variable_name: 'matrix_go_skype_bridge_database_engine' + engine_old: 'sqlite' + systemd_services_to_stop: ['matrix-go-skype-bridge.service'] + pgloader_options: ['--with "quote identifiers"'] + + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres + + - ansible.builtin.set_fact: + matrix_go_skype_bridge_requires_restart: true + when: "matrix_go_skype_bridge_sqlite_database_path_local_stat_result.stat.exists | bool" + when: "matrix_go_skype_bridge_database_engine == 'postgres'" + + +- name: Ensure Go Skype Bridge paths exists + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_go_skype_bridge_base_path }}", when: true} + - {path: "{{ matrix_go_skype_bridge_config_path }}", when: true} + - {path: "{{ matrix_go_skype_bridge_data_path }}", when: true} + - {path: "{{ matrix_go_skype_bridge_docker_src_files_path }}", when: "{{ matrix_go_skype_bridge_container_image_self_build }}"} + when: item.when | bool + +- name: Ensure Go Skype Bridge image is pulled + docker_image: + name: "{{ matrix_go_skype_bridge_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_go_skype_bridge_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_go_skype_bridge_docker_image_force_pull }}" + when: not matrix_go_skype_bridge_container_image_self_build + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure Go Skype Bridge repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_go_skype_bridge_container_image_self_build_repo }}" + dest: "{{ matrix_go_skype_bridge_docker_src_files_path }}" + version: "{{ matrix_go_skype_bridge_container_image_self_build_branch }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_go_skype_bridge_git_pull_results + when: "matrix_go_skype_bridge_container_image_self_build | bool" + +- name: Ensure Go Skype Bridge Docker image is built + docker_image: + name: "{{ matrix_go_skype_bridge_docker_image }}" + source: build + force_source: "{{ matrix_go_skype_bridge_git_pull_results.changed 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_go_skype_bridge_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_go_skype_bridge_docker_src_files_path }}" + pull: true + when: "matrix_go_skype_bridge_container_image_self_build | bool" + +- name: Check if an old database file exists + ansible.builtin.stat: + path: "{{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db" + register: matrix_go_skype_bridge_stat_database + +- name: Check if an old matrix state file exists + ansible.builtin.stat: + path: "{{ matrix_go_skype_bridge_base_path }}/mx-state.json" + register: matrix_go_skype_bridge_stat_mx_state + +- name: (Data relocation) Ensure matrix-go-skype-bridge.service is stopped + ansible.builtin.service: + name: matrix-go-skype-bridge + state: stopped + enabled: false + daemon_reload: true + failed_when: false + when: "matrix_go_skype_bridge_stat_database.stat.exists" + +- name: (Data relocation) Move go-skype-bridge database file to ./data directory + ansible.builtin.command: "mv {{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db {{ matrix_go_skype_bridge_data_path }}/go-skype-bridge.db" + when: "matrix_go_skype_bridge_stat_database.stat.exists" + +- name: (Data relocation) Move go-skype-bridge mx-state file to ./data directory + ansible.builtin.command: "mv {{ matrix_go_skype_bridge_base_path }}/mx-state.json {{ matrix_go_skype_bridge_data_path }}/mx-state.json" + when: "matrix_go_skype_bridge_stat_mx_state.stat.exists" + +- name: Ensure go-skype-bridge config.yaml installed + ansible.builtin.copy: + content: "{{ matrix_go_skype_bridge_configuration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_go_skype_bridge_config_path }}/config.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure go-skype-bridge registration.yaml installed + ansible.builtin.copy: + content: "{{ matrix_go_skype_bridge_registration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_go_skype_bridge_config_path }}/registration.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-go-skype-bridge.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-go-skype-bridge.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-go-skype-bridge.service" + mode: 0644 + register: matrix_go_skype_bridge_systemd_service_result + +- name: Ensure systemd reloaded after matrix-go-skype-bridge.service installation + ansible.builtin.service: + daemon_reload: true + when: "matrix_go_skype_bridge_systemd_service_result.changed" + +- name: Ensure matrix-go-skype-bridge.service restarted, if necessary + ansible.builtin.service: + name: "matrix-go-skype-bridge.service" + state: restarted + when: "matrix_go_skype_bridge_requires_restart | bool" diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml b/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml new file mode 100644 index 00000000..975b25ab --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml @@ -0,0 +1,25 @@ +--- + +- name: Check existence of matrix-go-skype-bridge service + ansible.builtin.stat: + path: "/etc/systemd/system/matrix-go-skype-bridge.service" + register: matrix_go_skype_bridge_service_stat + +- name: Ensure matrix-go-skype-bridge is stopped + ansible.builtin.service: + name: matrix-go-skype-bridge + state: stopped + enabled: false + daemon_reload: true + when: "matrix_go_skype_bridge_service_stat.stat.exists" + +- name: Ensure matrix-go-skype-bridge.service doesn't exist + ansible.builtin.file: + path: "/etc/systemd/system/matrix-go-skype-bridge.service" + state: absent + when: "matrix_go_skype_bridge_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-go-skype-bridge.service removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_go_skype_bridge_service_stat.stat.exists" diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml b/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml new file mode 100644 index 00000000..d681299f --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml @@ -0,0 +1,10 @@ +--- + +- name: Fail if required settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - "matrix_go_skype_bridge_appservice_token" + - "matrix_go_skype_bridge_homeserver_token" diff --git a/roles/matrix-bridge-go-skype-bridge/templates/config.yaml.j2 b/roles/matrix-bridge-go-skype-bridge/templates/config.yaml.j2 new file mode 100644 index 00000000..2a1dc6c1 --- /dev/null +++ b/roles/matrix-bridge-go-skype-bridge/templates/config.yaml.j2 @@ -0,0 +1,237 @@ +#jinja2: lstrip_blocks: "True" +# Homeserver details. +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: {{ matrix_go_skype_bridge_homeserver_address }} + # The domain of the homeserver (for MXIDs, etc). + domain: {{ matrix_go_skype_bridge_homeserver_domain }} + # If you don’t know what this is, no need to modify(for parse "mention user/reply message, etc") + server_name: matrix.to + +# Application service host/registration related details. +# Changing these values requires regeneration of the registration. +appservice: + # The address that the homeserver can use to connect to this appservice. + address: {{ matrix_go_skype_bridge_appservice_address }} + + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 + port: 8080 + + # Database config. + database: + # The database type. "sqlite3" and "postgres" are supported. + type: {{ matrix_go_skype_bridge_appservice_database_type|to_json }} + # The database URI. + # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string + # Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable + uri: {{ matrix_go_skype_bridge_appservice_database_uri|to_json }} + # Maximum number of connections. Mostly relevant for Postgres. + max_open_conns: 20 + max_idle_conns: 2 + + # Settings for provisioning API + provisioning: + # Prefix for the provisioning API paths. + prefix: /_matrix/provision/v1 + # Shared secret for authentication. If set to "disable", the provisioning API will be disabled. + shared_secret: disable + + # The unique ID of this appservice. + id: skype + # Appservice bot details. + bot: + # Username of the appservice bot. + username: skypebridgebot + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + displayname: Skype bridge bot + avatar: mxc://matrix.org/kGQUDQyPiwbRXPFkjoBrPyhC + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: "{{ matrix_go_skype_bridge_appservice_token }}" + hs_token: "{{ matrix_go_skype_bridge_homeserver_token }}" + +# Bridge config +bridge: + # Localpart template of MXIDs for Skype users. + # {{ '{{.}}' }} is replaced with the phone number of the Skype user. + username_template: {{ 'skype-{{.}}' }} + # Displayname template for Skype users. + # {{ '{{.Notify}}' }} - nickname set by the Skype user + # {{ '{{.Jid}}' }} - phone number (international format) + # The following variables are also available, but will cause problems on multi-user instances: + # {{ '{{.Name}}' }} - display name from contact list + # {{ '{{.Short}}' }} - short display name from contact list + # To use multiple if's, you need to use: {{ '{{else if .Name}}' }}, for example: + # "{{ '{{if .Notify}}' }}{{ '{{.Notify}}' }}{{ '{{else if .Name}}' }}{{ '{{.Name}}' }}{{ '{{else}}' }}{{ '{{.Jid}}' }}{{ '{{end}}' }} (WA)" + displayname_template: "{{ '{{if .DisplayName}}' }}{{ '{{.DisplayName}}' }}{{ '{{else}}' }}{{ '{{.PersonId}}' }}{{ '{{end}}' }} (Skype)" + # Localpart template for per-user room grouping community IDs. + # On startup, the bridge will try to create these communities, add all of the specific user's + # portals to the community, and invite the Matrix user to it. + # (Note that, by default, non-admins might not have your homeserver's permission to create + # communities.) + # {{ '{{.Localpart}}' }} is the MXID localpart and {{ '{{.Server}}' }} is the MXID server part of the user. + community_template: skype-{{ '{{.Localpart}}' }}={{ '{{.Server}}' }} + + # Skype connection timeout in seconds. + connection_timeout: 20 + # If Skype doesn't respond within connection_timeout, should the bridge try to fetch the message + # to see if it was actually bridged? Use this if you have problems with sends timing out but actually + # succeeding. + fetch_message_on_timeout: false + # Whether or not the bridge should send a read receipt from the bridge bot when a message has been + # sent to Skype. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will + # trigger a read receipt too. + delivery_receipts: false + # Number of times to regenerate QR code when logging in. + # The regenerated QR code is sent as an edit and essentially multiplies the login timeout (20 seconds) + login_qr_regen_count: 2 + # Maximum number of times to retry connecting on connection error. + max_connection_attempts: 3 + # Number of seconds to wait between connection attempts. + # Negative numbers are exponential backoff: -connection_retry_delay + 1 + 2^attempts + connection_retry_delay: -1 + # Whether or not the bridge should send a notice to the user's management room when it retries connecting. + # If false, it will only report when it stops retrying. + report_connection_retry: true + # Maximum number of seconds to wait for chats to be sent at startup. + # If this is too low and you have lots of chats, it could cause backfilling to fail. + chat_list_wait: 30 + # Maximum number of seconds to wait to sync portals before force unlocking message processing. + # If this is too low and you have lots of chats, it could cause backfilling to fail. + portal_sync_wait: 600 + + # Whether or not to send call start/end notices to Matrix. + call_notices: + start: true + end: true + + # Number of chats to sync for new users. + # Since some of the obtained conversations are not the conversations that the user needs to see, + # the actual number of conversations displayed on the matrix client will be slightly less than the set value + initial_chat_sync_count: 10 + # Number of old messages to fill when creating new portal rooms. + initial_history_fill_count: 20 + # Whether or not notifications should be turned off while filling initial history. + # Only applicable when using double puppeting. + initial_history_disable_notifications: false + # Maximum number of chats to sync when recovering from downtime. + # Set to -1 to sync all new chats during downtime. + recovery_chat_sync_limit: -1 + # Whether or not to sync history when recovering from downtime. + recovery_history_backfill: true + # Maximum number of seconds since last message in chat to skip + # syncing the chat in any case. This setting will take priority + # over both recovery_chat_sync_limit and initial_chat_sync_count. + # Default is 3 days = 259200 seconds + sync_max_chat_age: 259200 + + # sync contact, Non-martix-standard parameter, defaults to false + sync_contact: false + + # Whether or not to sync with custom puppets to receive EDUs that + # are not normally sent to appservices. + sync_with_custom_puppets: true + + # Servers to always allow double puppeting from + double_puppet_server_map: + "{{ matrix_go_skype_bridge_homeserver_domain }}": {{ matrix_go_skype_bridge_homeserver_address }} + # Allow using double puppeting from any server with a valid client .well-known file. + double_puppet_allow_discovery: false + # Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth + # + # If set, custom puppets will be enabled automatically for local users + # instead of users having to find an access token and run `login-matrix` + # manually. + login_shared_secret_map: {{ matrix_go_skype_bridge_bridge_login_shared_secret_map|to_json }} + + # Whether or not to invite own Skype user's Matrix puppet into private + # chat portals when backfilling if needed. + # This always uses the default puppet instead of custom puppets due to + # rate limits and timestamp massaging. + invite_own_puppet_for_backfilling: true + # Whether or not to explicitly set the avatar and room name for private + # chat portal rooms. This can be useful if the previous field works fine, + # but causes room avatar/name bugs. + private_chat_portal_meta: true + + # Whether or not thumbnails from Skype should be sent. + # They're disabled by default due to very low resolution. + Skype_thumbnail: false + + # Allow invite permission for user. User can invite any bots to room with Skype + # users (private chat and groups) + allow_user_invite: false + + # The prefix for commands. Only required in non-management rooms. + command_prefix: "{{ matrix_go_skype_bridge_command_prefix }}" + + # End-to-bridge encryption support options. This requires login_shared_secret to be configured + # in order to get a device for the bridge bot. + # + # Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal + # application service. + encryption: + # Allow encryption, work in group chat rooms with e2ee enabled + allow: {{ matrix_go_skype_bridge_bridge_encryption_allow|to_json }} + # Default to encryption, force-enable encryption in all portals the bridge creates + # This will cause the bridge bot to be in private chats for the encryption to work properly. + # It is recommended to also set private_chat_portal_meta to true when using this. + default: {{ matrix_go_skype_bridge_bridge_encryption_default|to_json }} + + puppet_id: + # when set to true, the matrixid of the contact (puppet) from the bridge to the matrix will be encrypted into another string + allow: false + # 8 characters + key: '12dsf323' + # Use the username_template prefix. (Warning: At present, username_template cannot be too complicated, otherwise this function may cause unknown errors) + username_template_prefix: 'skype-' + + # Permissions for using the bridge. + # Permitted values: + # relaybot - Talk through the relaybot (if enabled), no access otherwise + # user - Access to use the bridge to chat with a Skype account. + # admin - User level and some additional administration tools + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: {{ matrix_go_skype_bridge_bridge_permissions|to_json }} + + relaybot: + # Whether or not relaybot support is enabled. + enabled: false + # The management room for the bot. This is where all status notifications are posted and + # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting + # the command prefix completely like in user management rooms is not possible. + management: '!foo:example.com' + # List of users to invite to all created rooms that include the relaybot. + invites: [] + # The formats to use when sending messages to Skype via the relaybot. + message_formats: + m.text: "{{ '{{ .Sender.Displayname }}' }}: {{ '{{ .Message }}' }}" + m.notice: "{{ '{{ .Sender.Displayname }}' }}:: {{ '{{ .Message }}' }}" + m.emote: "* {{ '{{ .Sender.Displayname }}' }}: {{ '{{ .Message }}' }}" + m.file: "{{ '{{ .Sender.Displayname }}' }}: sent a file" + m.image: "{{ '{{ .Sender.Displayname }}' }}: sent an image" + m.audio: "{{ '{{ .Sender.Displayname }}' }}: sent an audio file" + m.video: "{{ '{{ .Sender.Displayname }}' }}: sent a video" + m.location: "{{ '{{ .Sender.Displayname }}' }}: sent a location" + +# Logging config. +logging: + # The directory for log files. Will be created if not found. + directory: ./logs + # Available variables: .Date for the file date and .Index for different log files on the same day. + # empy/null = journal logging only + file_name_format: + # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants + file_date_format: "2006-01-02" + # Log file permissions. + file_mode: 0600 + # Timestamp format for log entries in the Go time format. + timestamp_format: "Jan _2, 2006 15:04:05" + # Minimum severity for log messages. + # Options: debug, info, warn, error, fatal + print_level: {{ matrix_go_skype_bridge_log_level }} diff --git a/roles/matrix-bridge-mx-puppet-skype/templates/systemd/matrix-mx-puppet-skype.service.j2 b/roles/matrix-bridge-go-skype-bridge/templates/systemd/matrix-go-skype-bridge.service.j2 similarity index 54% rename from roles/matrix-bridge-mx-puppet-skype/templates/systemd/matrix-mx-puppet-skype.service.j2 rename to roles/matrix-bridge-go-skype-bridge/templates/systemd/matrix-go-skype-bridge.service.j2 index ec06485a..fe5ab2d6 100644 --- a/roles/matrix-bridge-mx-puppet-skype/templates/systemd/matrix-mx-puppet-skype.service.j2 +++ b/roles/matrix-bridge-go-skype-bridge/templates/systemd/matrix-go-skype-bridge.service.j2 @@ -1,11 +1,11 @@ #jinja2: lstrip_blocks: "True" [Unit] -Description=Matrix Mx Puppet Skype bridge -{% for service in matrix_mx_puppet_skype_systemd_required_services_list %} +Description=Matrix Go Skype Bridge bridge +{% for service in matrix_go_skype_bridge_systemd_required_services_list %} Requires={{ service }} After={{ service }} {% endfor %} -{% for service in matrix_mx_puppet_skype_systemd_wanted_services_list %} +{% for service in matrix_go_skype_bridge_systemd_wanted_services_list %} Wants={{ service }} {% endfor %} DefaultDependencies=no @@ -13,31 +13,31 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ matrix_systemd_unit_home_path }}" -ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mx-puppet-skype 2>/dev/null || true' -ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mx-puppet-skype 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-go-skype-bridge 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-go-skype-bridge 2>/dev/null || true' # 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-mx-puppet-skype \ +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-go-skype-bridge \ --log-driver=none \ --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ --cap-drop=ALL \ --network={{ matrix_docker_network }} \ - -e CONFIG_PATH=/config/config.yaml \ - -e REGISTRATION_PATH=/config/registration.yaml \ - -v {{ matrix_mx_puppet_skype_config_path }}:/config:z \ - -v {{ matrix_mx_puppet_skype_data_path }}:/data:z \ - {% for arg in matrix_mx_puppet_skype_container_extra_arguments %} + -v {{ matrix_go_skype_bridge_config_path }}:/config:z \ + -v {{ matrix_go_skype_bridge_data_path }}:/data:z \ + --workdir=/data \ + {% for arg in matrix_go_skype_bridge_container_extra_arguments %} {{ arg }} \ {% endfor %} - {{ matrix_mx_puppet_skype_docker_image }} + {{ matrix_go_skype_bridge_docker_image }} \ + /usr/bin/matrix-skype -c /config/config.yaml -r /config/registration.yaml -ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mx-puppet-skype 2>/dev/null || true' -ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mx-puppet-skype 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-go-skype-bridge 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-go-skype-bridge 2>/dev/null || true' Restart=always RestartSec=30 -SyslogIdentifier=matrix-mx-puppet-skype +SyslogIdentifier=matrix-go-skype-bridge [Install] WantedBy=multi-user.target diff --git a/roles/matrix-bridge-heisenbridge/defaults/main.yml b/roles/matrix-bridge-heisenbridge/defaults/main.yml index 80b3c95a..da74ed21 100644 --- a/roles/matrix-bridge-heisenbridge/defaults/main.yml +++ b/roles/matrix-bridge-heisenbridge/defaults/main.yml @@ -1,10 +1,10 @@ --- # heisenbridge is a bouncer-style Matrix IRC bridge -# See: https://github.com/hifi/heisenbridge +# Project source code URL: https://github.com/hifi/heisenbridge matrix_heisenbridge_enabled: true -matrix_heisenbridge_version: 1.10.1 +matrix_heisenbridge_version: 1.13.1 matrix_heisenbridge_docker_image: "{{ matrix_container_global_registry_prefix }}hif1/heisenbridge:{{ matrix_heisenbridge_version }}" matrix_heisenbridge_docker_image_force_pull: "{{ matrix_heisenbridge_docker_image.endswith(':latest') }}" @@ -45,4 +45,4 @@ matrix_heisenbridge_registration_yaml: aliases: [] rooms: [] -matrix_heisenbridge_registration: "{{ matrix_heisenbridge_registration_yaml|from_yaml }}" +matrix_heisenbridge_registration: "{{ matrix_heisenbridge_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-heisenbridge/tasks/init.yml b/roles/matrix-bridge-heisenbridge/tasks/init.yml index a66d7199..1612a505 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/init.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/init.yml @@ -2,24 +2,28 @@ # 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-heisenbridge role needs to execute before the matrix-synapse role. - when: "matrix_heisenbridge_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_heisenbridge_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-heisenbridge.service'] }}" - when: matrix_heisenbridge_enabled|bool + when: matrix_heisenbridge_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([]) }} - + - ["--mount type=bind,src={{ matrix_heisenbridge_base_path }}/registration.yaml,dst=/heisenbridge-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_heisenbridge_base_path }}/registration.yaml,dst=/heisenbridge-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/heisenbridge-registration.yaml"] }} - when: matrix_heisenbridge_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/heisenbridge-registration.yaml"] + }} + when: matrix_heisenbridge_enabled | bool diff --git a/roles/matrix-bridge-heisenbridge/tasks/main.yml b/roles/matrix-bridge-heisenbridge/tasks/main.yml index a266643d..6af9813e 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/main.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/main.yml @@ -1,17 +1,17 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_heisenbridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_heisenbridge_enabled | bool" tags: - setup-all - setup-heisenbridge -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_heisenbridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_heisenbridge_enabled | bool" tags: - setup-all - setup-heisenbridge diff --git a/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml b/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml index f24bf926..ffcc1c8b 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure heisenbridge paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -22,21 +22,21 @@ - "{{ matrix_heisenbridge_base_path }}" - name: Ensure heisenbridge registration.yaml installed if provided - copy: - content: "{{ matrix_heisenbridge_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_heisenbridge_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_heisenbridge_base_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-heisenbridge.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-heisenbridge.service.j2" dest: "{{ matrix_systemd_path }}/matrix-heisenbridge.service" mode: 0644 register: matrix_heisenbridge_systemd_service_result - name: Ensure systemd reloaded after matrix-heisenbridge.service installation - service: + ansible.builtin.service: daemon_reload: true when: matrix_heisenbridge_systemd_service_result.changed diff --git a/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml b/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml index 54d5bd67..a0232295 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-heisenbridge service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-heisenbridge.service" register: matrix_heisenbridge_service_stat - name: Ensure matrix-heisenbridge is stopped - service: + ansible.builtin.service: name: matrix-heisenbridge state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_heisenbridge_service_stat.stat.exists" - name: Ensure matrix-heisenbridge.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-heisenbridge.service" state: absent when: "matrix_heisenbridge_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-heisenbridge.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_heisenbridge_service_stat.stat.exists" diff --git a/roles/matrix-bridge-hookshot/defaults/main.yml b/roles/matrix-bridge-hookshot/defaults/main.yml index 45807ba9..7ffb26a2 100644 --- a/roles/matrix-bridge-hookshot/defaults/main.yml +++ b/roles/matrix-bridge-hookshot/defaults/main.yml @@ -1,7 +1,7 @@ --- # A bridge between Matrix and multiple project management services, such as GitHub, GitLab and JIRA. -# https://github.com/matrix-org/matrix-hookshot +# Project source code URL: https://github.com/matrix-org/matrix-hookshot matrix_hookshot_enabled: true @@ -10,7 +10,7 @@ matrix_hookshot_container_image_self_build: false matrix_hookshot_container_image_self_build_repo: "https://github.com/matrix-org/matrix-hookshot.git" matrix_hookshot_container_image_self_build_branch: "{{ 'main' if matrix_hookshot_version == 'latest' else matrix_hookshot_version }}" -matrix_hookshot_version: 1.5.0 +matrix_hookshot_version: 1.8.1 matrix_hookshot_docker_image: "{{ matrix_hookshot_docker_image_name_prefix }}halfshot/matrix-hookshot:{{ matrix_hookshot_version }}" matrix_hookshot_docker_image_name_prefix: "{{ 'localhost/' if matrix_hookshot_container_image_self_build else matrix_container_global_registry_prefix }}" @@ -29,13 +29,20 @@ matrix_hookshot_public_endpoint: /hookshot matrix_hookshot_appservice_port: 9993 matrix_hookshot_appservice_endpoint: "{{ matrix_hookshot_public_endpoint }}/_matrix/app" -# Metrics work only in conjunction with matrix_synapse_metrics_enabled etc -matrix_hookshot_metrics_enabled: true +# Controls whether metrics are enabled in the bridge configuration. +# Enabling them is usually enough for a local (in-container) Prometheus to consume them. +# If metrics need to be consumed by another (external) Prometheus server, consider exposing them via `matrix_hookshot_metrics_proxying_enabled`. +matrix_hookshot_metrics_enabled: false + +# Controls whether Hookshot metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/hookshot`. +# This will only work take effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. +# See the `matrix-nginx-proxy` role for details about enabling `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. +matrix_hookshot_metrics_proxying_enabled: false + # There is no need to edit ports. # Read the documentation to learn about using hookshot metrics with external Prometheus # If you still want something different, use matrix_hookshot_container_http_host_bind_ports below to expose ports instead. matrix_hookshot_metrics_port: 9001 -matrix_hookshot_metrics_endpoint: "{{ matrix_hookshot_public_endpoint }}/metrics" # There is no need to edit ports. use matrix_hookshot_container_http_host_bind_ports below to expose ports instead. matrix_hookshot_webhook_port: 9000 @@ -65,7 +72,7 @@ matrix_hookshot_github_oauth_uri: "{{ matrix_hookshot_urlprefix }}{{ matrix_hook # These are the default settings mentioned here and don't need to be modified: https://matrix-org.github.io/matrix-hookshot/usage/room_configuration/github_repo.html#configuration matrix_hookshot_github_ignore_hooks: "{}" matrix_hookshot_github_command_prefix: '!gh' -matrix_hookshot_github_showIssueRoomLink: false +matrix_hookshot_github_showIssueRoomLink: false # noqa var-naming matrix_hookshot_github_pr_diff: "{enabled: false, maxLines: 5}" matrix_hookshot_github_including_labels: '' matrix_hookshot_github_excluding_labels: '' @@ -90,7 +97,7 @@ matrix_hookshot_gitlab_secret: '' matrix_hookshot_figma_enabled: false # Default value of matrix_hookshot_figma_endpoint: "/hookshot/webhooks/figma/webhook" matrix_hookshot_figma_endpoint: "{{ matrix_hookshot_webhook_endpoint }}/figma/webhook" -matrix_hookshot_figma_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_figma_endpoint }}" +matrix_hookshot_figma_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_figma_endpoint }}" # noqa var-naming # To bridge figma webhooks, you need to configure one of multiple instances like this: # matrix_hookshot_figma_instances: # your-instance: @@ -121,6 +128,11 @@ matrix_hookshot_generic_allow_js_transformation_functions: false matrix_hookshot_generic_user_id_prefix: '_webhooks_' +matrix_hookshot_feeds_enabled: false +# polling interval in seconds +matrix_hookshot_feeds_interval: 600 + + # There is no need to edit ports. use matrix_hookshot_container_http_host_bind_ports below to expose ports instead. matrix_hookshot_provisioning_port: 9002 matrix_hookshot_provisioning_secret: '' @@ -132,9 +144,9 @@ matrix_hookshot_provisioning_endpoint: "{{ matrix_hookshot_public_endpoint }}{{ matrix_hookshot_widgets_enabled: true matrix_hookshot_widgets_port: 9003 -matrix_hookshot_widgets_addToAdminRooms: false # default off as it is a beta feature -matrix_hookshot_widgets_roomSetupWidget_enabled: true -matrix_hookshot_widgets_roomSetupWidget_addOnInvite: false +matrix_hookshot_widgets_addToAdminRooms: false # default off as it is a beta feature # noqa var-naming +matrix_hookshot_widgets_roomSetupWidget_enabled: true # noqa var-naming +matrix_hookshot_widgets_roomSetupWidget_addOnInvite: false # noqa var-naming # `disallowedIpRanges` describes which IP ranges should be disallowed when resolving homeserver IP addresses (for security reasons). Unless you know what you are doing, it is recommended to not include this key. The following IPs are blocked by default, unless you supply another list. # matrix_hookshot_widgets_disallowedIpRanges: # - 127.0.0.0/8 @@ -156,12 +168,12 @@ matrix_hookshot_widgets_roomSetupWidget_addOnInvite: false # - 2001:db8::/32 # - ff00::/8 # - fec0::/10 -matrix_hookshot_widgets_disallowedIpRanges: '' +matrix_hookshot_widgets_disallowedIpRanges: '' # noqa var-naming matrix_hookshot_widgets_internal: "/widgetapi" # Default value of matrix_hookshot_widgets_endpoint: "/hookshot/widgetapi" matrix_hookshot_widgets_endpoint: "{{ matrix_hookshot_public_endpoint }}{{ matrix_hookshot_widgets_internal }}" -matrix_hookshot_widgets_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_widgets_endpoint }}/v1/static" -matrix_hookshot_widgets_branding_widgetTitle: "Hookshot Configuration" +matrix_hookshot_widgets_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_widgets_endpoint }}/v1/static" # noqa var-naming +matrix_hookshot_widgets_branding_widgetTitle: "Hookshot Configuration" # noqa var-naming # You can configure access to the bridge as documented here https://matrix-org.github.io/matrix-hookshot/setup.html#permissions @@ -221,11 +233,11 @@ matrix_hookshot_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_hookshot_configuration_yaml`. -matrix_hookshot_configuration_extension: "{{ matrix_hookshot_configuration_extension_yaml|from_yaml if matrix_hookshot_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_hookshot_configuration_extension: "{{ matrix_hookshot_configuration_extension_yaml | from_yaml if matrix_hookshot_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_hookshot_configuration_yaml`. -matrix_hookshot_configuration: "{{ matrix_hookshot_configuration_yaml|from_yaml|combine(matrix_hookshot_configuration_extension, recursive=True) }}" +matrix_hookshot_configuration: "{{ matrix_hookshot_configuration_yaml | from_yaml | combine(matrix_hookshot_configuration_extension, recursive=True) }}" # Default registration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -243,8 +255,8 @@ matrix_hookshot_registration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_hookshot_registration_yaml`. -matrix_hookshot_registration_extension: "{{ matrix_hookshot_registration_extension_yaml|from_yaml if matrix_hookshot_registration_extension_yaml|from_yaml is mapping else {} }}" +matrix_hookshot_registration_extension: "{{ matrix_hookshot_registration_extension_yaml | from_yaml if matrix_hookshot_registration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final registration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_hookshot_registration_yaml`. -matrix_hookshot_registration: "{{ matrix_hookshot_registration_yaml|from_yaml|combine(matrix_hookshot_registration_extension, recursive=True) }}" +matrix_hookshot_registration: "{{ matrix_hookshot_registration_yaml | from_yaml | combine(matrix_hookshot_registration_extension, recursive=True) }}" diff --git a/roles/matrix-bridge-hookshot/tasks/init.yml b/roles/matrix-bridge-hookshot/tasks/init.yml index 384f6d3b..f8a1e76c 100644 --- a/roles/matrix-bridge-hookshot/tasks/init.yml +++ b/roles/matrix-bridge-hookshot/tasks/init.yml @@ -2,43 +2,47 @@ # 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-hookshot role needs to execute before the matrix-synapse role. - when: "matrix_hookshot_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_hookshot_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-hookshot.service'] }}" - when: matrix_hookshot_enabled|bool + when: matrix_hookshot_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([]) }} - + - ["--mount type=bind,src={{ matrix_hookshot_base_path }}/registration.yml,dst=/hookshot-registration.yml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_hookshot_base_path }}/registration.yml,dst=/hookshot-registration.yml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/hookshot-registration.yml"] }} - when: matrix_hookshot_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/hookshot-registration.yml"] + }} + when: matrix_hookshot_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append hookshot's 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-hookshot role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix hookshot proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_hookshot_matrix_nginx_proxy_configuration: | location ~ ^{{ matrix_hookshot_appservice_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_appservice_port }}"; @@ -51,7 +55,7 @@ } {% if matrix_hookshot_provisioning_enabled %} location ~ ^{{ matrix_hookshot_provisioning_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_provisioning_port }}"; @@ -65,7 +69,7 @@ {% endif %} {% if matrix_hookshot_widgets_enabled %} location ~ ^{{ matrix_hookshot_widgets_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_widgets_port }}"; @@ -78,7 +82,7 @@ } {% endif %} location ~ ^{{ matrix_hookshot_webhook_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_webhook_port }}"; @@ -91,20 +95,19 @@ } - name: Register hookshot proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_hookshot_matrix_nginx_proxy_configuration] }} - - name: Generate Matrix hookshot proxying configuration for matrix-nginx-proxy - set_fact: - matrix_hookshot_matrix_nginx_proxy_metrics_configuration: | - {% if matrix_hookshot_metrics_enabled and matrix_hookshot_proxy_metrics %} - location {{ matrix_hookshot_metrics_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + - name: Generate hookshot metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/hookshot) + ansible.builtin.set_fact: + matrix_hookshot_matrix_nginx_proxy_metrics_configuration_matrix_domain: | + location /metrics/hookshot { + {% 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_hookshot_container_url }}:{{ matrix_hookshot_metrics_port }}"; @@ -113,32 +116,26 @@ {# Generic configuration for use outside of our container setup #} proxy_pass http://127.0.0.1:{{ matrix_hookshot_metrics_port }}/metrics; {% endif %} - proxy_set_header Host $host; - {% if matrix_hookshot_proxy_metrics_basic_auth_enabled %} - auth_basic "protected"; - auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd; - {% endif %} } - {% endif %} + when: matrix_hookshot_metrics_enabled | bool and matrix_hookshot_metrics_proxying_enabled | bool - - name: Register hookshot metrics proxying configuration with matrix-nginx-proxy - set_fact: - matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks: | + - name: Register hookshot metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/hookshot) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + - [matrix_hookshot_matrix_nginx_proxy_metrics_configuration] + [matrix_hookshot_matrix_nginx_proxy_metrics_configuration_matrix_domain] }} - tags: - - always - when: matrix_hookshot_enabled|bool + when: matrix_hookshot_metrics_enabled | bool and matrix_hookshot_metrics_proxying_enabled | bool + when: matrix_hookshot_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the hookshot bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_hookshot_public_endpoint }}` URL endpoint to the matrix-hookshot container. You can expose the container's ports using the `matrix_hookshot_container_http_host_bind_ports` variable. - when: "matrix_hookshot_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_hookshot_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-hookshot/tasks/main.yml b/roles/matrix-bridge-hookshot/tasks/main.yml index 409b6175..99febe11 100644 --- a/roles/matrix-bridge-hookshot/tasks/main.yml +++ b/roles/matrix-bridge-hookshot/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_hookshot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_hookshot_enabled | bool" tags: - setup-all - setup-hookshot -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_hookshot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_hookshot_enabled | bool" tags: - setup-all - setup-hookshot -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_hookshot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_hookshot_enabled | bool" tags: - setup-all - setup-hookshot diff --git a/roles/matrix-bridge-hookshot/tasks/setup_install.yml b/roles/matrix-bridge-hookshot/tasks/setup_install.yml index 25f2978c..0c6bfc34 100644 --- a/roles/matrix-bridge-hookshot/tasks/setup_install.yml +++ b/roles/matrix-bridge-hookshot/tasks/setup_install.yml @@ -1,9 +1,9 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" - name: Ensure hookshot paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -12,7 +12,7 @@ with_items: - {path: "{{ matrix_hookshot_base_path }}", when: true} - {path: "{{ matrix_hookshot_docker_src_files_path }}", when: "{{ matrix_hookshot_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure hookshot image is pulled docker_image: @@ -27,7 +27,7 @@ until: result is not failed - name: Ensure hookshot repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_hookshot_container_image_self_build_repo }}" dest: "{{ matrix_hookshot_docker_src_files_path }}" version: "{{ matrix_hookshot_container_image_self_build_branch }}" @@ -35,7 +35,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_hookshot_git_pull_results - when: "matrix_hookshot_container_image_self_build|bool" + when: "matrix_hookshot_container_image_self_build | bool" - name: Ensure hookshot Docker image is built docker_image: @@ -47,68 +47,70 @@ dockerfile: Dockerfile path: "{{ matrix_hookshot_docker_src_files_path }}" pull: true - when: "matrix_hookshot_container_image_self_build|bool" + when: "matrix_hookshot_container_image_self_build | bool" - name: Check if hookshot passkey exists - stat: + ansible.builtin.stat: path: "{{ matrix_hookshot_base_path }}/passkey.pem" register: hookshot_passkey_file - name: Generate hookshot passkey if it doesn't exist - shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096" + ansible.builtin.shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096" become: true become_user: "{{ matrix_user_username }}" when: "not hookshot_passkey_file.stat.exists" - name: Ensure hookshot config.yml installed if provided - copy: - content: "{{ matrix_hookshot_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_hookshot_base_path }}/config.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Validate hookshot config.yml - command: | - {{ matrix_host_command_docker }} run - --rm - --name={{ matrix_hookshot_container_url }}-validate - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} - --cap-drop=ALL - -v {{ matrix_hookshot_base_path }}/config.yml:/config.yml - {{ matrix_hookshot_docker_image }} node Config/Config.js /config.yml + ansible.builtin.command: + cmd: | + {{ matrix_host_command_docker }} run + --rm + --name={{ matrix_hookshot_container_url }}-validate + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --cap-drop=ALL + -v {{ matrix_hookshot_base_path }}/config.yml:/config.yml + {{ matrix_hookshot_docker_image }} node Config/Config.js /config.yml register: hookshot_config_validation_result + changed_when: false - name: Fail if hookshot config.yml invalid - fail: + ansible.builtin.fail: msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}" when: "hookshot_config_validation_result.rc > 0" - name: Ensure hookshot registration.yml installed if provided - copy: - content: "{{ matrix_hookshot_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_hookshot_base_path }}/registration.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure hookshot github private key file installed if github is enabled - copy: + ansible.builtin.copy: content: "{{ matrix_hookshot_github_private_key }}" dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}" mode: 0400 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_hookshot_github_enabled|bool and matrix_hookshot_github_private_key|length > 0 + when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0 - name: Ensure matrix-hookshot.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2" dest: "{{ matrix_systemd_path }}/matrix-hookshot.service" mode: 0644 register: matrix_hookshot_systemd_service_result - name: Ensure systemd reloaded after matrix-hookshot.service installation - service: + ansible.builtin.service: daemon_reload: true when: matrix_hookshot_systemd_service_result.changed diff --git a/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml b/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml index d8efbb02..5aba14de 100644 --- a/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-hookshot service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-hookshot.service" register: matrix_hookshot_service_stat - name: Ensure matrix-hookshot is stopped - service: + ansible.builtin.service: name: matrix-hookshot state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_hookshot_service_stat.stat.exists" - name: Ensure matrix-hookshot.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-hookshot.service" state: absent when: "matrix_hookshot_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-hookshot.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_hookshot_service_stat.stat.exists" diff --git a/roles/matrix-bridge-hookshot/tasks/validate_config.yml b/roles/matrix-bridge-hookshot/tasks/validate_config.yml index 5da8809e..0fbcf53c 100644 --- a/roles/matrix-bridge-hookshot/tasks/validate_config.yml +++ b/roles/matrix-bridge-hookshot/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -10,7 +10,7 @@ - "matrix_hookshot_homeserver_token" - name: Fail if required GitHub settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable GitHub. when: "matrix_hookshot_github_enabled and vars[item] == ''" @@ -19,7 +19,7 @@ - "matrix_hookshot_github_secret" - name: Fail if required GitHub OAuth settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable GitHub OAuth. when: "matrix_hookshot_github_oauth_enabled and vars[item] == ''" @@ -28,7 +28,7 @@ - "matrix_hookshot_github_oauth_secret" - name: Fail if required Jira settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable Jira. when: "matrix_hookshot_jira_enabled and vars[item] == ''" @@ -36,7 +36,7 @@ - "matrix_hookshot_jira_secret" - name: Fail if required Jira OAuth settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable Jira OAuth. when: "matrix_hookshot_jira_oauth_enabled and vars[item] == ''" @@ -45,15 +45,28 @@ - "matrix_hookshot_jira_oauth_secret" - name: Fail if required Figma settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define at least one Figma instance to enable Figma. when: "matrix_hookshot_figma_enabled and matrix_hookshot_figma_instances is undefined" - name: Fail if required provisioning settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable provisioning. when: "matrix_hookshot_provisioning_enabled and vars[item] == ''" with_items: - "matrix_hookshot_provisioning_secret" + +- name: (Deprecation) Catch and report old metrics usage + ansible.builtin.fail: + msg: >- + Your configuration contains a variable (`{{ item }}`), which refers to the old metrics collection system for Hookshot, + which exposed metrics on `https://stats.DOMAIN/hookshot/metrics`. + + We now recommend exposing Hookshot metrics in another way, from another URL. + Refer to the changelog for more details: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/CHANGELOG.md#2022-06-22 + with_items: + - matrix_hookshot_proxy_metrics + - matrix_hookshot_metrics_endpoint + when: "item in vars" diff --git a/roles/matrix-bridge-hookshot/templates/config.yml.j2 b/roles/matrix-bridge-hookshot/templates/config.yml.j2 index c1771509..6fbce770 100644 --- a/roles/matrix-bridge-hookshot/templates/config.yml.j2 +++ b/roles/matrix-bridge-hookshot/templates/config.yml.j2 @@ -78,6 +78,13 @@ generic: allowJsTransformationFunctions: {{ matrix_hookshot_generic_allow_js_transformation_functions }} userIdPrefix: {{ matrix_hookshot_generic_user_id_prefix|to_json }} {% endif %} +{% if matrix_hookshot_feeds_enabled %} +feeds: + # (Optional) Configure this to enable RSS/Atom feed support + # + enabled: {{ matrix_hookshot_feeds_enabled }} + pollIntervalSeconds: {{ matrix_hookshot_feeds_interval }} +{% endif %} {% if matrix_hookshot_provisioning_enabled %} provisioning: # (Optional) Provisioning API for integration managers diff --git a/roles/matrix-bridge-mautrix-discord/defaults/main.yml b/roles/matrix-bridge-mautrix-discord/defaults/main.yml new file mode 100644 index 00000000..dbc23031 --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/defaults/main.yml @@ -0,0 +1,142 @@ +--- +# mautrix-discord is a Matrix <-> Discord bridge +# Project source code URL: https://github.com/mautrix/discord + +matrix_mautrix_discord_enabled: true + +matrix_mautrix_discord_container_image_self_build: false +matrix_mautrix_discord_container_image_self_build_repo: "https://mau.dev/mautrix/discord.git" +matrix_mautrix_discord_container_image_self_build_branch: "{{ 'main' if matrix_mautrix_discord_version == 'latest' else matrix_mautrix_discord_version }}" + +matrix_mautrix_discord_version: latest +# See: https://mau.dev/mautrix/discord/container_registry +matrix_mautrix_discord_docker_image: "{{ matrix_mautrix_discord_docker_image_name_prefix }}mautrix/discord:{{ matrix_mautrix_discord_version }}" +matrix_mautrix_discord_docker_image_name_prefix: "{{ 'localhost/' if matrix_mautrix_discord_container_image_self_build else 'dock.mau.dev/' }}" +matrix_mautrix_discord_docker_image_force_pull: "{{ matrix_mautrix_discord_docker_image.endswith(':latest') }}" + +matrix_mautrix_discord_base_path: "{{ matrix_base_data_path }}/mautrix-discord" +matrix_mautrix_discord_config_path: "{{ matrix_mautrix_discord_base_path }}/config" +matrix_mautrix_discord_data_path: "{{ matrix_mautrix_discord_base_path }}/data" +matrix_mautrix_discord_docker_src_files_path: "{{ matrix_mautrix_discord_base_path }}/docker-src" + +matrix_mautrix_discord_homeserver_address: "{{ matrix_homeserver_container_url }}" +matrix_mautrix_discord_homeserver_domain: "{{ matrix_domain }}" +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: [] + +# List of systemd services that matrix-mautrix-discord.service depends on. +matrix_mautrix_discord_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-mautrix-discord.service wants +matrix_mautrix_discord_systemd_wanted_services_list: [] + +matrix_mautrix_discord_appservice_token: '' +matrix_mautrix_discord_homeserver_token: '' + +matrix_mautrix_discord_appservice_bot_username: discordbot + +# Minimum severity of journal log messages. +# Options: debug, info, warn, error, fatal +matrix_mautrix_discord_logging_level: 'warn' + +# Whether or not created rooms should have federation enabled. +# If false, created portal rooms will never be federated. +matrix_mautrix_discord_federate_rooms: true + +# Database-related configuration fields. +# +# To use SQLite, stick to these defaults. +# +# To use Postgres: +# - change the engine (`matrix_mautrix_discord_database_engine: 'postgres'`) +# - adjust your database credentials via the `matrix_mautrix_discord_database_*` variables +matrix_mautrix_discord_database_engine: 'sqlite' + +matrix_mautrix_discord_sqlite_database_path_local: "{{ matrix_mautrix_discord_data_path }}/mautrix-discord.db" +matrix_mautrix_discord_sqlite_database_path_in_container: "/data/mautrix-discord.db" + +matrix_mautrix_discord_database_username: 'matrix_mautrix_discord' +matrix_mautrix_discord_database_password: 'some-password' +matrix_mautrix_discord_database_hostname: 'matrix-postgres' +matrix_mautrix_discord_database_port: 5432 +matrix_mautrix_discord_database_name: 'matrix_mautrix_discord' + +matrix_mautrix_discord_database_connection_string: 'postgresql://{{ matrix_mautrix_discord_database_username }}:{{ matrix_mautrix_discord_database_password }}@{{ matrix_mautrix_discord_database_hostname }}:{{ matrix_mautrix_discord_database_port }}/{{ matrix_mautrix_discord_database_name }}?sslmode=disable' + +matrix_mautrix_discord_appservice_database_type: "{{ + { + 'sqlite': 'sqlite3', + 'postgres':'postgres', + }[matrix_mautrix_discord_database_engine] +}}" + +matrix_mautrix_discord_appservice_database_uri: "{{ + { + 'sqlite': matrix_mautrix_discord_sqlite_database_path_in_container, + 'postgres': matrix_mautrix_discord_database_connection_string, + }[matrix_mautrix_discord_database_engine] +}}" + +# Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). +matrix_mautrix_discord_login_shared_secret: '' +matrix_mautrix_discord_bridge_login_shared_secret_map: + "{{ {matrix_mautrix_discord_homeserver_domain: matrix_mautrix_discord_login_shared_secret} if matrix_mautrix_discord_login_shared_secret else {} }}" + +# Servers to always allow double puppeting from +matrix_mautrix_discord_bridge_double_puppet_server_map: + "{{ matrix_mautrix_discord_homeserver_domain : matrix_mautrix_discord_homeserver_address }}" + +# Default mautrix-discord configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_mautrix_discord_configuration_extension_yaml`) +# or completely replace this variable with your own template. +matrix_mautrix_discord_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" + +matrix_mautrix_discord_configuration_extension_yaml: | + # Your custom YAML configuration goes here. + # This configuration extends the default starting configuration (`matrix_mautrix_discord_configuration_yaml`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_mautrix_discord_configuration_yaml`. + +matrix_mautrix_discord_configuration_extension: "{{ matrix_mautrix_discord_configuration_extension_yaml | from_yaml if matrix_mautrix_discord_configuration_extension_yaml | from_yaml is mapping else {} }}" + +# Holds the final configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_mautrix_discord_configuration_yaml`. +matrix_mautrix_discord_configuration: "{{ matrix_mautrix_discord_configuration_yaml | from_yaml | combine(matrix_mautrix_discord_configuration_extension, recursive=True) }}" + +matrix_mautrix_discord_registration_yaml: | + id: discord + url: {{ matrix_mautrix_discord_appservice_address }} + as_token: "{{ matrix_mautrix_discord_appservice_token }}" + hs_token: "{{ matrix_mautrix_discord_homeserver_token }}" + # See https://github.com/mautrix/signal/issues/43 + sender_localpart: _bot_{{ matrix_mautrix_discord_appservice_bot_username }} + rate_limited: false + namespaces: + users: + - regex: '^@discord_[0-9]+:{{ matrix_mautrix_discord_homeserver_domain | regex_escape }}$' + exclusive: true + - exclusive: true + regex: '^@{{ matrix_mautrix_discord_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_discord_homeserver_domain | regex_escape }}$' + de.sorunome.msc2409.push_ephemeral: true + +matrix_mautrix_discord_registration: "{{ matrix_mautrix_discord_registration_yaml | from_yaml }}" + +# Enable End-to-bridge encryption +matrix_mautrix_discord_bridge_encryption_allow: false +matrix_mautrix_discord_bridge_encryption_default: "{{ matrix_mautrix_discord_bridge_encryption_allow }}" +matrix_mautrix_discord_bridge_encryption_key_sharing_allow: "{{ matrix_mautrix_discord_bridge_encryption_allow }}" diff --git a/roles/matrix-bridge-mautrix-discord/tasks/init.yml b/roles/matrix-bridge-mautrix-discord/tasks/init.yml new file mode 100644 index 00000000..30baf017 --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/tasks/init.yml @@ -0,0 +1,21 @@ +--- +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-discord.service'] }}" + when: matrix_mautrix_discord_enabled | bool + +# If the matrix-synapse role is not used, these variables may not exist. +- ansible.builtin.set_fact: + matrix_synapse_container_extra_arguments: > + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_discord_config_path }}/registration.yaml,dst=/matrix-mautrix-discord-registration.yaml,ro"] + }} + + matrix_synapse_app_service_config_files: > + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-discord-registration.yaml"] + }} + when: matrix_mautrix_discord_enabled | bool diff --git a/roles/matrix-bridge-mautrix-discord/tasks/main.yml b/roles/matrix-bridge-mautrix-discord/tasks/main.yml new file mode 100644 index 00000000..9eaadf68 --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/tasks/main.yml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_discord_enabled | bool" + tags: + - setup-all + - setup-mautrix-discord + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup and matrix_mautrix_discord_enabled" + tags: + - setup-all + - setup-mautrix-discord + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup and not matrix_mautrix_discord_enabled" + tags: + - setup-all + - setup-mautrix-discord diff --git a/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml new file mode 100644 index 00000000..7e2ed79c --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/tasks/setup_install.yml @@ -0,0 +1,122 @@ +--- + +# 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 + ansible.builtin.fail: + msg: >- + The matrix-bridge-mautrix-discord role needs to execute before the matrix-synapse role. + when: "matrix_synapse_role_executed | default(False)" + +- ansible.builtin.set_fact: + matrix_mautrix_discord_requires_restart: false + +- block: + - name: Check if an SQLite database already exists + ansible.builtin.stat: + path: "{{ matrix_mautrix_discord_sqlite_database_path_local }}" + register: matrix_mautrix_discord_sqlite_database_path_local_stat_result + + - block: + - ansible.builtin.set_fact: + matrix_postgres_db_migration_request: + src: "{{ matrix_mautrix_discord_sqlite_database_path_local }}" + dst: "{{ matrix_mautrix_discord_database_connection_string }}" + caller: "{{ role_path | basename }}" + engine_variable_name: 'matrix_mautrix_discord_database_engine' + engine_old: 'sqlite' + systemd_services_to_stop: ['matrix-mautrix-discord.service'] + pgloader_options: ['--with "quote identifiers"'] + + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres + + - ansible.builtin.set_fact: + matrix_mautrix_discord_requires_restart: true + when: "matrix_mautrix_discord_sqlite_database_path_local_stat_result.stat.exists | bool" + when: "matrix_mautrix_discord_database_engine == 'postgres'" + + +- name: Ensure Mautrix Discord paths exists + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_mautrix_discord_base_path }}", when: true} + - {path: "{{ matrix_mautrix_discord_config_path }}", when: true} + - {path: "{{ matrix_mautrix_discord_data_path }}", when: true} + - {path: "{{ matrix_mautrix_discord_docker_src_files_path }}", when: "{{ matrix_mautrix_discord_container_image_self_build }}"} + when: item.when | bool + +- name: Ensure Mautrix Discord image is pulled + docker_image: + name: "{{ matrix_mautrix_discord_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_mautrix_discord_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_discord_docker_image_force_pull }}" + when: not matrix_mautrix_discord_container_image_self_build + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure Mautrix discord repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_mautrix_discord_container_image_self_build_repo }}" + dest: "{{ matrix_mautrix_discord_docker_src_files_path }}" + version: "{{ matrix_mautrix_discord_container_image_self_build_branch }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_mautrix_discord_git_pull_results + when: "matrix_mautrix_discord_container_image_self_build | bool" + +- name: Ensure Mautrix discord Docker image is built + docker_image: + name: "{{ matrix_mautrix_discord_docker_image }}" + source: build + force_source: "{{ matrix_mautrix_discord_git_pull_results.changed 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_discord_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_mautrix_discord_docker_src_files_path }}" + pull: true + when: "matrix_mautrix_discord_container_image_self_build | bool" + +- name: Ensure mautrix-discord config.yaml installed + ansible.builtin.copy: + content: "{{ matrix_mautrix_discord_configuration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_mautrix_discord_config_path }}/config.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure mautrix-discord registration.yaml installed + ansible.builtin.copy: + content: "{{ matrix_mautrix_discord_registration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_mautrix_discord_config_path }}/registration.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-mautrix-discord.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-mautrix-discord.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-mautrix-discord.service" + mode: 0644 + register: matrix_mautrix_discord_systemd_service_result + +- name: Ensure systemd reloaded after matrix-mautrix-discord.service installation + ansible.builtin.service: + daemon_reload: true + when: "matrix_mautrix_discord_systemd_service_result.changed" + +- name: Ensure matrix-mautrix-discord.service restarted, if necessary + ansible.builtin.service: + name: "matrix-mautrix-discord.service" + state: restarted + when: "matrix_mautrix_discord_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-discord/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-discord/tasks/setup_uninstall.yml new file mode 100644 index 00000000..94fef89a --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/tasks/setup_uninstall.yml @@ -0,0 +1,25 @@ +--- + +- name: Check existence of matrix-mautrix-discord service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-mautrix-discord.service" + register: matrix_mautrix_discord_service_stat + +- name: Ensure matrix-mautrix-discord is stopped + ansible.builtin.service: + name: matrix-mautrix-discord + state: stopped + enabled: false + daemon_reload: true + when: "matrix_mautrix_discord_service_stat.stat.exists" + +- name: Ensure matrix-mautrix-discord.service doesn't exist + ansible.builtin.file: + path: "{{ matrix_systemd_path }}/matrix-mautrix-discord.service" + state: absent + when: "matrix_mautrix_discord_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-mautrix-discord.service removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_mautrix_discord_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml new file mode 100644 index 00000000..4ba7e127 --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/tasks/validate_config.yml @@ -0,0 +1,10 @@ +--- + +- name: Fail if required settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - "matrix_mautrix_discord_appservice_token" + - "matrix_mautrix_discord_homeserver_token" diff --git a/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 new file mode 100644 index 00000000..fdd4f788 --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/templates/config.yaml.j2 @@ -0,0 +1,221 @@ +#jinja2: lstrip_blocks: "True" +# Homeserver details. +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: {{ matrix_mautrix_discord_homeserver_address | to_json }} + # The domain of the homeserver (for MXIDs, etc). + 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. + # If set, the bridge will make POST requests to this URL whenever a user's discord connection state changes. + # The bridge will use the appservice as_token to authorize requests. + status_endpoint: null + # Endpoint for reporting per-message status. + message_send_checkpoint_endpoint: null + # Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246? + async_media: false + +# Application service host/registration related details. +# 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 | to_json }} + + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 + port: 8080 + + # Database config. + database: + # The database type. "sqlite3" and "postgres" are supported. + type: {{ matrix_mautrix_discord_appservice_database_type|to_json }} + # The database URI. + # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string + # Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable + # To connect via Unix socket, use something like postgres:///dbname?host=/var/run/postgresql + uri: {{ matrix_mautrix_discord_appservice_database_uri|to_json }} + # Maximum number of connections. Mostly relevant for Postgres. + max_open_conns: 20 + max_idle_conns: 2 + # Maximum connection idle time and lifetime before they're closed. Disabled if null. + # Parsed with https://pkg.go.dev/time#ParseDuration + max_conn_idle_time: null + max_conn_lifetime: null + + # The unique ID of this appservice. + id: discord + # Appservice bot details. + bot: + # Username of the appservice bot. + username: {{ matrix_mautrix_discord_appservice_bot_username|to_json }} + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + displayname: Discord bridge bot + avatar: mxc://maunium.net/nIdEykemnwdisvHbpxflpDlC + # Whether or not to receive ephemeral events via appservice transactions. + # Requires MSC2409 support (i.e. Synapse 1.22+). + ephemeral_events: true + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: {{ matrix_mautrix_discord_appservice_token | to_json }} + hs_token: {{ matrix_mautrix_discord_homeserver_token | to_json }} + +# Bridge config +bridge: + # Localpart template of MXIDs for Discord users. + # {{ '{{.}}' }} is replaced with the internal ID of the Discord user. + username_template: "{{ 'discord_{{.}}' }}" + # Displayname template for Discord users. This is also used as the room name in DMs if private_chat_portal_meta is enabled. + # Available variables: + # {{ '{{.ID}}' }} - Internal user ID + # {{ '{{.Username}}' }} - User's displayname on Discord + # {{ '{{.Discriminator}}' }} - The 4 numbers after the name on Discord + # {{ '{{.Bot}}' }} - Whether the user is a bot + # {{ '{{.System}}' }} - Whether the user is an official system user + displayname_template: "{{ '{{.Username}} {{if .Bot}} (bot){{end}}' }}" + # Displayname template for Discord channels (bridged as rooms, or spaces when type=4). + # Available variables: + # {{ '{{.Name}}' }} - Channel name, or user displayname (pre-formatted with displayname_template) in DMs. + # {{ '{{.ParentName}}' }} - Parent channel name (used for categories). + # {{ '{{.GuildName}}' }} - Guild name. + # {{ '{{.NSFW}}' }} - Whether the channel is marked as NSFW. + # {{ '{{.Type}}' }} - Channel type (see values at https://github.com/bwmarrin/discordgo/blob/v0.25.0/structs.go#L251-L267) + channel_name_template: "{{ '{{if or (eq .Type 3) (eq .Type 4)}}{{.Name}}{{else}}#{{.Name}}{{end}}' }}" + # Displayname template for Discord guilds (bridged as spaces). + # Available variables: + # {{ '{{.Name}}' }} - Guild name + guild_name_template: "{{ '{{.Name}}' }}" + # Should the bridge explicitly set the avatar and room name for DM portal rooms? + # This is implicitly enabled in encrypted rooms. + private_chat_portal_meta: false + portal_message_buffer: 128 + # Number of private channel portals to create on bridge startup. + # Other portals will be created when receiving messages. + startup_private_channel_create_limit: 5 + # Should the bridge send a read receipt from the bridge bot when a message has been sent to Discord? + delivery_receipts: false + # Whether the bridge should send the message status as a custom com.beeper.message_send_status event. + message_status_events: true + # Whether the bridge should send error notices via m.notice events when a message fails to bridge. + message_error_notices: true + # Should the bridge use space-restricted join rules instead of invite-only for guild rooms? + # This can avoid unnecessary invite events in guild rooms when members are synced in. + restricted_rooms: true + # Should the bridge update the m.direct account data event when double puppeting is enabled. + # Note that updating the m.direct event is not atomic (except with mautrix-asmux) + # and is therefore prone to race conditions. + sync_direct_chat_list: false + # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. + # This field will automatically be changed back to false after it, except if the config file is not writable. + resend_bridge_info: false + # Should the bridge attempt to completely delete portal rooms when a channel is deleted on Discord? + # If true, the bridge will try to kick Matrix users from the room. Otherwise, the bridge only makes ghosts leave. + delete_portal_on_channel_delete: false + # Whether or not created rooms should have federation enabled. + # If false, created portal rooms will never be federated. + federate_rooms: {{ matrix_mautrix_discord_federate_rooms|to_json }} + # Servers to always allow double puppeting from + double_puppet_server_map: + "{{ matrix_mautrix_discord_homeserver_domain }}": {{ matrix_mautrix_discord_homeserver_address }} + # Allow using double puppeting from any server with a valid client .well-known file. + double_puppet_allow_discovery: false + # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth + # + # If set, double puppeting will be enabled automatically for local users + # instead of users having to find an access token and run `login-matrix` + # manually. + login_shared_secret_map: {{ matrix_mautrix_discord_bridge_login_shared_secret_map|to_json }} + + # The prefix for commands. Only required in non-management rooms. + command_prefix: "{{ matrix_mautrix_discord_command_prefix }}" + + # Messages sent upon joining a management room. + # Markdown is supported. The defaults are listed below. + management_room_text: + # Sent when joining a room. + welcome: "Hello, I'm a Discord bridge bot." + # Sent when joining a management room and the user is already logged in. + welcome_connected: "Use `help` for help." + # Sent when joining a management room and the user is not logged in. + welcome_unconnected: "Use `help` for help or `login` to log in." + # Optional extra text sent when joining a management room. + additional_help: "" + + # End-to-bridge encryption support options. + # + # See https://docs.mau.fi/bridges/general/end-to-bridge-encryption.html for more info. + encryption: + # Allow encryption, work in group chat rooms with e2ee enabled + allow: {{ matrix_mautrix_discord_bridge_encryption_allow|to_json }} + # Default to encryption, force-enable encryption in all portals the bridge creates + # This will cause the bridge bot to be in private chats for the encryption to work properly. + default: {{ matrix_mautrix_discord_bridge_encryption_default|to_json }} + # Require encryption, drop any unencrypted messages. + require: false + # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. + # You must use a client that supports requesting keys from other users to use this feature. + allow_key_sharing: {{ matrix_mautrix_discord_bridge_encryption_key_sharing_allow|to_json }} + # What level of device verification should be required from users? + # + # Valid levels: + # unverified - Send keys to all device in the room. + # cross-signed-untrusted - Require valid cross-signing, but trust all cross-signing keys. + # cross-signed-tofu - Require valid cross-signing, trust cross-signing keys on first use (and reject changes). + # cross-signed-verified - Require valid cross-signing, plus a valid user signature from the bridge bot. + # Note that creating user signatures from the bridge bot is not currently possible. + # verified - Require manual per-device verification + # (currently only possible by modifying the `trust` column in the `crypto_device` database table). + verification_levels: + # Minimum level for which the bridge should send keys to when bridging messages from WhatsApp to Matrix. + receive: unverified + # Minimum level that the bridge should accept for incoming Matrix messages. + send: unverified + # Minimum level that the bridge should require for accepting key requests. + share: cross-signed-tofu + # Options for Megolm room key rotation. These options allow you to + # configure the m.room.encryption event content. See: + # https://spec.matrix.org/v1.3/client-server-api/#mroomencryption for + # more information about that event. + rotation: + # Enable custom Megolm room key rotation settings. Note that these + # settings will only apply to rooms created after this option is + # set. + enable_custom: false + # The maximum number of milliseconds a session should be used + # before changing it. The Matrix spec recommends 604800000 (a week) + # as the default. + milliseconds: 604800000 + # The maximum number of messages that should be sent with a given a + # session before changing it. The Matrix spec recommends 100 as the + # default. + messages: 100 + + # Settings for provisioning API + provisioning: + # Prefix for the provisioning API paths. + prefix: /_matrix/provision + # Shared secret for authentication. If set to "generate", a random secret will be generated, + # or if set to "disable", the provisioning API will be disabled. + shared_secret: generate + + # Permissions for using the bridge. + # Permitted values: + # relay - Talk through the relaybot (if enabled), no access otherwise + # user - Access to use the bridge to chat with a Discord account. + # admin - User level and some additional administration tools + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: {{ matrix_mautrix_discord_bridge_permissions|to_json }} + +logging: + directory: ./logs + file_name_format: '' + file_date_format: "2006-01-02" + file_mode: 384 + timestamp_format: Jan _2, 2006 15:04:05 + 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 new file mode 100644 index 00000000..788cd012 --- /dev/null +++ b/roles/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 @@ -0,0 +1,43 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Matrix Mautrix Discord bridge +{% for service in matrix_mautrix_discord_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_mautrix_discord_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-discord 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mautrix-discord 2>/dev/null || true' + +# 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-discord \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_docker_network }} \ + --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 }} \ + {% endfor %} + {{ matrix_mautrix_discord_docker_image }} \ + /usr/bin/mautrix-discord -c /config/config.yaml -r /config/registration.yaml + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mautrix-discord 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mautrix-discord 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-mautrix-discord + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-bridge-mautrix-facebook/defaults/main.yml b/roles/matrix-bridge-mautrix-facebook/defaults/main.yml index d1469863..719c86dc 100644 --- a/roles/matrix-bridge-mautrix-facebook/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-facebook/defaults/main.yml @@ -1,6 +1,6 @@ --- # mautrix-facebook is a Matrix <-> Facebook bridge -# See: https://github.com/mautrix/facebook +# Project source code URL: https://github.com/mautrix/facebook matrix_mautrix_facebook_enabled: true @@ -17,6 +17,8 @@ matrix_mautrix_facebook_config_path: "{{ matrix_mautrix_facebook_base_path }}/co matrix_mautrix_facebook_data_path: "{{ matrix_mautrix_facebook_base_path }}/data" matrix_mautrix_facebook_docker_src_files_path: "{{ matrix_mautrix_facebook_base_path }}/docker-src" +matrix_mautrix_facebook_command_prefix: "!fb" + # Whether or not the public-facing endpoints should be enabled (web-based login) matrix_mautrix_facebook_appservice_public_enabled: true @@ -44,6 +46,12 @@ matrix_mautrix_facebook_homeserver_token: '' # If false, created portal rooms will never be federated. matrix_mautrix_facebook_federate_rooms: true +matrix_mautrix_facebook_bridge_permissions: | + {{ + {matrix_mautrix_facebook_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # Controls whether the matrix-mautrix-facebook container exposes its HTTP port. # # Takes an ":" or "" value (e.g. "127.0.0.1:9008"), or empty string to not expose. @@ -89,6 +97,9 @@ matrix_mautrix_facebook_appservice_bot_username: facebookbot matrix_mautrix_facebook_bridge_presence: true +# Specifies the default log level for all bridge loggers. +matrix_mautrix_facebook_logging_level: WARNING + # Default configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -105,11 +116,11 @@ matrix_mautrix_facebook_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_facebook_configuration_yaml`. -matrix_mautrix_facebook_configuration_extension: "{{ matrix_mautrix_facebook_configuration_extension_yaml|from_yaml if matrix_mautrix_facebook_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_facebook_configuration_extension: "{{ matrix_mautrix_facebook_configuration_extension_yaml | from_yaml if matrix_mautrix_facebook_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_facebook_configuration_yaml`. -matrix_mautrix_facebook_configuration: "{{ matrix_mautrix_facebook_configuration_yaml|from_yaml|combine(matrix_mautrix_facebook_configuration_extension, recursive=True) }}" +matrix_mautrix_facebook_configuration: "{{ matrix_mautrix_facebook_configuration_yaml | from_yaml | combine(matrix_mautrix_facebook_configuration_extension, recursive=True) }}" matrix_mautrix_facebook_registration_yaml: | id: facebook @@ -118,13 +129,13 @@ matrix_mautrix_facebook_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@facebook_.+:{{ matrix_mautrix_facebook_homeserver_domain|regex_escape }}$' + regex: '^@facebook_.+:{{ matrix_mautrix_facebook_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_facebook_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_facebook_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_facebook_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_facebook_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_facebook_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_facebook_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_facebook_registration: "{{ matrix_mautrix_facebook_registration_yaml|from_yaml }}" +matrix_mautrix_facebook_registration: "{{ matrix_mautrix_facebook_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/init.yml b/roles/matrix-bridge-mautrix-facebook/tasks/init.yml index 200e9846..c5eb58be 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/init.yml @@ -2,42 +2,46 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Mautrix-Facebook image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mautrix_facebook_container_image_self_build and matrix_mautrix_facebook_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-facebook.service'] }}" - when: matrix_mautrix_facebook_enabled|bool + when: matrix_mautrix_facebook_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_facebook_config_path }}/registration.yaml,dst=/matrix-mautrix-facebook-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_facebook_config_path }}/registration.yaml,dst=/matrix-mautrix-facebook-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-facebook-registration.yaml"] }} - when: matrix_mautrix_facebook_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-facebook-registration.yaml"] + }} + when: matrix_mautrix_facebook_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix Facebook's 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-facebook role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix Facebook proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_facebook_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_facebook_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-facebook:29319"; @@ -49,24 +53,24 @@ } - name: Register Mautrix Facebook proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_facebook_matrix_nginx_proxy_configuration] }} - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix Facebook bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_facebook_public_endpoint }}` URL endpoint to the matrix-mautrix-facebook container. You can expose the container's port using the `matrix_mautrix_facebook_container_http_host_bind_port` variable. - when: "not matrix_nginx_proxy_enabled|default(False)|bool" + when: "not matrix_nginx_proxy_enabled | default(False) | bool" tags: - always - when: matrix_mautrix_facebook_enabled|bool and matrix_mautrix_facebook_appservice_public_enabled|bool + when: matrix_mautrix_facebook_enabled | bool and matrix_mautrix_facebook_appservice_public_enabled | bool diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/main.yml b/roles/matrix-bridge-mautrix-facebook/tasks/main.yml index b6e65fe2..3ef2cb23 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_facebook_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_facebook_enabled | bool" tags: - setup-all - setup-mautrix-facebook -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_facebook_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_facebook_enabled | bool" tags: - setup-all - setup-mautrix-facebook -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_facebook_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_facebook_enabled | bool" tags: - setup-all - setup-mautrix-facebook diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml index 699ed88a..3e7d8f05 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml @@ -3,35 +3,37 @@ # 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-facebook role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_facebook_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_facebook_sqlite_database_path_local }}" register: matrix_mautrix_facebook_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_facebook_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_facebook_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_facebook_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-facebook.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_facebook_requires_restart: true - when: "matrix_mautrix_facebook_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_facebook_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_facebook_database_engine == 'postgres'" - name: Ensure Mautrix Facebook image is pulled @@ -47,7 +49,7 @@ until: result is not failed - name: Ensure Mautrix Facebook paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -58,10 +60,10 @@ - {path: "{{ matrix_mautrix_facebook_config_path }}", when: true} - {path: "{{ matrix_mautrix_facebook_data_path }}", when: true} - {path: "{{ matrix_mautrix_facebook_docker_src_files_path }}", when: "{{ matrix_mautrix_facebook_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Facebook repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_facebook_container_image_self_build_repo }}" dest: "{{ matrix_mautrix_facebook_docker_src_files_path }}" version: "{{ matrix_mautrix_facebook_docker_image.split(':')[1] }}" @@ -69,7 +71,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_facebook_git_pull_results - when: "matrix_mautrix_facebook_container_image_self_build|bool" + when: "matrix_mautrix_facebook_container_image_self_build | bool" - name: Ensure Mautrix Facebook Docker image is built docker_image: @@ -81,15 +83,15 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_facebook_docker_src_files_path }}" pull: true - when: "matrix_mautrix_facebook_container_image_self_build|bool" + when: "matrix_mautrix_facebook_container_image_self_build | bool" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db" register: matrix_mautrix_facebook_stat_database - name: (Data relocation) Ensure matrix-mautrix-facebook.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-facebook state: stopped enabled: false @@ -98,39 +100,39 @@ when: "matrix_mautrix_facebook_stat_database.stat.exists" - name: (Data relocation) Move mautrix-facebook database file to ./data directory - command: "mv {{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db {{ matrix_mautrix_facebook_data_path }}/mautrix-facebook.db" + ansible.builtin.command: "mv {{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db {{ matrix_mautrix_facebook_data_path }}/mautrix-facebook.db" when: "matrix_mautrix_facebook_stat_database.stat.exists" - name: Ensure mautrix-facebook config.yaml installed - copy: - content: "{{ matrix_mautrix_facebook_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_facebook_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_facebook_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-facebook registration.yaml installed - copy: - content: "{{ matrix_mautrix_facebook_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_facebook_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_facebook_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-facebook.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-facebook.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service" mode: 0644 register: matrix_mautrix_facebook_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-facebook.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_facebook_systemd_service_result.changed" - name: Ensure matrix-mautrix-facebook.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-facebook.service" state: restarted - when: "matrix_mautrix_facebook_requires_restart|bool" + when: "matrix_mautrix_facebook_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml index 1c8fbd3b..2635f1f5 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-facebook service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service" register: matrix_mautrix_facebook_service_stat - name: Ensure matrix-mautrix-facebook is stopped - service: + ansible.builtin.service: name: matrix-mautrix-facebook state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_facebook_service_stat.stat.exists" - name: Ensure matrix-mautrix-facebook.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service" state: absent when: "matrix_mautrix_facebook_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-facebook.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_facebook_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml index 7fcd6bea..4f588b5f 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -12,10 +12,10 @@ - block: - name: Inject warning if on an old SQLite-supporting version - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your mautrix-facebook bridge is still on SQLite and on the last version that supported it, before support was dropped. Support has been subsequently re-added in v0.3.2, so we advise you to upgrade (by removing your `matrix_mautrix_facebook_docker_image` definition from vars.yml)" diff --git a/roles/matrix-bridge-mautrix-facebook/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-facebook/templates/config.yaml.j2 index c3cb1932..3318255d 100644 --- a/roles/matrix-bridge-mautrix-facebook/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-facebook/templates/config.yaml.j2 @@ -86,7 +86,7 @@ bridge: - first_name # The prefix for commands. Only required in non-management rooms. - command_prefix: "!fb" + command_prefix: "{{ matrix_mautrix_facebook_command_prefix }}" # Number of chats to sync (and create portals for) on startup/login. # Set 0 to disable automatic syncing. @@ -201,8 +201,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - '{{ matrix_mautrix_facebook_homeserver_domain }}': user + permissions: {{ matrix_mautrix_facebook_bridge_permissions|to_json }} relay: # Whether relay mode should be allowed. If allowed, `!fb set-relay` can be used to turn any @@ -250,11 +249,11 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: {{ matrix_mautrix_facebook_logging_level|to_json }} paho: - level: INFO + level: {{ matrix_mautrix_facebook_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_facebook_logging_level|to_json }} root: - level: DEBUG + level: {{ matrix_mautrix_facebook_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml b/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml index e334e8d6..a4b1438b 100644 --- a/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml @@ -1,13 +1,14 @@ --- # mautrix-googlechat is a Matrix <-> googlechat bridge -# See: https://github.com/mautrix/googlechat +# Project source code URL: https://github.com/mautrix/googlechat matrix_mautrix_googlechat_enabled: true matrix_mautrix_googlechat_container_image_self_build: false matrix_mautrix_googlechat_container_image_self_build_repo: "https://github.com/mautrix/googlechat.git" +matrix_mautrix_googlechat_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_googlechat_version == 'latest' else matrix_mautrix_googlechat_version }}" -matrix_mautrix_googlechat_version: v0.3.1 +matrix_mautrix_googlechat_version: v0.3.3 # See: https://mau.dev/mautrix/googlechat/container_registry matrix_mautrix_googlechat_docker_image: "{{ matrix_mautrix_googlechat_docker_image_name_prefix }}mautrix/googlechat:{{ matrix_mautrix_googlechat_version }}" matrix_mautrix_googlechat_docker_image_name_prefix: "{{ 'localhost/' if matrix_mautrix_googlechat_container_image_self_build else 'dock.mau.dev/' }}" @@ -24,6 +25,8 @@ matrix_mautrix_googlechat_homeserver_address: "{{ matrix_homeserver_container_ur matrix_mautrix_googlechat_homeserver_domain: '{{ matrix_domain }}' matrix_mautrix_googlechat_appservice_address: 'http://matrix-mautrix-googlechat:8080' +matrix_mautrix_googlechat_command_prefix: "!gc" + # Controls whether the matrix-mautrix-googlechat container exposes its HTTP port (tcp/8080 in the container). # # Takes an ":" or "" value (e.g. "127.0.0.1:9007"), or empty string to not expose. @@ -45,6 +48,12 @@ matrix_mautrix_googlechat_homeserver_token: '' # If false, created portal rooms will never be federated. matrix_mautrix_googlechat_federate_rooms: true +matrix_mautrix_googlechat_bridge_permissions: | + {{ + {matrix_mautrix_googlechat_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # Database-related configuration fields. # # To use SQLite, stick to these defaults. @@ -78,6 +87,9 @@ matrix_mautrix_googlechat_login_shared_secret: '' matrix_mautrix_googlechat_appservice_bot_username: googlechatbot +# Specifies the default log level for all bridge loggers. +matrix_mautrix_googlechat_logging_level: WARNING + # Default configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -94,11 +106,11 @@ matrix_mautrix_googlechat_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_googlechat_configuration_yaml`. -matrix_mautrix_googlechat_configuration_extension: "{{ matrix_mautrix_googlechat_configuration_extension_yaml|from_yaml if matrix_mautrix_googlechat_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_googlechat_configuration_extension: "{{ matrix_mautrix_googlechat_configuration_extension_yaml | from_yaml if matrix_mautrix_googlechat_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_googlechat_configuration_yaml`. -matrix_mautrix_googlechat_configuration: "{{ matrix_mautrix_googlechat_configuration_yaml|from_yaml|combine(matrix_mautrix_googlechat_configuration_extension, recursive=True) }}" +matrix_mautrix_googlechat_configuration: "{{ matrix_mautrix_googlechat_configuration_yaml | from_yaml | combine(matrix_mautrix_googlechat_configuration_extension, recursive=True) }}" matrix_mautrix_googlechat_registration_yaml: | id: googlechat @@ -107,13 +119,13 @@ matrix_mautrix_googlechat_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@googlechat_.+:{{ matrix_mautrix_googlechat_homeserver_domain|regex_escape }}$' + regex: '^@googlechat_.+:{{ matrix_mautrix_googlechat_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_googlechat_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_googlechat_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_googlechat_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_googlechat_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_googlechat_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_googlechat_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_googlechat_registration: "{{ matrix_mautrix_googlechat_registration_yaml|from_yaml }}" +matrix_mautrix_googlechat_registration: "{{ matrix_mautrix_googlechat_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml index f458df1b..7f846526 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml @@ -2,42 +2,46 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Mautrix-Google Chat image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mautrix_googlechat_container_image_self_build and matrix_mautrix_googlechat_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-googlechat.service'] }}" - when: matrix_mautrix_googlechat_enabled|bool + when: matrix_mautrix_googlechat_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_googlechat_config_path }}/registration.yaml,dst=/matrix-mautrix-googlechat-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_googlechat_config_path }}/registration.yaml,dst=/matrix-mautrix-googlechat-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-googlechat-registration.yaml"] }} - when: matrix_mautrix_googlechat_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-googlechat-registration.yaml"] + }} + when: matrix_mautrix_googlechat_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix googlechat's 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-googlechat role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix googlechat proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_googlechat_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_googlechat_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-googlechat:8080"; @@ -48,23 +52,23 @@ {% endif %} } - name: Register Mautrix googlechat proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_googlechat_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mautrix_googlechat_enabled|bool + when: matrix_mautrix_googlechat_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix googlechat bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_googlechat_public_endpoint }}` URL endpoint to the matrix-mautrix-googlechat container. You can expose the container's port using the `matrix_mautrix_googlechat_container_http_host_bind_port` variable. - when: "matrix_mautrix_googlechat_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mautrix_googlechat_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml index 16054e7b..070abfcd 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_googlechat_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_googlechat_enabled | bool" tags: - setup-all - setup-mautrix-googlechat -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_googlechat_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_googlechat_enabled | bool" tags: - setup-all - setup-mautrix-googlechat -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_googlechat_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_googlechat_enabled | bool" tags: - setup-all - setup-mautrix-googlechat diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml index bf04e834..f2192a34 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml @@ -3,35 +3,37 @@ # 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-googlechat role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_googlechat_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}" register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_googlechat_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_googlechat_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-googlechat.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_googlechat_requires_restart: true - when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_googlechat_database_engine == 'postgres'" - name: Ensure Mautrix googlechat image is pulled @@ -47,7 +49,7 @@ until: result is not failed - name: Ensure Mautrix googlechat paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -58,17 +60,18 @@ - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true} - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true} - {path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Mautrix Hangots repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_googlechat_git_pull_results - when: "matrix_mautrix_googlechat_container_image_self_build|bool" + when: "matrix_mautrix_googlechat_container_image_self_build | bool" - name: Ensure Mautrix googlechat Docker image is built docker_image: @@ -80,15 +83,15 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}" pull: true - when: "matrix_mautrix_googlechat_container_image_self_build|bool" + when: "matrix_mautrix_googlechat_container_image_self_build | bool" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db" register: matrix_mautrix_googlechat_stat_database - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-googlechat state: stopped enabled: false @@ -97,39 +100,39 @@ when: "matrix_mautrix_googlechat_stat_database.stat.exists" - name: (Data relocation) Move mautrix-googlechat database file to ./data directory - command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db" + ansible.builtin.command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db" when: "matrix_mautrix_googlechat_stat_database.stat.exists" - name: Ensure mautrix-googlechat config.yaml installed - copy: - content: "{{ matrix_mautrix_googlechat_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-googlechat registration.yaml installed - copy: - content: "{{ matrix_mautrix_googlechat_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-googlechat.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service" mode: 0644 register: matrix_mautrix_googlechat_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_googlechat_systemd_service_result.changed" - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-googlechat.service" state: restarted - when: "matrix_mautrix_googlechat_requires_restart|bool" + when: "matrix_mautrix_googlechat_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml index a315c0c8..104e58a5 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-googlechat service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service" register: matrix_mautrix_googlechat_service_stat - name: Ensure matrix-mautrix-googlechat is stopped - service: + ansible.builtin.service: name: matrix-mautrix-googlechat state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_googlechat_service_stat.stat.exists" - name: Ensure matrix-mautrix-googlechat.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service" state: absent when: "matrix_mautrix_googlechat_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_googlechat_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml index 083e8d34..fc36472e 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -9,6 +9,6 @@ - "matrix_mautrix_googlechat_public_endpoint" - "matrix_mautrix_googlechat_appservice_token" - "matrix_mautrix_googlechat_homeserver_token" -- debug: +- ansible.builtin.debug: msg: - '`matrix_mautrix_googlechat_homeserver_domain` == {{ matrix_mautrix_googlechat_homeserver_domain }}' diff --git a/roles/matrix-bridge-mautrix-googlechat/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-googlechat/templates/config.yaml.j2 index e2af8830..a2560a9f 100644 --- a/roles/matrix-bridge-mautrix-googlechat/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-googlechat/templates/config.yaml.j2 @@ -62,7 +62,7 @@ bridge: - name # The prefix for commands. Only required in non-management rooms. - command_prefix: "!HO" + command_prefix: "{{ matrix_mautrix_googlechat_command_prefix }}" # Number of chats to sync (and create portals for) on startup/login. # Maximum 20, set 0 to disable automatic syncing. @@ -117,8 +117,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - '{{ matrix_mautrix_googlechat_homeserver_domain }}': user + permissions: {{ matrix_mautrix_googlechat_bridge_permissions|to_json }} # Python logging configuration. # @@ -138,11 +137,11 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: {{ matrix_mautrix_googlechat_logging_level|to_json }} hangups: - level: DEBUG + level: {{ matrix_mautrix_googlechat_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_googlechat_logging_level|to_json }} root: - level: DEBUG + level: {{ matrix_mautrix_googlechat_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml b/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml index 911c81c6..8b338fd7 100644 --- a/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml @@ -1,11 +1,12 @@ --- # mautrix-hangouts is a Matrix <-> Hangouts bridge -# See: https://github.com/mautrix/hangouts +# Project source code URL: https://github.com/mautrix/hangouts matrix_mautrix_hangouts_enabled: true matrix_mautrix_hangouts_container_image_self_build: false matrix_mautrix_hangouts_container_image_self_build_repo: "https://github.com/mautrix/hangouts.git" +matrix_mautrix_hangouts_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_hangouts_version == 'latest' else matrix_mautrix_googlechat_version }}" matrix_mautrix_hangouts_version: latest # See: https://mau.dev/mautrix/hangouts/container_registry @@ -24,6 +25,14 @@ matrix_mautrix_hangouts_homeserver_address: "{{ matrix_homeserver_container_url matrix_mautrix_hangouts_homeserver_domain: '{{ matrix_domain }}' matrix_mautrix_hangouts_appservice_address: 'http://matrix-mautrix-hangouts:8080' +matrix_mautrix_hangouts_command_prefix: "!HO" + +matrix_mautrix_hangouts_bridge_permissions: | + {{ + {matrix_mautrix_hangouts_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # Controls whether the matrix-mautrix-hangouts container exposes its HTTP port (tcp/8080 in the container). # # Takes an ":" or "" value (e.g. "127.0.0.1:9007"), or empty string to not expose. @@ -75,6 +84,9 @@ matrix_mautrix_hangouts_login_shared_secret: '' matrix_mautrix_hangouts_appservice_bot_username: hangoutsbot +# Specifies the default log level for all bridge loggers. +matrix_mautrix_hangouts_logging_level: WARNING + # Default configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -91,11 +103,11 @@ matrix_mautrix_hangouts_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_hangouts_configuration_yaml`. -matrix_mautrix_hangouts_configuration_extension: "{{ matrix_mautrix_hangouts_configuration_extension_yaml|from_yaml if matrix_mautrix_hangouts_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_hangouts_configuration_extension: "{{ matrix_mautrix_hangouts_configuration_extension_yaml | from_yaml if matrix_mautrix_hangouts_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_hangouts_configuration_yaml`. -matrix_mautrix_hangouts_configuration: "{{ matrix_mautrix_hangouts_configuration_yaml|from_yaml|combine(matrix_mautrix_hangouts_configuration_extension, recursive=True) }}" +matrix_mautrix_hangouts_configuration: "{{ matrix_mautrix_hangouts_configuration_yaml | from_yaml | combine(matrix_mautrix_hangouts_configuration_extension, recursive=True) }}" matrix_mautrix_hangouts_registration_yaml: | id: hangouts @@ -104,13 +116,13 @@ matrix_mautrix_hangouts_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@hangouts_.+:{{ matrix_mautrix_hangouts_homeserver_domain|regex_escape }}$' + regex: '^@hangouts_.+:{{ matrix_mautrix_hangouts_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_hangouts_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_hangouts_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_hangouts_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_hangouts_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_hangouts_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_hangouts_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_hangouts_registration: "{{ matrix_mautrix_hangouts_registration_yaml|from_yaml }}" +matrix_mautrix_hangouts_registration: "{{ matrix_mautrix_hangouts_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml index 680dcd88..8ad9bc02 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml @@ -2,42 +2,46 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Mautrix-Hangouts image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mautrix_hangouts_container_image_self_build and matrix_mautrix_hangouts_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-hangouts.service'] }}" - when: matrix_mautrix_hangouts_enabled|bool + when: matrix_mautrix_hangouts_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_hangouts_config_path }}/registration.yaml,dst=/matrix-mautrix-hangouts-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_hangouts_config_path }}/registration.yaml,dst=/matrix-mautrix-hangouts-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-hangouts-registration.yaml"] }} - when: matrix_mautrix_hangouts_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-hangouts-registration.yaml"] + }} + when: matrix_mautrix_hangouts_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix Hangouts's 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-hangouts role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix Hangouts proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_hangouts_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_hangouts_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-hangouts:8080"; @@ -48,23 +52,23 @@ {% endif %} } - name: Register Mautrix Hangouts proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_hangouts_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mautrix_hangouts_enabled|bool + when: matrix_mautrix_hangouts_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix Hangouts bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_hangouts_public_endpoint }}` URL endpoint to the matrix-mautrix-hangouts container. You can expose the container's port using the `matrix_mautrix_hangouts_container_http_host_bind_port` variable. - when: "matrix_mautrix_hangouts_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mautrix_hangouts_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml index b43ff478..d6913689 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_hangouts_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_hangouts_enabled | bool" tags: - setup-all - setup-mautrix-hangouts -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_hangouts_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_hangouts_enabled | bool" tags: - setup-all - setup-mautrix-hangouts -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_hangouts_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_hangouts_enabled | bool" tags: - setup-all - setup-mautrix-hangouts diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml index 6a880815..4087162e 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml @@ -3,35 +3,37 @@ # 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-hangouts role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_hangouts_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_hangouts_sqlite_database_path_local }}" register: matrix_mautrix_hangouts_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_hangouts_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_hangouts_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_hangouts_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-hangouts.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_hangouts_requires_restart: true - when: "matrix_mautrix_hangouts_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_hangouts_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_hangouts_database_engine == 'postgres'" - name: Ensure Mautrix Hangouts image is pulled @@ -47,7 +49,7 @@ until: result is not failed - name: Ensure Mautrix Hangouts paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -58,17 +60,18 @@ - {path: "{{ matrix_mautrix_hangouts_config_path }}", when: true} - {path: "{{ matrix_mautrix_hangouts_data_path }}", when: true} - {path: "{{ matrix_mautrix_hangouts_docker_src_files_path }}", when: "{{ matrix_mautrix_hangouts_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Mautrix Hangots repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_hangouts_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_hangouts_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_hangouts_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_hangouts_git_pull_results - when: "matrix_mautrix_hangouts_container_image_self_build|bool" + when: "matrix_mautrix_hangouts_container_image_self_build | bool" - name: Ensure Mautrix Hangouts Docker image is built docker_image: @@ -80,15 +83,15 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_hangouts_docker_src_files_path }}" pull: true - when: "matrix_mautrix_hangouts_container_image_self_build|bool" + when: "matrix_mautrix_hangouts_container_image_self_build | bool" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db" register: matrix_mautrix_hangouts_stat_database - name: (Data relocation) Ensure matrix-mautrix-hangouts.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-hangouts state: stopped enabled: false @@ -97,39 +100,39 @@ when: "matrix_mautrix_hangouts_stat_database.stat.exists" - name: (Data relocation) Move mautrix-hangouts database file to ./data directory - command: "mv {{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db {{ matrix_mautrix_hangouts_data_path }}/mautrix-hangouts.db" + ansible.builtin.command: "mv {{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db {{ matrix_mautrix_hangouts_data_path }}/mautrix-hangouts.db" when: "matrix_mautrix_hangouts_stat_database.stat.exists" - name: Ensure mautrix-hangouts config.yaml installed - copy: - content: "{{ matrix_mautrix_hangouts_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_hangouts_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_hangouts_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-hangouts registration.yaml installed - copy: - content: "{{ matrix_mautrix_hangouts_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_hangouts_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_hangouts_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-hangouts.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-hangouts.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-hangouts.service" mode: 0644 register: matrix_mautrix_hangouts_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-hangouts.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_hangouts_systemd_service_result.changed" - name: Ensure matrix-mautrix-hangouts.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-hangouts.service" state: restarted - when: "matrix_mautrix_hangouts_requires_restart|bool" + when: "matrix_mautrix_hangouts_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml index 8ce859c8..2cb676b5 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-hangouts service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-hangouts.service" register: matrix_mautrix_hangouts_service_stat - name: Ensure matrix-mautrix-hangouts is stopped - service: + ansible.builtin.service: name: matrix-mautrix-hangouts state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_hangouts_service_stat.stat.exists" - name: Ensure matrix-mautrix-hangouts.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-hangouts.service" state: absent when: "matrix_mautrix_hangouts_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-hangouts.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_hangouts_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml index 0242ef16..c80586e0 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -9,6 +9,6 @@ - "matrix_mautrix_hangouts_public_endpoint" - "matrix_mautrix_hangouts_appservice_token" - "matrix_mautrix_hangouts_homeserver_token" -- debug: +- ansible.builtin.debug: msg: - '`matrix_mautrix_hangouts_homeserver_domain` == {{ matrix_mautrix_hangouts_homeserver_domain }}' diff --git a/roles/matrix-bridge-mautrix-hangouts/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-hangouts/templates/config.yaml.j2 index 7ff7d539..d737f3f1 100644 --- a/roles/matrix-bridge-mautrix-hangouts/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-hangouts/templates/config.yaml.j2 @@ -62,7 +62,7 @@ bridge: - name # The prefix for commands. Only required in non-management rooms. - command_prefix: "!HO" + command_prefix: "{{ matrix_mautrix_hangouts_command_prefix }}" # Number of chats to sync (and create portals for) on startup/login. # Maximum 20, set 0 to disable automatic syncing. @@ -114,8 +114,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - '{{ matrix_mautrix_hangouts_homeserver_domain }}': user + permissions: {{ matrix_mautrix_hangouts_bridge_permissions|to_json }} # Python logging configuration. # @@ -135,11 +134,11 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: {{ matrix_mautrix_hangouts_logging_level|to_json }} hangups: - level: DEBUG + level: {{ matrix_mautrix_hangouts_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_hangouts_logging_level|to_json }} root: - level: DEBUG + level: {{ matrix_mautrix_hangouts_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-instagram/defaults/main.yml b/roles/matrix-bridge-mautrix-instagram/defaults/main.yml index 4ae2d374..bcb6ddb1 100644 --- a/roles/matrix-bridge-mautrix-instagram/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-instagram/defaults/main.yml @@ -1,11 +1,12 @@ --- # mautrix-instagram is a Matrix <-> Instagram bridge -# See: https://github.com/mautrix/instagram +# Project source code URL: https://github.com/mautrix/instagram matrix_mautrix_instagram_enabled: true matrix_mautrix_instagram_container_image_self_build: false matrix_mautrix_instagram_container_image_self_build_repo: "https://github.com/mautrix/instagram.git" +matrix_mautrix_instagram_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_instagram_version == 'latest' else matrix_mautrix_instagram_version }}" matrix_mautrix_instagram_version: v0.1.3 # See: https://mau.dev/tulir/mautrix-instagram/container_registry @@ -22,6 +23,14 @@ matrix_mautrix_instagram_homeserver_address: "{{ matrix_homeserver_container_url matrix_mautrix_instagram_homeserver_domain: '{{ matrix_domain }}' matrix_mautrix_instagram_appservice_address: 'http://matrix-mautrix-instagram:29330' +matrix_mautrix_instagram_command_prefix: "!ig" + +matrix_mautrix_instagram_bridge_permissions: | + {{ + {matrix_mautrix_instagram_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # A list of extra arguments to pass to the container matrix_mautrix_instagram_container_extra_arguments: [] @@ -68,6 +77,9 @@ matrix_mautrix_instagram_appservice_bot_username: instagrambot matrix_mautrix_instagram_bridge_presence: true +# Specifies the default log level for all bridge loggers. +matrix_mautrix_instagram_logging_level: WARNING + # Default configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -84,11 +96,11 @@ matrix_mautrix_instagram_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_instagram_configuration_yaml`. -matrix_mautrix_instagram_configuration_extension: "{{ matrix_mautrix_instagram_configuration_extension_yaml|from_yaml if matrix_mautrix_instagram_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_instagram_configuration_extension: "{{ matrix_mautrix_instagram_configuration_extension_yaml | from_yaml if matrix_mautrix_instagram_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_instagram_configuration_yaml`. -matrix_mautrix_instagram_configuration: "{{ matrix_mautrix_instagram_configuration_yaml|from_yaml|combine(matrix_mautrix_instagram_configuration_extension, recursive=True) }}" +matrix_mautrix_instagram_configuration: "{{ matrix_mautrix_instagram_configuration_yaml | from_yaml | combine(matrix_mautrix_instagram_configuration_extension, recursive=True) }}" matrix_mautrix_instagram_registration_yaml: | id: instagram @@ -97,13 +109,13 @@ matrix_mautrix_instagram_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@instagram_.+:{{ matrix_mautrix_instagram_homeserver_domain|regex_escape }}$' + regex: '^@instagram_.+:{{ matrix_mautrix_instagram_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_instagram_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_instagram_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_instagram_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_instagram_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_instagram_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_instagram_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_instagram_registration: "{{ matrix_mautrix_instagram_registration_yaml|from_yaml }}" +matrix_mautrix_instagram_registration: "{{ matrix_mautrix_instagram_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/init.yml b/roles/matrix-bridge-mautrix-instagram/tasks/init.yml index d33acd09..5a78afed 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/init.yml @@ -2,23 +2,27 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Mautrix-Instagram image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mautrix_instagram_container_image_self_build and matrix_mautrix_instagram_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-instagram.service'] }}" - when: matrix_mautrix_instagram_enabled|bool + when: matrix_mautrix_instagram_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_instagram_config_path }}/registration.yaml,dst=/matrix-mautrix-instagram-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_instagram_config_path }}/registration.yaml,dst=/matrix-mautrix-instagram-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-instagram-registration.yaml"] }} - when: matrix_mautrix_instagram_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-instagram-registration.yaml"] + }} + when: matrix_mautrix_instagram_enabled | bool diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/main.yml b/roles/matrix-bridge-mautrix-instagram/tasks/main.yml index b6ffcd06..d5becb6d 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_instagram_enabled | bool" tags: - setup-all - setup-mautrix-instagram -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_instagram_enabled | bool" tags: - setup-all - setup-mautrix-instagram -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_instagram_enabled | bool" tags: - setup-all - setup-mautrix-instagram diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml index 5e30adbe..88b0286e 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml @@ -2,10 +2,10 @@ # 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-instagram role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure Mautrix instagram image is pulled docker_image: @@ -20,7 +20,7 @@ until: result is not failed - name: Ensure Mautrix instagram paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -31,17 +31,18 @@ - {path: "{{ matrix_mautrix_instagram_config_path }}", when: true} - {path: "{{ matrix_mautrix_instagram_data_path }}", when: true} - {path: "{{ matrix_mautrix_instagram_docker_src_files_path }}", when: "{{ matrix_mautrix_instagram_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix instagram repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_instagram_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_instagram_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_instagram_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_instagram_git_pull_results - when: "matrix_mautrix_instagram_container_image_self_build|bool" + when: "matrix_mautrix_instagram_container_image_self_build | bool" - name: Ensure Mautrix instagram Docker image is built docker_image: @@ -53,32 +54,32 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_instagram_docker_src_files_path }}" pull: true - when: "matrix_mautrix_instagram_container_image_self_build|bool" + when: "matrix_mautrix_instagram_container_image_self_build | bool" - name: Ensure mautrix-instagram config.yaml installed - copy: - content: "{{ matrix_mautrix_instagram_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_instagram_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_instagram_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-instagram registration.yaml installed - copy: - content: "{{ matrix_mautrix_instagram_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_instagram_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_instagram_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-instagram.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-instagram.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-instagram.service" mode: 0644 register: matrix_mautrix_instagram_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-instagram.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_instagram_systemd_service_result.changed" diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml index 2cc0e0e9..55d882d3 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml @@ -1,11 +1,11 @@ --- - name: Check existence of matrix-mautrix-instagram service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-instagram.service" register: matrix_mautrix_instagram_service_stat - name: Ensure matrix-mautrix-instagram is stopped - service: + ansible.builtin.service: name: matrix-mautrix-instagram state: stopped enabled: false @@ -13,12 +13,12 @@ when: "matrix_mautrix_instagram_service_stat.stat.exists" - name: Ensure matrix-mautrix-instagram.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-instagram.service" state: absent when: "matrix_mautrix_instagram_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-instagram.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_instagram_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml index 24992ff5..99f7b015 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mautrix-instagram/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-instagram/templates/config.yaml.j2 index cb74d5c1..039b9bfe 100644 --- a/roles/matrix-bridge-mautrix-instagram/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-instagram/templates/config.yaml.j2 @@ -135,7 +135,7 @@ bridge: # Whether or not the bridge should backfill chats when reconnecting. resync: true # Should even disconnected users be reconnected? - always: false + always: false # End-to-bridge encryption support options. These require matrix-nio to be installed with pip # and login_shared_secret to be configured in order to get a device for the bridge bot. # @@ -166,7 +166,7 @@ bridge: # been sent to Instagram. delivery_receipts: false # Whether or not delivery errors should be reported as messages in the Matrix room. - delivery_error_reports: false + delivery_error_reports: true # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. # This field will automatically be changed back to false after it, # except if the config file is not writable. @@ -176,7 +176,7 @@ bridge: unimportant_bridge_notices: true # The prefix for commands. Only required in non-management rooms. - command_prefix: "!ig" + command_prefix: "{{ matrix_mautrix_instagram_command_prefix }}" # Permissions for using the bridge. # Permitted values: # user - Use the bridge with puppeting. @@ -185,8 +185,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - "{{ matrix_mautrix_instagram_homeserver_domain }}": user + permissions: {{ matrix_mautrix_instagram_bridge_permissions|to_json }} # Provisioning API part of the web server for automated portal creation and fetching information. # Used by things like mautrix-manager (https://github.com/tulir/mautrix-manager). provisioning: @@ -216,13 +215,13 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: {{ matrix_mautrix_instagram_logging_level|to_json }} mauigpapi: - level: DEBUG + level: {{ matrix_mautrix_instagram_logging_level|to_json }} paho: - level: INFO + level: {{ matrix_mautrix_instagram_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_instagram_logging_level|to_json }} root: - level: DEBUG + level: {{ matrix_mautrix_instagram_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-signal/defaults/main.yml b/roles/matrix-bridge-mautrix-signal/defaults/main.yml index 4e95f1f9..bdef7fa5 100644 --- a/roles/matrix-bridge-mautrix-signal/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-signal/defaults/main.yml @@ -1,25 +1,28 @@ --- # mautrix-signal is a Matrix <-> Signal bridge -# See: https://github.com/mautrix/signal +# Project source code URL: https://github.com/mautrix/signal matrix_mautrix_signal_enabled: true matrix_mautrix_signal_container_image_self_build: false matrix_mautrix_signal_docker_repo: "https://mau.dev/mautrix/signal.git" +matrix_mautrix_signal_docker_repo_version: "{{ 'master' if matrix_mautrix_signal_version == 'latest' else matrix_mautrix_signal_version }}" matrix_mautrix_signal_docker_src_files_path: "{{ matrix_base_data_path }}/mautrix-signal/docker-src" -matrix_mautrix_signal_version: v0.2.3 -matrix_mautrix_signal_daemon_version: 0.17.0 +matrix_mautrix_signal_version: v0.3.0 +matrix_mautrix_signal_daemon_version: 0.20.0 # See: https://mau.dev/mautrix/signal/container_registry matrix_mautrix_signal_docker_image: "dock.mau.dev/mautrix/signal:{{ matrix_mautrix_signal_version }}" matrix_mautrix_signal_docker_image_force_pull: "{{ matrix_mautrix_signal_docker_image.endswith(':latest') }}" matrix_mautrix_signal_daemon_container_image_self_build: false -matrix_mautrix_signal_daemon_docker_repo: "https://mau.dev/maunium/signald.git" +matrix_mautrix_signal_daemon_docker_repo: "https://gitlab.com/signald/signald" +matrix_mautrix_signal_daemon_docker_repo_version: "{{ 'master' if matrix_mautrix_signal_daemon_version == 'latest' else matrix_mautrix_signal_daemon_version }}" matrix_mautrix_signal_daemon_docker_src_files_path: "{{ matrix_base_data_path }}/mautrix-signald/docker-src" -matrix_mautrix_signal_daemon_docker_image: "docker.io/signald/signald:{{ matrix_mautrix_signal_daemon_version }}" -matrix_mautrix_signal_daemon_docker_image_force_pull: "{{ matrix_mautrix_signal_daemon_docker_image.endswith(':latest') }}" +matrix_mautrix_signal_daemon_docker_image: "docker.io/signald/signald:{{ matrix_mautrix_signal_daemon_docker_image_tag }}" +matrix_mautrix_signal_daemon_docker_image_force_pull: "{{ matrix_mautrix_signal_daemon_docker_image_tag.endswith(':latest') }}" +matrix_mautrix_signal_daemon_docker_image_tag: "{{ matrix_mautrix_signal_daemon_version }}" matrix_mautrix_signal_base_path: "{{ matrix_base_data_path }}/mautrix-signal" matrix_mautrix_signal_config_path: "{{ matrix_mautrix_signal_base_path }}/bridge" @@ -29,6 +32,8 @@ matrix_mautrix_signal_homeserver_address: '' matrix_mautrix_signal_homeserver_domain: '' matrix_mautrix_signal_appservice_address: 'http://matrix-mautrix-signal:29328' +matrix_mautrix_signal_command_prefix: "!signal" + # Controls whether the matrix-mautrix-signal container exposes its port (tcp/29328 in the container). # # Takes an ":" or "" value (e.g. "127.0.0.1:9006"), or empty string to not expose. @@ -56,6 +61,9 @@ matrix_mautrix_signal_homeserver_token: '' matrix_mautrix_signal_appservice_bot_username: signalbot +# Specifies the default log level for all bridge loggers. +matrix_mautrix_signal_logging_level: WARNING + # Whether or not created rooms should have federation enabled. # If false, created portal rooms will never be federated. matrix_mautrix_signal_federate_rooms: true @@ -95,9 +103,14 @@ matrix_mautrix_signal_relaybot_enabled: false # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user +# +# This variable used to contain a YAML string, but now needs to contain a hashmap/dictionary. matrix_mautrix_signal_bridge_permissions: | - '*': relay - '{{ matrix_mautrix_signal_homeserver_domain }}': user + {{ + {'*': 'relay'} + | combine({matrix_mautrix_signal_homeserver_domain: 'user'}) + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} # Default configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -115,14 +128,25 @@ matrix_mautrix_signal_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_signal_configuration_yaml`. -matrix_mautrix_signal_configuration_extension: "{{ matrix_mautrix_signal_configuration_extension_yaml|from_yaml if matrix_mautrix_signal_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_signal_configuration_extension: "{{ matrix_mautrix_signal_configuration_extension_yaml | from_yaml if matrix_mautrix_signal_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_signal_configuration_yaml`. -matrix_mautrix_signal_configuration: "{{ matrix_mautrix_signal_configuration_yaml|from_yaml|combine(matrix_mautrix_signal_configuration_extension, recursive=True) }}" +matrix_mautrix_signal_configuration: "{{ matrix_mautrix_signal_configuration_yaml | from_yaml | combine(matrix_mautrix_signal_configuration_extension, recursive=True) }}" matrix_mautrix_signal_registration_yaml: "{{ lookup('template', 'templates/registration.yaml.j2') }}" -matrix_mautrix_signal_registration: "{{ matrix_mautrix_signal_registration_yaml|from_yaml }}" +matrix_mautrix_signal_registration: "{{ matrix_mautrix_signal_registration_yaml | from_yaml }}" matrix_mautrix_signal_log_level: 'DEBUG' + +matrix_mautrix_signal_bridge_encryption_allow: false +matrix_mautrix_signal_bridge_encryption_default: "{{ matrix_mautrix_signal_bridge_encryption_allow }}" +matrix_mautrix_signal_bridge_encryption_key_sharing_allow: "{{ matrix_mautrix_signal_bridge_encryption_allow }}" + +# Additional environment variables to pass to the Signal Daemon container +# +# Example: +# matrix_mautrix_signal_daemon_environment_variables_extension: | +# SIGNALD_TRUST_NEW_KEYS=true +matrix_mautrix_signal_daemon_environment_variables_extension: '' diff --git a/roles/matrix-bridge-mautrix-signal/tasks/init.yml b/roles/matrix-bridge-mautrix-signal/tasks/init.yml index 21d52066..c96fe596 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/init.yml @@ -1,18 +1,22 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-signal.service', 'matrix-mautrix-signal-daemon.service'] }}" - when: matrix_mautrix_signal_enabled|bool + when: matrix_mautrix_signal_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_signal_config_path }}/registration.yaml,dst=/matrix-mautrix-signal-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_signal_config_path }}/registration.yaml,dst=/matrix-mautrix-signal-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-signal-registration.yaml"] }} - when: matrix_mautrix_signal_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-signal-registration.yaml"] + }} + when: matrix_mautrix_signal_enabled | bool diff --git a/roles/matrix-bridge-mautrix-signal/tasks/main.yml b/roles/matrix-bridge-mautrix-signal/tasks/main.yml index 643b94c9..54bdafcd 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_signal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_signal_enabled | bool" tags: - setup-all - setup-mautrix-signal -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_signal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_signal_enabled | bool" tags: - setup-all - setup-mautrix-signal -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_signal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_signal_enabled | bool" tags: - setup-all - setup-mautrix-signal diff --git a/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml index c7202f05..cfc704a8 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml @@ -3,10 +3,10 @@ # 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-signal role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure Mautrix Signal image is pulled docker_image: @@ -14,7 +14,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_signal_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_signal_docker_image_force_pull }}" - when: "not matrix_mautrix_signal_container_image_self_build|bool" + when: "not matrix_mautrix_signal_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -22,14 +22,15 @@ - name: Ensure Mautrix Signal repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_signal_docker_repo }}" + version: "{{ matrix_mautrix_signal_docker_repo_version }}" dest: "{{ matrix_mautrix_signal_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_signal_git_pull_results - when: "matrix_mautrix_signal_container_image_self_build|bool" + when: "matrix_mautrix_signal_container_image_self_build | bool" - name: Ensure Mautrix Signal image is built docker_image: @@ -41,7 +42,7 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_signal_docker_src_files_path }}" pull: true - when: "matrix_mautrix_signal_container_image_self_build|bool" + when: "matrix_mautrix_signal_container_image_self_build | bool" - name: Ensure Mautrix Signal Daemon image is pulled @@ -50,18 +51,19 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_signal_daemon_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_signal_daemon_docker_image_force_pull }}" - when: matrix_mautrix_signal_enabled and not matrix_mautrix_signal_daemon_container_image_self_build|bool + when: matrix_mautrix_signal_enabled and not matrix_mautrix_signal_daemon_container_image_self_build | bool register: matrix_mautrix_signal_daemon_pull_results - name: Ensure Mautrix Signal Daemon repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_signal_daemon_docker_repo }}" + version: "{{ matrix_mautrix_signal_daemon_docker_repo_version }}" dest: "{{ matrix_mautrix_signal_daemon_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_signal_daemon_git_pull_results - when: "matrix_mautrix_signal_daemon_container_image_self_build|bool" + when: "matrix_mautrix_signal_daemon_container_image_self_build | bool" - name: Ensure Mautrix Signal Daemon image is built docker_image: @@ -70,13 +72,13 @@ force_source: "{{ matrix_mautrix_signal_daemon_git_pull_results.changed 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_signal_daemon_git_pull_results.changed }}" build: - dockerfile: Dockerfile + dockerfile: Containerfile path: "{{ matrix_mautrix_signal_daemon_docker_src_files_path }}" pull: true - when: "matrix_mautrix_signal_daemon_container_image_self_build|bool" + when: "matrix_mautrix_signal_daemon_container_image_self_build | bool" - name: Ensure Mautrix Signal paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -90,37 +92,46 @@ - "{{ matrix_mautrix_signal_daemon_path }}/attachments" - "{{ matrix_mautrix_signal_daemon_path }}/data" + +- name: Ensure mautrix-signal-daemon environment variables file created + ansible.builtin.template: + src: "{{ role_path }}/templates/env.j2" + dest: "{{ matrix_mautrix_signal_daemon_path }}/env" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: 0644 + - name: Ensure mautrix-signal config.yaml installed - copy: - content: "{{ matrix_mautrix_signal_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_signal_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_signal_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-signal registration.yaml installed - copy: - content: "{{ matrix_mautrix_signal_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_signal_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_signal_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-signal-daemon.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-signal-daemon.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-signal-daemon.service" mode: 0644 register: matrix_mautrix_signal_daemon_systemd_service_result - name: Ensure matrix-mautrix-signal.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-signal.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-signal.service" mode: 0644 register: matrix_mautrix_signal_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-signal.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_signal_systemd_service_result.changed or matrix_mautrix_signal_daemon_systemd_service_result.changed" diff --git a/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml index 8ca2be3f..befbcbec 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml @@ -2,12 +2,12 @@ # Signal daemon service - name: Check existence of matrix-mautrix-signal-daemon service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal-daemon.service" register: matrix_mautrix_signal_daemon_service_stat - name: Ensure matrix-mautrix-signal-daemon is stopped - service: + ansible.builtin.service: name: matrix-mautrix-signal-daemon state: stopped enabled: false @@ -15,19 +15,19 @@ when: "matrix_mautrix_signal_daemon_service_stat.stat.exists" - name: Ensure matrix-mautrix-signal-daemon.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal-daemon.service" state: absent when: "matrix_mautrix_signal_daemon_service_stat.stat.exists" # Bridge service - name: Check existence of matrix-mautrix-signal service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal.service" register: matrix_mautrix_signal_service_stat - name: Ensure matrix-mautrix-signal is stopped - service: + ansible.builtin.service: name: matrix-mautrix-signal state: stopped enabled: false @@ -35,13 +35,13 @@ when: "matrix_mautrix_signal_service_stat.stat.exists" - name: Ensure matrix-mautrix-signal.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal.service" state: absent when: "matrix_mautrix_signal_service_stat.stat.exists" # All services - name: Ensure systemd reloaded after matrix-mautrix-signal_X.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_signal_service_stat.stat.exists or matrix_mautrix_signal_daemon_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml index 108ac044..ea2c1c43 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -11,8 +11,17 @@ - "matrix_mautrix_signal_homeserver_token" - "matrix_mautrix_signal_appservice_token" +- name: (Deprecation) Fail if matrix_mautrix_signal_bridge_permissions specified as YAML string, instead of a dictionary + ansible.builtin.fail: + msg: >- + The `matrix_mautrix_signal_bridge_permissions` variable in your configuration is specified as a YAML string. + The playbook now expects a hashmap/dictionary in this variable. + Change your configuration like this: + matrix_mautrix_signal_bridge_permissions: {{ matrix_mautrix_signal_bridge_permissions | from_yaml | to_json }} + when: "matrix_mautrix_signal_bridge_permissions is string" + - name: (Deprecation) Catch and report renamed Signal variables - fail: + 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 }}`). diff --git a/roles/matrix-bridge-mautrix-signal/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-signal/templates/config.yaml.j2 index 2f427b90..796a6e41 100644 --- a/roles/matrix-bridge-mautrix-signal/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-signal/templates/config.yaml.j2 @@ -152,15 +152,15 @@ bridge: # this to work. See https://github.com/tulir/mautrix-telegram/wiki/End‐to‐bridge-encryption encryption: # Allow encryption, work in group chat rooms with e2ee enabled - allow: false + allow: {{ matrix_mautrix_signal_bridge_encryption_allow|to_json }} # Default to encryption, force-enable encryption in all portals the bridge creates # This will cause the bridge bot to be in private chats for the encryption to work properly. - default: false + default: {{ matrix_mautrix_signal_bridge_encryption_default|to_json }} # Options for automatic key sharing. key_sharing: # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. # You must use a client that supports requesting keys from other users to use this feature. - allow: false + allow: {{ matrix_mautrix_signal_bridge_encryption_key_sharing_allow|to_json }} # Require the requesting device to have a valid cross-signing signature? # This doesn't require that the bridge has verified the device, only that the user has verified it. # Not yet implemented. @@ -177,7 +177,7 @@ bridge: # Note that this is not related to Signal delivery receipts. delivery_receipts: false # Whether or not delivery errors should be reported as messages in the Matrix room. (not yet implemented) - delivery_error_reports: false + delivery_error_reports: true # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. # This field will automatically be changed back to false after it, # except if the config file is not writable. @@ -197,7 +197,7 @@ bridge: shared_secret: generate # The prefix for commands. Only required in non-management rooms. - command_prefix: "!signal" + command_prefix: "{{ matrix_mautrix_signal_command_prefix }}" # Messages sent upon joining a management room. # Markdown is supported. The defaults are listed below. @@ -223,8 +223,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - {{ matrix_mautrix_signal_bridge_permissions|from_yaml }} + permissions: {{ matrix_mautrix_signal_bridge_permissions|to_json }} relay: # Whether or not relay mode should be allowed. If allowed, `!signal set-relay` can be used to turn any @@ -266,9 +265,9 @@ logging: formatter: colored loggers: mau: - level: {{ matrix_mautrix_signal_log_level }} + level: {{ matrix_mautrix_signal_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_signal_logging_level|to_json }} root: - level: {{ matrix_mautrix_signal_log_level }} + level: {{ matrix_mautrix_signal_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-signal/templates/env.j2 b/roles/matrix-bridge-mautrix-signal/templates/env.j2 new file mode 100644 index 00000000..f5357ed2 --- /dev/null +++ b/roles/matrix-bridge-mautrix-signal/templates/env.j2 @@ -0,0 +1 @@ +{{ matrix_mautrix_signal_daemon_environment_variables_extension }} diff --git a/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 b/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 index 32e913a1..5d6da2c4 100644 --- a/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 +++ b/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 @@ -5,12 +5,12 @@ hs_token: "{{ matrix_mautrix_signal_homeserver_token }}" namespaces: users: - exclusive: true - regex: '^@signal_.+:{{ matrix_mautrix_signal_homeserver_domain|regex_escape }}$' + regex: '^@signal_.+:{{ matrix_mautrix_signal_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_signal_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_signal_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_signal_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_signal_homeserver_domain | regex_escape }}$' aliases: - exclusive: true - regex: '^#signal_.+:{{ matrix_mautrix_signal_homeserver_domain|regex_escape }}$' + regex: '^#signal_.+:{{ matrix_mautrix_signal_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_signal_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_signal_appservice_bot_username }} diff --git a/roles/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal-daemon.service.j2 b/roles/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal-daemon.service.j2 index 0ee05d7d..31e68ea9 100644 --- a/roles/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal-daemon.service.j2 +++ b/roles/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal-daemon.service.j2 @@ -21,9 +21,20 @@ ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} # Intentional delay, so that the homeserver (we likely depend on) can manage to start. ExecStartPre={{ matrix_host_command_sleep }} 5 +# Migration task required by the 0.19.0 upgrade +ExecStartPre=-{{ matrix_host_command_docker }} run --rm --name matrix-mautrix-signal-daemon \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_docker_network }} \ + -v {{ matrix_mautrix_signal_daemon_path }}:/signald:z \ + {{ matrix_mautrix_signal_daemon_docker_image }} \ + --migrate-data + # We can't use `--read-only` for this bridge. ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-mautrix-signal-daemon \ --log-driver=none \ + --env-file={{ matrix_mautrix_signal_daemon_path }}/env \ --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ --cap-drop=ALL \ --network={{ matrix_docker_network }} \ diff --git a/roles/matrix-bridge-mautrix-telegram/defaults/main.yml b/roles/matrix-bridge-mautrix-telegram/defaults/main.yml index 65a446e0..5c3c88fb 100644 --- a/roles/matrix-bridge-mautrix-telegram/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-telegram/defaults/main.yml @@ -1,17 +1,19 @@ --- # mautrix-telegram is a Matrix <-> Telegram bridge -# See: https://github.com/mautrix/telegram +# Project source code URL: https://github.com/mautrix/telegram matrix_mautrix_telegram_enabled: true matrix_telegram_lottieconverter_container_image_self_build: false matrix_telegram_lottieconverter_container_image_self_build_mask_arch: false matrix_telegram_lottieconverter_docker_repo: "https://mau.dev/tulir/lottieconverter.git" +matrix_telegram_lottieconverter_docker_repo_version: "master" matrix_telegram_lottieconverter_docker_src_files_path: "{{ matrix_base_data_path }}/lotticonverter/docker-src" matrix_telegram_lottieconverter_docker_image: "dock.mau.dev/tulir/lottieconverter:alpine-3.15" # needs to be ajusted according to FROM clause of Dockerfile of mautrix-telegram matrix_mautrix_telegram_container_image_self_build: false matrix_mautrix_telegram_docker_repo: "https://mau.dev/mautrix/telegram.git" +matrix_mautrix_telegram_docker_repo_version: "{{ 'master' if matrix_mautrix_telegram_version == 'latest' else matrix_mautrix_telegram_version }}" matrix_mautrix_telegram_docker_src_files_path: "{{ matrix_base_data_path }}/mautrix-telegram/docker-src" matrix_mautrix_telegram_version: v0.11.3 @@ -23,6 +25,14 @@ matrix_mautrix_telegram_base_path: "{{ matrix_base_data_path }}/mautrix-telegram matrix_mautrix_telegram_config_path: "{{ matrix_mautrix_telegram_base_path }}/config" matrix_mautrix_telegram_data_path: "{{ matrix_mautrix_telegram_base_path }}/data" +matrix_mautrix_telegram_command_prefix: "!tg" + +matrix_mautrix_telegram_bridge_permissions: | + {{ + {matrix_mautrix_telegram_homeserver_domain: 'full'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # Get your own API keys at https://my.telegram.org/apps matrix_mautrix_telegram_api_id: '' matrix_mautrix_telegram_api_hash: '' @@ -43,6 +53,9 @@ matrix_mautrix_telegram_appservice_public_external: 'https://{{ matrix_server_fq matrix_mautrix_telegram_appservice_bot_username: telegrambot +# Specifies the default log level for all bridge loggers. +matrix_mautrix_telegram_logging_level: WARNING + # Whether or not created rooms should have federation enabled. # If false, created portal rooms will never be federated. matrix_mautrix_telegram_federate_rooms: true @@ -112,11 +125,11 @@ matrix_mautrix_telegram_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_telegram_configuration_yaml`. -matrix_mautrix_telegram_configuration_extension: "{{ matrix_mautrix_telegram_configuration_extension_yaml|from_yaml if matrix_mautrix_telegram_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_telegram_configuration_extension: "{{ matrix_mautrix_telegram_configuration_extension_yaml | from_yaml if matrix_mautrix_telegram_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_telegram_configuration_yaml`. -matrix_mautrix_telegram_configuration: "{{ matrix_mautrix_telegram_configuration_yaml|from_yaml|combine(matrix_mautrix_telegram_configuration_extension, recursive=True) }}" +matrix_mautrix_telegram_configuration: "{{ matrix_mautrix_telegram_configuration_yaml | from_yaml | combine(matrix_mautrix_telegram_configuration_extension, recursive=True) }}" matrix_mautrix_telegram_registration_yaml: | id: telegram @@ -125,19 +138,19 @@ matrix_mautrix_telegram_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + regex: '^@telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_telegram_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_telegram_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_telegram_homeserver_domain | regex_escape }}$' aliases: - exclusive: true - regex: '^#telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + regex: '^#telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain | regex_escape }}$' # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_telegram_appservice_bot_username }} url: {{ matrix_mautrix_telegram_appservice_address }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_telegram_registration: "{{ matrix_mautrix_telegram_registration_yaml|from_yaml }}" +matrix_mautrix_telegram_registration: "{{ matrix_mautrix_telegram_registration_yaml | from_yaml }}" # Templates for defining MXID's and displaynames for users and rooms. matrix_mautrix_telegram_username_template: 'telegram_{userid}' diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/init.yml b/roles/matrix-bridge-mautrix-telegram/tasks/init.yml index a97dcd8e..fac5a86c 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/init.yml @@ -2,42 +2,46 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Mautrix-Telegram image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mautrix_telegram_container_image_self_build and matrix_mautrix_telegram_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-telegram.service'] }}" - when: matrix_mautrix_telegram_enabled|bool + when: matrix_mautrix_telegram_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_telegram_config_path }}/registration.yaml,dst=/matrix-mautrix-telegram-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_telegram_config_path }}/registration.yaml,dst=/matrix-mautrix-telegram-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-telegram-registration.yaml"] }} - when: matrix_mautrix_telegram_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-telegram-registration.yaml"] + }} + when: matrix_mautrix_telegram_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix Telegram's 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-telegram role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix Telegram proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_telegram_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_telegram_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-telegram:8080"; @@ -49,23 +53,23 @@ } - name: Register Mautrix Telegram proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_telegram_matrix_nginx_proxy_configuration] }} - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix Telegram bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_telegram_public_endpoint }}` URL endpoint to the matrix-mautrix-telegram container. You can expose the container's port using the `matrix_mautrix_telegram_container_http_host_bind_port` variable. - when: "not matrix_nginx_proxy_enabled|default(False)|bool" + when: "not matrix_nginx_proxy_enabled | default(False) | bool" tags: - always - when: matrix_mautrix_telegram_enabled|bool and matrix_mautrix_telegram_appservice_public_enabled|bool + when: matrix_mautrix_telegram_enabled | bool and matrix_mautrix_telegram_appservice_public_enabled | bool diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/main.yml b/roles/matrix-bridge-mautrix-telegram/tasks/main.yml index 018b30da..471f0cf1 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/main.yml @@ -1,22 +1,22 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_telegram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_telegram_enabled | bool" tags: - setup-all - setup-mautrix-telegram -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_telegram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_telegram_enabled | bool" tags: - setup-all - setup-mautrix-telegram -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_telegram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_telegram_enabled | bool" tags: - setup-all - setup-mautrix-telegram diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml index 55e7d016..6ce39657 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml @@ -3,39 +3,41 @@ # 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-telegram role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_telegram_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}" register: matrix_mautrix_telegram_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_telegram_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_telegram_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-telegram.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_telegram_requires_restart: true - when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_telegram_database_engine == 'postgres'" - name: Ensure Mautrix Telegram paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -46,7 +48,7 @@ - {path: "{{ matrix_mautrix_telegram_config_path }}", when: true} - {path: "{{ matrix_mautrix_telegram_data_path }}", when: true} - {path: "{{ matrix_mautrix_telegram_docker_src_files_path }}", when: "{{ matrix_mautrix_telegram_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Telegram image is pulled docker_image: @@ -54,21 +56,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_telegram_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_telegram_docker_image_force_pull }}" - when: "not matrix_mautrix_telegram_container_image_self_build|bool" + when: "not matrix_mautrix_telegram_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure lottieconverter is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_telegram_lottieconverter_docker_repo }}" + version: "{{ matrix_telegram_lottieconverter_docker_repo_version }}" dest: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_telegram_lottieconverter_git_pull_results - when: "matrix_telegram_lottieconverter_container_image_self_build|bool and matrix_mautrix_telegram_container_image_self_build|bool" + when: "matrix_telegram_lottieconverter_container_image_self_build | bool and matrix_mautrix_telegram_container_image_self_build | bool" - name: Ensure lottieconverter Docker image is built docker_image: @@ -80,17 +83,18 @@ dockerfile: Dockerfile path: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}" pull: true - when: "matrix_telegram_lottieconverter_container_image_self_build|bool and matrix_telegram_lottieconverter_git_pull_results.changed and matrix_mautrix_telegram_container_image_self_build|bool" + when: "matrix_telegram_lottieconverter_container_image_self_build | bool and matrix_telegram_lottieconverter_git_pull_results.changed and matrix_mautrix_telegram_container_image_self_build | bool" - name: Ensure matrix-mautrix-telegram repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_telegram_docker_repo }}" + version: "{{ matrix_mautrix_telegram_docker_repo_version }}" dest: "{{ matrix_mautrix_telegram_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_telegram_git_pull_results - when: "matrix_mautrix_telegram_container_image_self_build|bool" + when: "matrix_mautrix_telegram_container_image_self_build | bool" - name: Ensure matrix-mautrix-telegram Docker image is built docker_image: @@ -101,18 +105,18 @@ build: dockerfile: Dockerfile path: "{{ matrix_mautrix_telegram_docker_src_files_path }}" - pull: "{{ not matrix_telegram_lottieconverter_container_image_self_build_mask_arch|bool }}" + pull: "{{ not matrix_telegram_lottieconverter_container_image_self_build_mask_arch | bool }}" args: TARGETARCH: "" - when: "matrix_mautrix_telegram_container_image_self_build|bool and matrix_mautrix_telegram_git_pull_results.changed" + when: "matrix_mautrix_telegram_container_image_self_build | bool and matrix_mautrix_telegram_git_pull_results.changed" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db" register: matrix_mautrix_telegram_stat_database - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-telegram state: stopped enabled: false @@ -121,39 +125,39 @@ when: "matrix_mautrix_telegram_stat_database.stat.exists" - name: (Data relocation) Move mautrix-telegram database file to ./data directory - command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db" + ansible.builtin.command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db" when: "matrix_mautrix_telegram_stat_database.stat.exists" - name: Ensure mautrix-telegram config.yaml installed - copy: - content: "{{ matrix_mautrix_telegram_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_telegram_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-telegram registration.yaml installed - copy: - content: "{{ matrix_mautrix_telegram_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_telegram_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-telegram.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service" mode: 0644 register: matrix_mautrix_telegram_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_telegram_systemd_service_result.changed" - name: Ensure matrix-mautrix-telegram.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-telegram.service" state: restarted - when: "matrix_mautrix_telegram_requires_restart|bool" + when: "matrix_mautrix_telegram_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml index a713898b..f4a5f569 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-telegram service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service" register: matrix_mautrix_telegram_service_stat - name: Ensure matrix-mautrix-telegram is stopped - service: + ansible.builtin.service: name: matrix-mautrix-telegram state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_telegram_service_stat.stat.exists" - name: Ensure matrix-mautrix-telegram.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service" state: absent when: "matrix_mautrix_telegram_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-telegram.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_telegram_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml index 2067b97b..9711448b 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_mautrix_telegram_homeserver_token" - name: (Deprecation) Catch and report renamed Telegram variables - fail: + 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 }}`). diff --git a/roles/matrix-bridge-mautrix-telegram/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-telegram/templates/config.yaml.j2 index 6569ce87..3a7ab7f1 100644 --- a/roles/matrix-bridge-mautrix-telegram/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-telegram/templates/config.yaml.j2 @@ -105,11 +105,11 @@ bridge: # synced when they send messages. The maximum is 10000, after which the Telegram server # will not send any more members. # Defaults to no local limit (-> limited to 10000 by server) - max_initial_member_sync: -1 + max_initial_member_sync: 10 # Whether or not to sync the member list in channels. # If no channel admins have logged into the bridge, the bridge won't be able to sync the member # list regardless of this setting. - sync_channel_members: true + sync_channel_members: false # Whether or not to skip deleted members when syncing members. skip_deleted_members: true # Whether or not to automatically synchronize contacts and chats of Matrix users logged into @@ -204,7 +204,7 @@ bridge: # been sent to Telegram. delivery_receipts: false # Whether or not delivery errors should be reported as messages in the Matrix room. - delivery_error_reports: false + delivery_error_reports: true # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. # This field will automatically be changed back to false after it, # except if the config file is not writable. @@ -276,7 +276,7 @@ bridge: list: [] # The prefix for commands. Only required in non-management rooms. - command_prefix: "!tg" + command_prefix: "{{ matrix_mautrix_telegram_command_prefix }}" # Permissions for using the bridge. # Permitted values: @@ -289,8 +289,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - '{{ matrix_mautrix_telegram_homeserver_domain }}': full + permissions: {{ matrix_mautrix_telegram_bridge_permissions|to_json }} # Options related to the message relay Telegram bot. relaybot: @@ -401,11 +400,11 @@ logging: formatter: precise loggers: mau: - level: DEBUG + level: {{ matrix_mautrix_telegram_logging_level|to_json }} telethon: - level: DEBUG + level: {{ matrix_mautrix_telegram_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_telegram_logging_level|to_json }} root: - level: DEBUG + level: {{ matrix_mautrix_telegram_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-twitter/defaults/main.yml b/roles/matrix-bridge-mautrix-twitter/defaults/main.yml index 3dd4667c..29999c45 100644 --- a/roles/matrix-bridge-mautrix-twitter/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-twitter/defaults/main.yml @@ -1,13 +1,14 @@ --- # mautrix-twitter is a Matrix <-> Twitter bridge -# See: https://github.com/mautrix/twitter +# Project source code URL: https://github.com/mautrix/twitter matrix_mautrix_twitter_enabled: true matrix_mautrix_twitter_container_image_self_build: false matrix_mautrix_twitter_container_image_self_build_repo: "https://github.com/mautrix/twitter.git" +matrix_mautrix_twitter_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_twitter_version == 'latest' else matrix_mautrix_twitter_version }}" -matrix_mautrix_twitter_version: v0.1.3 +matrix_mautrix_twitter_version: v0.1.4 # See: https://mau.dev/tulir/mautrix-twitter/container_registry matrix_mautrix_twitter_docker_image: "{{ matrix_mautrix_twitter_docker_image_name_prefix }}mautrix/twitter:{{ matrix_mautrix_twitter_version }}" matrix_mautrix_twitter_docker_image_name_prefix: "{{ 'localhost/' if matrix_mautrix_twitter_container_image_self_build else 'dock.mau.dev/' }}" @@ -22,6 +23,14 @@ matrix_mautrix_twitter_homeserver_address: "{{ matrix_homeserver_container_url } matrix_mautrix_twitter_homeserver_domain: '{{ matrix_domain }}' matrix_mautrix_twitter_appservice_address: 'http://matrix-mautrix-twitter:29327' +matrix_mautrix_twitter_command_prefix: "!tw" + +matrix_mautrix_twitter_bridge_permissions: | + {{ + {matrix_mautrix_twitter_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # A list of extra arguments to pass to the container matrix_mautrix_twitter_container_extra_arguments: [] @@ -66,6 +75,9 @@ matrix_mautrix_twitter_bridge_login_shared_secret_map: "{{ {matrix_mautrix_twitt matrix_mautrix_twitter_appservice_bot_username: twitterbot +# Specifies the default log level for all bridge loggers. +matrix_mautrix_twitter_logging_level: WARNING + # Default configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -82,11 +94,11 @@ matrix_mautrix_twitter_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_twitter_configuration_yaml`. -matrix_mautrix_twitter_configuration_extension: "{{ matrix_mautrix_twitter_configuration_extension_yaml|from_yaml if matrix_mautrix_twitter_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_twitter_configuration_extension: "{{ matrix_mautrix_twitter_configuration_extension_yaml | from_yaml if matrix_mautrix_twitter_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_twitter_configuration_yaml`. -matrix_mautrix_twitter_configuration: "{{ matrix_mautrix_twitter_configuration_yaml|from_yaml|combine(matrix_mautrix_twitter_configuration_extension, recursive=True) }}" +matrix_mautrix_twitter_configuration: "{{ matrix_mautrix_twitter_configuration_yaml | from_yaml | combine(matrix_mautrix_twitter_configuration_extension, recursive=True) }}" matrix_mautrix_twitter_registration_yaml: | id: twitter @@ -95,13 +107,13 @@ matrix_mautrix_twitter_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@twitter_.+:{{ matrix_mautrix_twitter_homeserver_domain|regex_escape }}$' + regex: '^@twitter_.+:{{ matrix_mautrix_twitter_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_twitter_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_twitter_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_twitter_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_twitter_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_twitter_appservice_address }} # See https://github.com/tulir/mautrix-signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_twitter_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_twitter_registration: "{{ matrix_mautrix_twitter_registration_yaml|from_yaml }}" +matrix_mautrix_twitter_registration: "{{ matrix_mautrix_twitter_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/init.yml b/roles/matrix-bridge-mautrix-twitter/tasks/init.yml index 5b526bbd..75a60ffa 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/init.yml @@ -1,25 +1,29 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-twitter.service'] }}" - when: matrix_mautrix_twitter_enabled|bool + when: matrix_mautrix_twitter_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_twitter_config_path }}/registration.yaml,dst=/matrix-mautrix-twitter-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_twitter_config_path }}/registration.yaml,dst=/matrix-mautrix-twitter-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-twitter-registration.yaml"] }} - when: matrix_mautrix_twitter_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-twitter-registration.yaml"] + }} + when: matrix_mautrix_twitter_enabled | bool # ansible lower than 2.8, does not support docker_image build parameters # for self buildig it is explicitly needed, so we rather fail here - name: Fail if running on Ansible lower than 2.8 and trying self building - fail: + ansible.builtin.fail: msg: "To self build Mautrix Twitter image, you should usa ansible 2.8 or higher. E.g. pip contains such packages." when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mautrix_twitter_container_image_self_build" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/main.yml b/roles/matrix-bridge-mautrix-twitter/tasks/main.yml index 6c0abe4f..2f0c39b2 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_twitter_enabled | bool" tags: - setup-all - setup-mautrix-twitter -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_twitter_enabled | bool" tags: - setup-all - setup-mautrix-twitter -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_twitter_enabled | bool" tags: - setup-all - setup-mautrix-twitter diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml index 552c9d52..05887c6d 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml @@ -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-twitter role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_twitter_requires_restart: false - name: Ensure Mautrix Twitter image is pulled @@ -17,14 +17,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_twitter_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_twitter_docker_image_force_pull }}" - when: matrix_mautrix_twitter_enabled|bool and not matrix_mautrix_twitter_container_image_self_build + when: matrix_mautrix_twitter_enabled | bool and not matrix_mautrix_twitter_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Mautrix Twitter paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -35,18 +35,18 @@ - {path: "{{ matrix_mautrix_twitter_config_path }}", when: true} - {path: "{{ matrix_mautrix_twitter_data_path }}", when: true} - {path: "{{ matrix_mautrix_twitter_docker_src_files_path }}", when: "{{ matrix_mautrix_twitter_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Twitter repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_twitter_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_twitter_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_twitter_docker_src_files_path }}" - # version: "{{ matrix_coturn_docker_image.split(':')[1] }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_twitter_git_pull_results - when: "matrix_mautrix_twitter_enabled|bool and matrix_mautrix_twitter_container_image_self_build" + when: "matrix_mautrix_twitter_enabled | bool and matrix_mautrix_twitter_container_image_self_build" - name: Ensure Mautrix Twitter Docker image is built docker_image: @@ -57,38 +57,38 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_twitter_docker_src_files_path }}" pull: true - when: "matrix_mautrix_twitter_enabled|bool and matrix_mautrix_twitter_container_image_self_build|bool" + when: "matrix_mautrix_twitter_enabled | bool and matrix_mautrix_twitter_container_image_self_build | bool" - name: Ensure mautrix-twitter config.yaml installed - copy: - content: "{{ matrix_mautrix_twitter_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_twitter_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_twitter_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-twitter registration.yaml installed - copy: - content: "{{ matrix_mautrix_twitter_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_twitter_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_twitter_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-twitter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-twitter.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-twitter.service" mode: 0644 register: matrix_mautrix_twitter_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-twitter.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_twitter_systemd_service_result.changed" - name: Ensure matrix-mautrix-twitter.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-twitter.service" state: restarted - when: "matrix_mautrix_twitter_requires_restart|bool" + when: "matrix_mautrix_twitter_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml index 024603e7..5ce64906 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml @@ -1,24 +1,24 @@ --- - name: Check existence of matrix-mautrix-twitter service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-twitter.service" register: matrix_mautrix_twitter_service_stat - name: Ensure matrix-mautrix-twitter is stopped - service: + ansible.builtin.service: name: matrix-mautrix-twitter state: stopped daemon_reload: true when: "matrix_mautrix_twitter_service_stat.stat.exists" - name: Ensure matrix-mautrix-twitter.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-twitter.service" state: absent when: "matrix_mautrix_twitter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-twitter.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_twitter_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml index 5b6e3d02..326dca83 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mautrix-twitter/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-twitter/templates/config.yaml.j2 index f0ae69b2..da823d1e 100644 --- a/roles/matrix-bridge-mautrix-twitter/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-twitter/templates/config.yaml.j2 @@ -149,7 +149,7 @@ bridge: # been sent to Twitter. delivery_receipts: false # Whether or not delivery errors should be reported as messages in the Matrix room. - delivery_error_reports: false + delivery_error_reports: true # Whether or not non-fatal polling errors should send notices to the notice room. temporary_disconnect_notices: true # Number of seconds to sleep more than the previous error when a polling error occurs. @@ -163,7 +163,7 @@ bridge: resend_bridge_info: false # The prefix for commands. Only required in non-management rooms. - command_prefix: "!tw" + command_prefix: "{{ matrix_mautrix_twitter_command_prefix }}" # Permissions for using the bridge. # Permitted values: @@ -173,8 +173,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - '{{ matrix_mautrix_twitter_homeserver_domain }}': user + permissions: {{ matrix_mautrix_twitter_bridge_permissions|to_json }} # Python logging configuration. @@ -195,9 +194,9 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: {{ matrix_mautrix_twitter_logging_level|to_json }} aiohttp: - level: INFO + level: {{ matrix_mautrix_twitter_logging_level|to_json }} root: - level: DEBUG + level: {{ matrix_mautrix_twitter_logging_level|to_json }} handlers: [console] diff --git a/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml b/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml index d920be51..2bc34a91 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml @@ -1,6 +1,6 @@ --- # mautrix-whatsapp is a Matrix <-> Whatsapp bridge -# See: https://github.com/mautrix/whatsapp +# Project source code URL: https://github.com/mautrix/whatsapp matrix_mautrix_whatsapp_enabled: true @@ -8,7 +8,7 @@ matrix_mautrix_whatsapp_container_image_self_build: false matrix_mautrix_whatsapp_container_image_self_build_repo: "https://mau.dev/mautrix/whatsapp.git" matrix_mautrix_whatsapp_container_image_self_build_branch: "{{ 'master' if matrix_mautrix_whatsapp_version == 'latest' else matrix_mautrix_whatsapp_version }}" -matrix_mautrix_whatsapp_version: v0.3.1 +matrix_mautrix_whatsapp_version: v0.6.0 # See: https://mau.dev/mautrix/whatsapp/container_registry matrix_mautrix_whatsapp_docker_image: "{{ matrix_mautrix_whatsapp_docker_image_name_prefix }}mautrix/whatsapp:{{ matrix_mautrix_whatsapp_version }}" matrix_mautrix_whatsapp_docker_image_name_prefix: "{{ 'localhost/' if matrix_mautrix_whatsapp_container_image_self_build else 'dock.mau.dev/' }}" @@ -23,6 +23,8 @@ matrix_mautrix_whatsapp_homeserver_address: "{{ matrix_homeserver_container_url matrix_mautrix_whatsapp_homeserver_domain: "{{ matrix_domain }}" matrix_mautrix_whatsapp_appservice_address: "http://matrix-mautrix-whatsapp:8080" +matrix_mautrix_whatsapp_command_prefix: "!wa" + # A list of extra arguments to pass to the container matrix_mautrix_whatsapp_container_extra_arguments: [] @@ -37,6 +39,10 @@ matrix_mautrix_whatsapp_homeserver_token: '' matrix_mautrix_whatsapp_appservice_bot_username: whatsappbot +# Minimum severity of journal log messages. +# Options: debug, info, warn, error, fatal +matrix_mautrix_whatsapp_logging_level: 'warn' + # Whether or not created rooms should have federation enabled. # If false, created portal rooms will never be federated. matrix_mautrix_whatsapp_federate_rooms: true @@ -84,6 +90,17 @@ matrix_mautrix_whatsapp_bridge_login_shared_secret_map: matrix_mautrix_whatsapp_bridge_double_puppet_server_map: "{{ matrix_mautrix_whatsapp_homeserver_domain : matrix_mautrix_whatsapp_homeserver_address }}" +# Enable End-to-bridge encryption +matrix_mautrix_whatsapp_bridge_encryption_allow: false +matrix_mautrix_whatsapp_bridge_encryption_default: "{{ matrix_mautrix_whatsapp_bridge_encryption_allow }}" +matrix_mautrix_whatsapp_bridge_encryption_key_sharing_allow: "{{ matrix_mautrix_whatsapp_bridge_encryption_allow }}" + +matrix_mautrix_whatsapp_bridge_permissions: | + {{ + {matrix_mautrix_whatsapp_homeserver_domain: 'user'} + | combine({matrix_admin: 'admin'} if matrix_admin else {}) + }} + # Default mautrix-whatsapp configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # @@ -100,11 +117,11 @@ matrix_mautrix_whatsapp_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_whatsapp_configuration_yaml`. -matrix_mautrix_whatsapp_configuration_extension: "{{ matrix_mautrix_whatsapp_configuration_extension_yaml|from_yaml if matrix_mautrix_whatsapp_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_whatsapp_configuration_extension: "{{ matrix_mautrix_whatsapp_configuration_extension_yaml | from_yaml if matrix_mautrix_whatsapp_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_whatsapp_configuration_yaml`. -matrix_mautrix_whatsapp_configuration: "{{ matrix_mautrix_whatsapp_configuration_yaml|from_yaml|combine(matrix_mautrix_whatsapp_configuration_extension, recursive=True) }}" +matrix_mautrix_whatsapp_configuration: "{{ matrix_mautrix_whatsapp_configuration_yaml | from_yaml | combine(matrix_mautrix_whatsapp_configuration_extension, recursive=True) }}" matrix_mautrix_whatsapp_registration_yaml: | id: whatsapp @@ -116,10 +133,10 @@ matrix_mautrix_whatsapp_registration_yaml: | rate_limited: false namespaces: users: - - regex: '^@whatsapp_[0-9]+:{{ matrix_mautrix_whatsapp_homeserver_domain|regex_escape }}$' + - regex: '^@whatsapp_[0-9]+:{{ matrix_mautrix_whatsapp_homeserver_domain | regex_escape }}$' exclusive: true - exclusive: true - regex: '^@{{ matrix_mautrix_whatsapp_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_whatsapp_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_whatsapp_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_whatsapp_homeserver_domain | regex_escape }}$' de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_whatsapp_registration: "{{ matrix_mautrix_whatsapp_registration_yaml|from_yaml }}" +matrix_mautrix_whatsapp_registration: "{{ matrix_mautrix_whatsapp_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml index 57166386..ab10a530 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml @@ -1,17 +1,21 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-whatsapp.service'] }}" - when: matrix_mautrix_whatsapp_enabled|bool + when: matrix_mautrix_whatsapp_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([]) }} - + - ["--mount type=bind,src={{ matrix_mautrix_whatsapp_config_path }}/registration.yaml,dst=/matrix-mautrix-whatsapp-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mautrix_whatsapp_config_path }}/registration.yaml,dst=/matrix-mautrix-whatsapp-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mautrix-whatsapp-registration.yaml"] }} - when: matrix_mautrix_whatsapp_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mautrix-whatsapp-registration.yaml"] + }} + when: matrix_mautrix_whatsapp_enabled | bool diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml index 0a963eb2..4df6fd23 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml @@ -1,21 +1,21 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_whatsapp_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_whatsapp_enabled | bool" tags: - setup-all - setup-mautrix-whatsapp -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" when: "run_setup and matrix_mautrix_whatsapp_enabled" tags: - setup-all - setup-mautrix-whatsapp -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" when: "run_setup and not matrix_mautrix_whatsapp_enabled" tags: - setup-all diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml index f47675b5..c3edd6a7 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml @@ -3,41 +3,43 @@ # 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-whatsapp role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_whatsapp_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_whatsapp_sqlite_database_path_local }}" register: matrix_mautrix_whatsapp_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_whatsapp_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_whatsapp_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_whatsapp_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-whatsapp.service'] pgloader_options: ['--with "quote identifiers"'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_whatsapp_requires_restart: true - when: "matrix_mautrix_whatsapp_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_whatsapp_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_whatsapp_database_engine == 'postgres'" - name: Ensure Mautrix Whatsapp paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -48,7 +50,7 @@ - {path: "{{ matrix_mautrix_whatsapp_config_path }}", when: true} - {path: "{{ matrix_mautrix_whatsapp_data_path }}", when: true} - {path: "{{ matrix_mautrix_whatsapp_docker_src_files_path }}", when: "{{ matrix_mautrix_whatsapp_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Whatsapp image is pulled docker_image: @@ -63,7 +65,7 @@ until: result is not failed - name: Ensure Mautrix Whatsapp repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_whatsapp_container_image_self_build_repo }}" dest: "{{ matrix_mautrix_whatsapp_docker_src_files_path }}" version: "{{ matrix_mautrix_whatsapp_container_image_self_build_branch }}" @@ -71,7 +73,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_whatsapp_git_pull_results - when: "matrix_mautrix_whatsapp_container_image_self_build|bool" + when: "matrix_mautrix_whatsapp_container_image_self_build | bool" - name: Ensure Mautrix Whatsapp Docker image is built docker_image: @@ -83,20 +85,20 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_whatsapp_docker_src_files_path }}" pull: true - when: "matrix_mautrix_whatsapp_container_image_self_build|bool" + when: "matrix_mautrix_whatsapp_container_image_self_build | bool" - name: Check if an old database file exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_whatsapp_base_path }}/mautrix-whatsapp.db" register: matrix_mautrix_whatsapp_stat_database - name: Check if an old matrix state file exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_whatsapp_base_path }}/mx-state.json" register: matrix_mautrix_whatsapp_stat_mx_state - name: (Data relocation) Ensure matrix-mautrix-whatsapp.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-whatsapp state: stopped enabled: false @@ -105,43 +107,43 @@ when: "matrix_mautrix_whatsapp_stat_database.stat.exists" - name: (Data relocation) Move mautrix-whatsapp database file to ./data directory - command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mautrix-whatsapp.db {{ matrix_mautrix_whatsapp_data_path }}/mautrix-whatsapp.db" + ansible.builtin.command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mautrix-whatsapp.db {{ matrix_mautrix_whatsapp_data_path }}/mautrix-whatsapp.db" when: "matrix_mautrix_whatsapp_stat_database.stat.exists" - name: (Data relocation) Move mautrix-whatsapp mx-state file to ./data directory - command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mx-state.json {{ matrix_mautrix_whatsapp_data_path }}/mx-state.json" + ansible.builtin.command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mx-state.json {{ matrix_mautrix_whatsapp_data_path }}/mx-state.json" when: "matrix_mautrix_whatsapp_stat_mx_state.stat.exists" - name: Ensure mautrix-whatsapp config.yaml installed - copy: - content: "{{ matrix_mautrix_whatsapp_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_whatsapp_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_whatsapp_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-whatsapp registration.yaml installed - copy: - content: "{{ matrix_mautrix_whatsapp_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_whatsapp_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_whatsapp_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-whatsapp.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-whatsapp.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-whatsapp.service" mode: 0644 register: matrix_mautrix_whatsapp_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-whatsapp.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_whatsapp_systemd_service_result.changed" - name: Ensure matrix-mautrix-whatsapp.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-whatsapp.service" state: restarted - when: "matrix_mautrix_whatsapp_requires_restart|bool" + when: "matrix_mautrix_whatsapp_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml index 3884f9e7..c531b530 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-whatsapp service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-whatsapp.service" register: matrix_mautrix_whatsapp_service_stat - name: Ensure matrix-mautrix-whatsapp is stopped - service: + ansible.builtin.service: name: matrix-mautrix-whatsapp state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_whatsapp_service_stat.stat.exists" - name: Ensure matrix-mautrix-whatsapp.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-whatsapp.service" state: absent when: "matrix_mautrix_whatsapp_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-whatsapp.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_whatsapp_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml index c983c4cc..863dc926 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml @@ -1,10 +1,20 @@ --- - 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_whatsapp_appservice_token" - "matrix_mautrix_whatsapp_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_whatsapp_log_level', 'new': 'matrix_mautrix_whatsapp_logging_level'} diff --git a/roles/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 index 0e3b855c..fab8d964 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 @@ -5,13 +5,17 @@ homeserver: address: {{ matrix_mautrix_whatsapp_homeserver_address }} # The domain of the homeserver (for MXIDs, etc). domain: {{ matrix_mautrix_whatsapp_homeserver_domain }} -# Application service host/registration related details. -# Changing these values requires regeneration of the registration. # The URL to push real-time bridge status to. # If set, the bridge will make POST requests to this URL whenever a user's whatsapp connection state changes. # The bridge will use the appservice as_token to authorize requests. - status_endpoint: "null" + status_endpoint: null + # Endpoint for reporting per-message status. + message_send_checkpoint_endpoint: null + # Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246? + async_media: false +# Application service host/registration related details. +# Changing these values requires regeneration of the registration. appservice: # The address that the homeserver can use to connect to this appservice. address: {{ matrix_mautrix_whatsapp_appservice_address }} @@ -24,11 +28,16 @@ appservice: type: {{ matrix_mautrix_whatsapp_appservice_database_type|to_json }} # The database URI. # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string - # Postgres: Connection string. For example, postgres://user:password@host/database + # Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable + # To connect via Unix socket, use something like postgres:///dbname?host=/var/run/postgresql uri: {{ matrix_mautrix_whatsapp_appservice_database_uri|to_json }} # Maximum number of connections. Mostly relevant for Postgres. max_open_conns: 20 max_idle_conns: 2 + # Maximum connection idle time and lifetime before they're closed. Disabled if null. + # Parsed with https://pkg.go.dev/time#ParseDuration + max_conn_idle_time: null + max_conn_lifetime: null # The unique ID of this appservice. id: whatsapp # Appservice bot details. @@ -39,37 +48,71 @@ appservice: # to leave display name/avatar as-is. displayname: WhatsApp bridge bot avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr + + # Whether or not to receive ephemeral events via appservice transactions. + # Requires MSC2409 support (i.e. Synapse 1.22+). + # You should disable bridge -> sync_with_custom_puppets when this is enabled. + ephemeral_events: false + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. as_token: "{{ matrix_mautrix_whatsapp_appservice_token }}" hs_token: "{{ matrix_mautrix_whatsapp_homeserver_token }}" +# Segment API key to track some events, like provisioning API login and encryption errors. +segment_key: null + +# Prometheus config. +metrics: + # Enable prometheus metrics? + enabled: false + # IP and port where the metrics listener should be. The path is always /metrics + listen: 127.0.0.1:8001 + +# Config for things that are directly sent to WhatsApp. +whatsapp: + # Device name that's shown in the "WhatsApp Web" section in the mobile app. + os_name: Mautrix-WhatsApp bridge + # Browser name that determines the logo shown in the mobile app. + # Must be "unknown" for a generic icon or a valid browser name if you want a specific icon. + # List of valid browser names: https://github.com/tulir/whatsmeow/blob/8b34d886d543b72e5f4699cf5b2797f68d598f78/binary/proto/def.proto#L38-L51 + browser_name: unknown + # Bridge config bridge: # Localpart template of MXIDs for WhatsApp users. # {{ '{{.}}' }} is replaced with the phone number of the WhatsApp user. username_template: "{{ 'whatsapp_{{.}}' }}" - displayname_template: "{{ '{{if .PushName}}{{.PushName}}{{else if .BusinessName}}{{.BusinessName}}{{else}}{{.JID}}{{end}} (WA)' }}" + # Displayname template for WhatsApp users. + # {{ '{{.PushName}}' }} - nickname set by the WhatsApp user + # {{ '{{.BusinessName}}' }} - validated WhatsApp business name + # {{ '{{.Phone}}' }} - phone number (international format) + # The following variables are also available, but will cause problems on multi-user instances: + # {{ '{{.FullName}}' }} - full name from contact list + # {{ '{{.FirstName}}' }} - first name from contact list + displayname_template: "{{ '{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)' }}" + # Should the bridge create a space for each logged-in user and add bridged rooms to it? + # Users who logged in before turning this on should run `!wa sync space` to create and fill the space for the first time. + personal_filtering_spaces: false # Should the bridge send a read receipt from the bridge bot when a message has been sent to WhatsApp? delivery_receipts: false + # Whether the bridge should send the message status as a custom com.beeper.message_send_status event. + message_status_events: false + # Whether the bridge should send error notices via m.notice events when a message fails to bridge. + message_error_notices: true # Should incoming calls send a message to the Matrix room? call_start_notices: true # Should another user's cryptographic identity changing send a message to Matrix? identity_change_notices: false - # Should a "reactions not yet supported" warning be sent to the Matrix room when a user reacts to a message? - reaction_notices: true portal_message_buffer: 128 - # Settings for handling history sync payloads. These settings only apply right after login, - # because the phone only sends the history sync data once, and there's no way to re-request it - # (other than logging out and back in again). + # Settings for handling history sync payloads. history_sync: # Should the bridge create portals for chats in the history sync payload? create_portals: true - # Maximum age of chats in seconds to create portals for. Set to 0 to create portals for all chats in sync payload. - max_age: 604800 # Enable backfilling history sync payloads from WhatsApp using batch sending? # This requires a server with MSC2716 support, which is currently an experimental feature in synapse. # It can be enabled by setting experimental_features -> msc2716_enabled to true in homeserver.yaml. - # Note that as of Synapse 1.46, there are still some bugs with the implementation, especially if using event persistence workers. + # Note that prior to Synapse 1.49, there were some bugs with the implementation, especially if using event persistence workers. + # There are also still some issues in Synapse's federation implementation. backfill: false # Use double puppets for backfilling? # In order to use this, the double puppets must be in the appservice's user ID namespace @@ -80,6 +123,67 @@ bridge: # Should the bridge request a full sync from the phone when logging in? # This bumps the size of history syncs from 3 months to 1 year. request_full_sync: false + # Settings for media requests. If the media expired, then it will not + # be on the WA servers. + # Media can always be requested by reacting with the ♻️ (recycle) emoji. + # These settings determine if the media requests should be done + # automatically during or after backfill. + media_requests: + # Should expired media be automatically requested from the server as + # part of the backfill process? + auto_request_media: true + # Whether to request the media immediately after the media message + # is backfilled ("immediate") or at a specific time of the day + # ("local_time"). + request_method: immediate + # If request_method is "local_time", what time should the requests + # be sent (in minutes after midnight)? + request_local_time: 120 + # The maximum number of initial conversations that should be synced. + # Other conversations will be backfilled on demand when the start PM + # provisioning endpoint is used or when a message comes in from that + # chat. + max_initial_conversations: -1 + # Settings for immediate backfills. These backfills should generally be + # small and their main purpose is to populate each of the initial chats + # (as configured by max_initial_conversations) with a few messages so + # that you can continue conversations without loosing context. + immediate: + # The number of concurrent backfill workers to create for immediate + # backfills. Note that using more than one worker could cause the + # room list to jump around since there are no guarantees about the + # order in which the backfills will complete. + worker_count: 1 + # The maximum number of events to backfill initially. + max_events: 10 + # Settings for deferred backfills. The purpose of these backfills are + # to fill in the rest of the chat history that was not covered by the + # immediate backfills. These backfills generally should happen at a + # slower pace so as not to overload the homeserver. + # Each deferred backfill config should define a "stage" of backfill + # (i.e. the last week of messages). The fields are as follows: + # - start_days_ago: the number of days ago to start backfilling from. + # To indicate the start of time, use -1. For example, for a week ago, use 7. + # - max_batch_events: the number of events to send per batch. + # - batch_delay: the number of seconds to wait before backfilling each batch. + deferred: + # Last Week + - start_days_ago: 7 + max_batch_events: 20 + batch_delay: 5 + # Last Month + - start_days_ago: 30 + max_batch_events: 50 + batch_delay: 10 + # Last 3 months + - start_days_ago: 90 + max_batch_events: 100 + batch_delay: 10 + # The start of time + - start_days_ago: -1 + max_batch_events: 500 + batch_delay: 10 + # Should puppet avatars be fetched from the server even if an avatar is already set? user_avatar_sync: true # Should Matrix users leaving groups be bridged to WhatsApp? bridge_matrix_leave: true @@ -89,11 +193,26 @@ bridge: # Note that updating the m.direct event is not atomic (except with mautrix-asmux) # and is therefore prone to race conditions. sync_direct_chat_list: false + # Should the bridge use MSC2867 to bridge manual "mark as unread"s from + # WhatsApp and set the unread status on initial backfill? + # This will only work on clients that support the m.marked_unread or + # com.famedly.marked_unread room account data. + sync_manual_marked_unread: true # When double puppeting is enabled, users can use `!wa toggle` to change whether # presence and read receipts are bridged. These settings set the default values. # Existing users won't be affected when these are changed. default_bridge_receipts: true default_bridge_presence: true + # Send the presence as "available" to whatsapp when users start typing on a portal. + # This works as a workaround for homeservers that do not support presence, and allows + # users to see when the whatsapp user on the other side is typing during a conversation. + send_presence_on_typing: false + # Should the bridge always send "active" delivery receipts (two gray ticks on WhatsApp) + # even if the user isn't marked as online (e.g. when presence bridging isn't enabled)? + # + # By default, the bridge acts like WhatsApp web, which only sends active delivery + # receipts when it's in the foreground. + force_active_delivery_receipts: false # Servers to always allow double puppeting from double_puppet_server_map: "{{ matrix_mautrix_whatsapp_homeserver_domain }}": {{ matrix_mautrix_whatsapp_homeserver_address }} @@ -125,9 +244,14 @@ bridge: # Should WhatsApp status messages be bridged into a Matrix room? # Disabling this won't affect already created status broadcast rooms. enable_status_broadcast: true + # Should sending WhatsApp status messages be allowed? + # This can cause issues if the user has lots of contacts, so it's disabled by default. + disable_status_broadcast_send: true # Should the status broadcast room be muted and moved into low priority by default? - # This is only applied when creating the room, the user can unmute/untag it later. + # This is only applied when creating the room, the user can unmute it later. mute_status_broadcast: true + # Tag to apply to the status broadcast room. + status_broadcast_tag: m.lowpriority # Should the bridge use thumbnails from WhatsApp? # They're disabled by default due to very low resolution. whatsapp_thumbnail: false @@ -137,9 +261,33 @@ bridge: # Whether or not created rooms should have federation enabled. # If false, created portal rooms will never be federated. federate_rooms: {{ matrix_mautrix_whatsapp_federate_rooms|to_json }} + # Whether to enable disappearing messages in groups. If enabled, then the expiration time of + # the messages will be determined by the first user to read the message, rather than individually. + # If the bridge only has a single user, this can be turned on safely. + disappearing_messages_in_groups: false + # Should the bridge never send alerts to the bridge management room? + # These are mostly things like the user being logged out. + disable_bridge_alerts: false + # Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview, + # and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews` + # key in the event content even if this is disabled. + url_previews: false + # Send captions in the same message as images. This will send data compatible with both MSC2530 and MSC3552. + # This is currently not supported in most clients. + caption_in_message: false + # Maximum time for handling Matrix events. Duration strings formatted for https://pkg.go.dev/time#ParseDuration + # Null means there's no enforced timeout. + message_handling_timeout: + # Send an error message after this timeout, but keep waiting for the response until the deadline. + # This is counted from the origin_server_ts, so the warning time is consistent regardless of the source of delay. + # If the message is older than this when it reaches the bridge, the message won't be handled at all. + error_after: null + # Drop messages after this timeout. They may still go through if the message got sent to the servers. + # This is counted from the time the bridge starts handling the message. + deadline: 120s # The prefix for commands. Only required in non-management rooms. - command_prefix: "!wa" + command_prefix: "{{ matrix_mautrix_whatsapp_command_prefix }}" # Messages sent upon joining a management room. # Markdown is supported. The defaults are listed below. @@ -158,23 +306,58 @@ bridge: # See https://docs.mau.fi/bridges/general/end-to-bridge-encryption.html for more info. encryption: # Allow encryption, work in group chat rooms with e2ee enabled - allow: false + allow: {{ matrix_mautrix_whatsapp_bridge_encryption_allow|to_json }} # Default to encryption, force-enable encryption in all portals the bridge creates # This will cause the bridge bot to be in private chats for the encryption to work properly. # It is recommended to also set private_chat_portal_meta to true when using this. - default: false - # Options for automatic key sharing. - key_sharing: - # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. - # You must use a client that supports requesting keys from other users to use this feature. - allow: false - # Require the requesting device to have a valid cross-signing signature? - # This doesn't require that the bridge has verified the device, only that the user has verified it. - # Not yet implemented. - require_cross_signing: false - # Require devices to be verified by the bridge? - # Verification by the bridge is not yet implemented. - require_verification: true + default: {{ matrix_mautrix_whatsapp_bridge_encryption_default|to_json }} + # Require encryption, drop any unencrypted messages. + require: false + # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. + # You must use a client that supports requesting keys from other users to use this feature. + allow_key_sharing: {{ matrix_mautrix_whatsapp_bridge_encryption_key_sharing_allow|to_json }} + # What level of device verification should be required from users? + # + # Valid levels: + # unverified - Send keys to all device in the room. + # cross-signed-untrusted - Require valid cross-signing, but trust all cross-signing keys. + # cross-signed-tofu - Require valid cross-signing, trust cross-signing keys on first use (and reject changes). + # cross-signed-verified - Require valid cross-signing, plus a valid user signature from the bridge bot. + # Note that creating user signatures from the bridge bot is not currently possible. + # verified - Require manual per-device verification + # (currently only possible by modifying the `trust` column in the `crypto_device` database table). + verification_levels: + # Minimum level for which the bridge should send keys to when bridging messages from WhatsApp to Matrix. + receive: unverified + # Minimum level that the bridge should accept for incoming Matrix messages. + send: unverified + # Minimum level that the bridge should require for accepting key requests. + share: cross-signed-tofu + # Options for Megolm room key rotation. These options allow you to + # configure the m.room.encryption event content. See: + # https://spec.matrix.org/v1.3/client-server-api/#mroomencryption for + # more information about that event. + rotation: + # Enable custom Megolm room key rotation settings. Note that these + # settings will only apply to rooms created after this option is + # set. + enable_custom: false + # The maximum number of milliseconds a session should be used + # before changing it. The Matrix spec recommends 604800000 (a week) + # as the default. + milliseconds: 604800000 + # The maximum number of messages that should be sent with a given a + # session before changing it. The Matrix spec recommends 100 as the + # default. + messages: 100 + + # Settings for provisioning API + provisioning: + # Prefix for the provisioning API paths. + prefix: /_matrix/provision + # Shared secret for authentication. If set to "generate", a random secret will be generated, + # or if set to "disable", the provisioning API will be disabled. + shared_secret: generate # Permissions for using the bridge. # Permitted values: @@ -185,8 +368,7 @@ bridge: # * - All Matrix users # domain - All users on that homeserver # mxid - Specific user - permissions: - "{{ matrix_mautrix_whatsapp_homeserver_domain }}": user + permissions: {{ matrix_mautrix_whatsapp_bridge_permissions|to_json }} # Settings for relay mode relay: @@ -211,13 +393,14 @@ logging: # The directory for log files. Will be created if not found. directory: ./logs # Available variables: .Date for the file date and .Index for different log files on the same day. - file_name_format: "{{ '{{.Date}}-{{.Index}}.log' }}" + # Set this to null to disable logging to file. + file_name_format: null # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants file_date_format: "2006-01-02" # Log file permissions. - file_mode: 0600 + file_mode: 0o600 # Timestamp format for log entries in the Go time format. timestamp_format: "Jan _2, 2006 15:04:05" - # Minimum severity for log messages. + # Minimum severity for log messages printed to stdout/stderr. This doesn't affect the log file. # Options: debug, info, warn, error, fatal - print_level: debug + print_level: {{ matrix_mautrix_whatsapp_logging_level }} diff --git a/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml b/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml index 52257689..771af992 100644 --- a/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml @@ -1,27 +1,21 @@ --- # Mx Puppet Discord is a Matrix <-> Discord bridge -# See: https://gitlab.com/beeper/mx-puppet-monorepo (originally based on https://github.com/matrix-discord/mx-puppet-discord) -# -# We use the Beeper-maintained fork, because https://github.com/matrix-discord/mx-puppet-discord is horribly broken often. See: -# - https://github.com/matrix-discord/mx-puppet-discord/issues/201 -# - https://github.com/matrix-discord/mx-puppet-discord/issues/202 -# - https://github.com/matrix-discord/mx-puppet-discord/issues/203 -# - (other similar issues in the past) +# Project source code URL: https://gitlab.com/mx-puppet/discord/mx-puppet-discord matrix_mx_puppet_discord_enabled: true matrix_mx_puppet_discord_container_image_self_build: false -matrix_mx_puppet_discord_container_image_self_build_repo: "https://gitlab.com/beeper/mx-puppet-monorepo" +matrix_mx_puppet_discord_container_image_self_build_repo: "https://gitlab.com/mx-puppet/discord/mx-puppet-discord.git" matrix_mx_puppet_discord_container_image_self_build_version: "{{ 'main' if matrix_mx_puppet_discord_version == 'latest' else matrix_mx_puppet_discord_version }}" -matrix_mx_puppet_discord_container_image_self_build_dockerfile_path: "docker/Dockerfile-discord" +matrix_mx_puppet_discord_container_image_self_build_dockerfile_path: "Dockerfile" # Controls whether the mx-puppet-discord container exposes its HTTP port (tcp/8432 in the container). # # Takes an ":" or "" value (e.g. "127.0.0.1:8432"), or empty string to not expose. matrix_mx_puppet_discord_container_http_host_bind_port: '' -matrix_mx_puppet_discord_version: latest -matrix_mx_puppet_discord_docker_image: "{{ matrix_mx_puppet_discord_docker_image_name_prefix }}beeper/mx-puppet-monorepo/discord:{{ matrix_mx_puppet_discord_version }}" +matrix_mx_puppet_discord_version: v0.1.1 +matrix_mx_puppet_discord_docker_image: "{{ matrix_mx_puppet_discord_docker_image_name_prefix }}mx-puppet/discord/mx-puppet-discord:{{ matrix_mx_puppet_discord_version }}" matrix_mx_puppet_discord_docker_image_name_prefix: "{{ 'localhost/' if matrix_mx_puppet_discord_container_image_self_build else 'registry.gitlab.com/' }}" matrix_mx_puppet_discord_docker_image_force_pull: "{{ matrix_mx_puppet_discord_docker_image.endswith(':latest') }}" @@ -36,13 +30,13 @@ matrix_mx_puppet_discord_homeserver_address: "{{ matrix_homeserver_container_url matrix_mx_puppet_discord_homeserver_domain: '{{ matrix_domain }}' matrix_mx_puppet_discord_appservice_address: 'http://matrix-mx-puppet-discord:{{ matrix_mx_puppet_discord_appservice_port }}' -matrix_mx_puppet_discord_bridge_mediaUrl: "https://{{ matrix_server_fqn_matrix }}" +matrix_mx_puppet_discord_bridge_mediaUrl: "https://{{ matrix_server_fqn_matrix }}" # noqa var-naming # "@user:server.com" to allow specific user # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_discord_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -94,11 +88,11 @@ matrix_mx_puppet_discord_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_discord_configuration_yaml`. -matrix_mx_puppet_discord_configuration_extension: "{{ matrix_mx_puppet_discord_configuration_extension_yaml|from_yaml if matrix_mx_puppet_discord_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_discord_configuration_extension: "{{ matrix_mx_puppet_discord_configuration_extension_yaml | from_yaml if matrix_mx_puppet_discord_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_discord_configuration_yaml`. -matrix_mx_puppet_discord_configuration: "{{ matrix_mx_puppet_discord_configuration_yaml|from_yaml|combine(matrix_mx_puppet_discord_configuration_extension, recursive=True) }}" +matrix_mx_puppet_discord_configuration: "{{ matrix_mx_puppet_discord_configuration_yaml | from_yaml | combine(matrix_mx_puppet_discord_configuration_extension, recursive=True) }}" matrix_mx_puppet_discord_registration_yaml: | as_token: "{{ matrix_mx_puppet_discord_appservice_token }}" @@ -107,15 +101,15 @@ matrix_mx_puppet_discord_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain|regex_escape }}' + regex: '@_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain|regex_escape }}' + regex: '#_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _discordpuppet_bot url: {{ matrix_mx_puppet_discord_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_discord_registration: "{{ matrix_mx_puppet_discord_registration_yaml|from_yaml }}" +matrix_mx_puppet_discord_registration: "{{ matrix_mx_puppet_discord_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml index 69458093..9fbba3c8 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml @@ -2,23 +2,27 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the mx-puppet-discord image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_discord_container_image_self_build and matrix_mx_puppet_discord_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-discord.service'] }}" - when: matrix_mx_puppet_discord_enabled|bool + when: matrix_mx_puppet_discord_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([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_discord_config_path }}/registration.yaml,dst=/matrix-mx-puppet-discord-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mx_puppet_discord_config_path }}/registration.yaml,dst=/matrix-mx-puppet-discord-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-discord-registration.yaml"] }} - when: matrix_mx_puppet_discord_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mx-puppet-discord-registration.yaml"] + }} + when: matrix_mx_puppet_discord_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml index e11a2db0..281092e1 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_discord_enabled | bool" tags: - setup-all - setup-mx-puppet-discord -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_discord_enabled | bool" tags: - setup-all - setup-mx-puppet-discord -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_discord_enabled | bool" tags: - setup-all - setup-mx-puppet-discord diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml index 3ddfa39d..d60f73f9 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml @@ -3,13 +3,13 @@ # 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-mx-puppet-discord role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Discord paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,49 +20,54 @@ - {path: "{{ matrix_mx_puppet_discord_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_discord_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_discord_docker_src_files_path }}", when: "{{ matrix_mx_puppet_discord_container_image_self_build }}"} - when: matrix_mx_puppet_discord_enabled|bool and item.when|bool + when: matrix_mx_puppet_discord_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_discord_base_path }}/database.db" register: matrix_mx_puppet_discord_stat_database - block: - name: (Data relocation) Ensure matrix-mx-puppet-discord.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-discord state: stopped daemon_reload: true failed_when: false - name: (Data relocation) Move mx-puppet-discord database file to ./data directory - command: "mv {{ matrix_mx_puppet_discord_base_path }}/database.db {{ matrix_mx_puppet_discord_data_path }}/database.db" + ansible.builtin.command: + cmd: "mv {{ matrix_mx_puppet_discord_base_path }}/database.db {{ matrix_mx_puppet_discord_data_path }}/database.db" + register: matrix_mx_puppet_discord_relocate_database_result + changed_when: matrix_mx_puppet_discord_relocate_database_result.rc == 0 when: "matrix_mx_puppet_discord_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_discord_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_discord_sqlite_database_path_local }}" register: matrix_mx_puppet_discord_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_discord_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_discord_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_discord_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-discord.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_discord_requires_restart: true - when: "matrix_mx_puppet_discord_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_discord_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_discord_database_engine == 'postgres'" - name: Ensure MX Puppet Discord image is pulled @@ -71,14 +76,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_discord_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_mx_puppet_discord_docker_image_force_pull }}" - when: matrix_mx_puppet_discord_enabled|bool and not matrix_mx_puppet_discord_container_image_self_build + when: matrix_mx_puppet_discord_enabled | bool and not matrix_mx_puppet_discord_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Discord repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_discord_container_image_self_build_repo }}" dest: "{{ matrix_mx_puppet_discord_docker_src_files_path }}" force: "yes" @@ -86,7 +91,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_discord_git_pull_results - when: "matrix_mx_puppet_discord_enabled|bool and matrix_mx_puppet_discord_container_image_self_build" + when: "matrix_mx_puppet_discord_enabled | bool and matrix_mx_puppet_discord_container_image_self_build" - name: Ensure MX Puppet Discord Docker image is built docker_image: @@ -98,38 +103,38 @@ dockerfile: "{{ matrix_mx_puppet_discord_container_image_self_build_dockerfile_path }}" path: "{{ matrix_mx_puppet_discord_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_discord_enabled|bool and matrix_mx_puppet_discord_container_image_self_build|bool" + when: "matrix_mx_puppet_discord_enabled | bool and matrix_mx_puppet_discord_container_image_self_build | bool" - name: Ensure mx-puppet-discord config.yaml installed - copy: - content: "{{ matrix_mx_puppet_discord_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_discord_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_discord_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-discord discord-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_discord_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_discord_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_discord_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-discord.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-discord.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-discord.service" mode: 0644 register: matrix_mx_puppet_discord_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-discord.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_discord_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-discord.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-discord.service" state: restarted - when: "matrix_mx_puppet_discord_requires_restart|bool" + when: "matrix_mx_puppet_discord_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml index b3ab8e39..585c6c85 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-discord service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-discord.service" register: matrix_mx_puppet_discord_service_stat - name: Ensure matrix-mx-puppet-discord is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-discord state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_discord_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-discord.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-discord.service" state: absent when: "matrix_mx_puppet_discord_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-discord.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_discord_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml index c253eda2..e73a868a 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-discord/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-discord/templates/config.yaml.j2 index edb0c280..a1c0cc48 100644 --- a/roles/matrix-bridge-mx-puppet-discord/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mx-puppet-discord/templates/config.yaml.j2 @@ -25,7 +25,7 @@ presence: # Bridge Discord online/offline status enabled: true # How often to send status to the homeserver in milliseconds - interval: 500 + interval: 5000 provisioning: # Regex of Matrix IDs allowed to use the puppet bridge @@ -117,7 +117,7 @@ logging: # Log level of console output # Allowed values starting with most verbose: # silly, debug, verbose, info, warn, error - console: info + console: warn # Date and time formatting lineDateFormat: MMM-D HH:mm:ss.SSS # Logging files diff --git a/roles/matrix-bridge-mx-puppet-discord/templates/systemd/matrix-mx-puppet-discord.service.j2 b/roles/matrix-bridge-mx-puppet-discord/templates/systemd/matrix-mx-puppet-discord.service.j2 index 7a4c4a38..52b12c3d 100644 --- a/roles/matrix-bridge-mx-puppet-discord/templates/systemd/matrix-mx-puppet-discord.service.j2 +++ b/roles/matrix-bridge-mx-puppet-discord/templates/systemd/matrix-mx-puppet-discord.service.j2 @@ -17,7 +17,7 @@ ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mx-puppet-discord 2>/dev/null || true' # Intentional delay, so that the homeserver (we likely depend on) can manage to start. -ExecStartPre={{ matrix_host_command_sleep }} 5 +ExecStartPre={{ matrix_host_command_sleep }} 15 ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-mx-puppet-discord \ --log-driver=none \ diff --git a/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml b/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml index 0daf6dfc..59b8c193 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml @@ -1,20 +1,21 @@ --- # Mx Puppet GroupMe is a Matrix <-> GroupMe bridge -# See: https://gitlab.com/robintown/mx-puppet-groupme +# Project source code URL: https://gitlab.com/xangelix-pub/matrix/mx-puppet-groupme matrix_mx_puppet_groupme_enabled: true matrix_mx_puppet_groupme_container_image_self_build: false -matrix_mx_puppet_groupme_container_image_self_build_repo: "https://gitlab.com/robintown/mx-puppet-groupme" +matrix_mx_puppet_groupme_container_image_self_build_repo: "https://gitlab.com/xangelix-pub/matrix/mx-puppet-groupme" +matrix_mx_puppet_groupme_container_image_self_build_repo_version: "{{ 'main' if matrix_mx_puppet_groupme_version == 'latest' else matrix_mx_puppet_groupme_version }}" # Controls whether the mx-puppet-groupme container exposes its HTTP port (tcp/8437 in the container). # # Takes an ":" or "" value (e.g. "127.0.0.1:8437"), or empty string to not expose. matrix_mx_puppet_groupme_container_http_host_bind_port: '' -matrix_mx_puppet_groupme_version: latest -matrix_mx_puppet_groupme_docker_image: "{{ matrix_mx_puppet_groupme_docker_image_name_prefix }}xangelix/mx-puppet-groupme:{{ matrix_mx_puppet_groupme_version }}" -matrix_mx_puppet_groupme_docker_image_name_prefix: "{{ 'localhost/' if matrix_mx_puppet_groupme_container_image_self_build else matrix_container_global_registry_prefix }}" +matrix_mx_puppet_groupme_version: 533cccc8 +matrix_mx_puppet_groupme_docker_image: "{{ matrix_mx_puppet_groupme_docker_image_name_prefix }}xangelix-pub/matrix/mx-puppet-groupme:{{ matrix_mx_puppet_groupme_version }}" +matrix_mx_puppet_groupme_docker_image_name_prefix: "{{ 'localhost/' if matrix_mx_puppet_groupme_container_image_self_build else 'registry.gitlab.com/' }}" matrix_mx_puppet_groupme_docker_image_force_pull: "{{ matrix_mx_puppet_groupme_docker_image.endswith(':latest') }}" matrix_mx_puppet_groupme_base_path: "{{ matrix_base_data_path }}/mx-puppet-groupme" @@ -32,7 +33,7 @@ matrix_mx_puppet_groupme_appservice_address: 'http://matrix-mx-puppet-groupme:{{ # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_groupme_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -83,11 +84,11 @@ matrix_mx_puppet_groupme_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_groupme_configuration_yaml`. -matrix_mx_puppet_groupme_configuration_extension: "{{ matrix_mx_puppet_groupme_configuration_extension_yaml|from_yaml if matrix_mx_puppet_groupme_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_groupme_configuration_extension: "{{ matrix_mx_puppet_groupme_configuration_extension_yaml | from_yaml if matrix_mx_puppet_groupme_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_groupme_configuration_yaml`. -matrix_mx_puppet_groupme_configuration: "{{ matrix_mx_puppet_groupme_configuration_yaml|from_yaml|combine(matrix_mx_puppet_groupme_configuration_extension, recursive=True) }}" +matrix_mx_puppet_groupme_configuration: "{{ matrix_mx_puppet_groupme_configuration_yaml | from_yaml | combine(matrix_mx_puppet_groupme_configuration_extension, recursive=True) }}" matrix_mx_puppet_groupme_registration_yaml: | as_token: "{{ matrix_mx_puppet_groupme_appservice_token }}" @@ -96,15 +97,15 @@ matrix_mx_puppet_groupme_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain|regex_escape }}' + regex: '@_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain|regex_escape }}' + regex: '#_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _groupmepuppet_bot url: {{ matrix_mx_puppet_groupme_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_groupme_registration: "{{ matrix_mx_puppet_groupme_registration_yaml|from_yaml }}" +matrix_mx_puppet_groupme_registration: "{{ matrix_mx_puppet_groupme_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml index db28f324..1a06b09e 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml @@ -2,23 +2,27 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the mx-puppet-groupme image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_groupme_container_image_self_build and matrix_mx_puppet_groupme_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-groupme.service'] }}" - when: matrix_mx_puppet_groupme_enabled|bool + when: matrix_mx_puppet_groupme_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([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_groupme_config_path }}/registration.yaml,dst=/matrix-mx-puppet-groupme-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mx_puppet_groupme_config_path }}/registration.yaml,dst=/matrix-mx-puppet-groupme-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-groupme-registration.yaml"] }} - when: matrix_mx_puppet_groupme_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mx-puppet-groupme-registration.yaml"] + }} + when: matrix_mx_puppet_groupme_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml index 070f920b..8cc55759 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_groupme_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_groupme_enabled | bool" tags: - setup-all - setup-mx-puppet-groupme -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_groupme_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_groupme_enabled | bool" tags: - setup-all - setup-mx-puppet-groupme -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_groupme_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_groupme_enabled | bool" tags: - setup-all - setup-mx-puppet-groupme diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml index 286c5611..497f0109 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml @@ -3,13 +3,13 @@ # 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-mx-puppet-groupme role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Groupme paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_groupme_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_groupme_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_groupme_docker_src_files_path }}", when: "{{ matrix_mx_puppet_groupme_container_image_self_build }}"} - when: matrix_mx_puppet_groupme_enabled|bool and item.when|bool + when: matrix_mx_puppet_groupme_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_groupme_base_path }}/database.db" register: matrix_mx_puppet_groupme_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-groupme.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-groupme state: stopped enabled: false @@ -37,33 +37,35 @@ when: "matrix_mx_puppet_groupme_stat_database.stat.exists" - name: (Data relocation) Move mx-puppet-groupme database file to ./data directory - command: "mv {{ matrix_mx_puppet_groupme_base_path }}/database.db {{ matrix_mx_puppet_groupme_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_groupme_base_path }}/database.db {{ matrix_mx_puppet_groupme_data_path }}/database.db" when: "matrix_mx_puppet_groupme_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_groupme_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_groupme_sqlite_database_path_local }}" register: matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_groupme_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_groupme_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_groupme_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-groupme.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_groupme_requires_restart: true - when: "matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_groupme_database_engine == 'postgres'" - name: Ensure MX Puppet Groupme image is pulled @@ -72,21 +74,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_groupme_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_mx_puppet_groupme_docker_image_force_pull }}" - when: matrix_mx_puppet_groupme_enabled|bool and not matrix_mx_puppet_groupme_container_image_self_build + when: matrix_mx_puppet_groupme_enabled | bool and not matrix_mx_puppet_groupme_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Groupme repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_groupme_container_image_self_build_repo }}" + version: "{{ matrix_mx_puppet_groupme_container_image_self_build_repo_version }}" dest: "{{ matrix_mx_puppet_groupme_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_groupme_git_pull_results - when: "matrix_mx_puppet_groupme_enabled|bool and matrix_mx_puppet_groupme_container_image_self_build" + when: "matrix_mx_puppet_groupme_enabled | bool and matrix_mx_puppet_groupme_container_image_self_build" - name: Ensure MX Puppet Groupme Docker image is built docker_image: @@ -98,38 +101,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_groupme_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_groupme_enabled|bool and matrix_mx_puppet_groupme_container_image_self_build" + when: "matrix_mx_puppet_groupme_enabled | bool and matrix_mx_puppet_groupme_container_image_self_build" - name: Ensure mx-puppet-groupme config.yaml installed - copy: - content: "{{ matrix_mx_puppet_groupme_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_groupme_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_groupme_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-groupme groupme-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_groupme_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_groupme_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_groupme_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-groupme.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-groupme.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-groupme.service" mode: 0644 register: matrix_mx_puppet_groupme_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-groupme.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_groupme_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-groupme.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-groupme.service" state: restarted - when: "matrix_mx_puppet_groupme_requires_restart|bool" + when: "matrix_mx_puppet_groupme_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml index 24daf7be..5ded6107 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-groupme service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-groupme.service" register: matrix_mx_puppet_groupme_service_stat - name: Ensure matrix-mx-puppet-groupme is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-groupme state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_groupme_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-groupme.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-groupme.service" state: absent when: "matrix_mx_puppet_groupme_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-groupme.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_groupme_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml index 5c5463ce..d091de6d 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-groupme/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-groupme/templates/config.yaml.j2 index a9ab7701..357baec7 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mx-puppet-groupme/templates/config.yaml.j2 @@ -78,7 +78,7 @@ logging: # Log level of console output # Allowed values starting with most verbose: # silly, debug, verbose, info, warn, error - console: info + console: warn # Date and time formatting lineDateFormat: MMM-D HH:mm:ss.SSS # Logging files diff --git a/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml b/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml index 3a73e0fe..aae6eb5a 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml @@ -1,11 +1,12 @@ --- # mx-puppet-instagram bridges instagram DMs -# See: https://github.com/Sorunome/mx-puppet-instagram +# Project source code URL: https://github.com/Sorunome/mx-puppet-instagram matrix_mx_puppet_instagram_enabled: true matrix_mx_puppet_instagram_container_image_self_build: false matrix_mx_puppet_instagram_container_image_self_build_repo: "https://github.com/Sorunome/mx-puppet-instagram.git" +matrix_mx_puppet_instagram_container_image_self_build_repo_version: "{{ 'master' if matrix_mx_puppet_instagram_version == 'latest' else matrix_mx_puppet_instagram_version }}" matrix_mx_puppet_instagram_version: latest matrix_mx_puppet_instagram_docker_image: "{{ matrix_mx_puppet_instagram_docker_image_name_prefix }}sorunome/mx-puppet-instagram:{{ matrix_mx_puppet_instagram_version }}" @@ -26,7 +27,7 @@ matrix_mx_puppet_instagram_appservice_address: 'http://matrix-mx-puppet-instagra # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_instagram_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -77,11 +78,11 @@ matrix_mx_puppet_instagram_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_instagram_configuration_yaml`. -matrix_mx_puppet_instagram_configuration_extension: "{{ matrix_mx_puppet_instagram_configuration_extension_yaml|from_yaml if matrix_mx_puppet_instagram_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_instagram_configuration_extension: "{{ matrix_mx_puppet_instagram_configuration_extension_yaml | from_yaml if matrix_mx_puppet_instagram_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_instagram_configuration_yaml`. -matrix_mx_puppet_instagram_configuration: "{{ matrix_mx_puppet_instagram_configuration_yaml|from_yaml|combine(matrix_mx_puppet_instagram_configuration_extension, recursive=True) }}" +matrix_mx_puppet_instagram_configuration: "{{ matrix_mx_puppet_instagram_configuration_yaml | from_yaml | combine(matrix_mx_puppet_instagram_configuration_extension, recursive=True) }}" matrix_mx_puppet_instagram_registration_yaml: | as_token: "{{ matrix_mx_puppet_instagram_appservice_token }}" @@ -90,15 +91,15 @@ matrix_mx_puppet_instagram_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain|regex_escape }}' + regex: '@_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain|regex_escape }}' + regex: '#_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _instagrampuppet_bot url: {{ matrix_mx_puppet_instagram_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_instagram_registration: "{{ matrix_mx_puppet_instagram_registration_yaml|from_yaml }}" +matrix_mx_puppet_instagram_registration: "{{ matrix_mx_puppet_instagram_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml index d16e6be0..850c6859 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml @@ -2,23 +2,27 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the mx-puppet-instagram image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_instagram_container_image_self_build and matrix_mx_puppet_instagram_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-instagram.service'] }}" - when: matrix_mx_puppet_instagram_enabled|bool + when: matrix_mx_puppet_instagram_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([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_instagram_config_path }}/registration.yaml,dst=/matrix-mx-puppet-instagram-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mx_puppet_instagram_config_path }}/registration.yaml,dst=/matrix-mx-puppet-instagram-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-instagram-registration.yaml"] }} - when: matrix_mx_puppet_instagram_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mx-puppet-instagram-registration.yaml"] + }} + when: matrix_mx_puppet_instagram_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml index 6abb281f..978577cc 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_instagram_enabled | bool" tags: - setup-all - setup-mx-puppet-instagram -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_instagram_enabled | bool" tags: - setup-all - setup-mx-puppet-instagram -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_instagram_enabled | bool" tags: - setup-all - setup-mx-puppet-instagram diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml index 2e74c059..7695d88e 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml @@ -3,36 +3,38 @@ # 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-mx-puppet-instagram role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_instagram_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_instagram_sqlite_database_path_local }}" register: matrix_mx_puppet_instagram_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_instagram_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_instagram_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_instagram_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-instagram.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_instagram_requires_restart: true - when: "matrix_mx_puppet_instagram_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_instagram_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_instagram_database_engine == 'postgres'" - name: Ensure mx-puppet-instagram image is pulled @@ -41,14 +43,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_instagram_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_mx_puppet_instagram_docker_image_force_pull }}" - when: matrix_mx_puppet_instagram_enabled|bool and not matrix_mx_puppet_instagram_container_image_self_build + when: matrix_mx_puppet_instagram_enabled | bool and not matrix_mx_puppet_instagram_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure mx-puppet-instagram paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -59,17 +61,18 @@ - {path: "{{ matrix_mx_puppet_instagram_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_instagram_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_instagram_docker_src_files_path }}", when: "{{ matrix_mx_puppet_instagram_container_image_self_build }}"} - when: matrix_mx_puppet_instagram_enabled|bool and item.when|bool + when: matrix_mx_puppet_instagram_enabled | bool and item.when | bool - name: Ensure mx-puppet-instagram repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_instagram_container_image_self_build_repo }}" + version: "{{ matrix_mx_puppet_instagram_container_image_self_build_repo_version }}" dest: "{{ matrix_mx_puppet_instagram_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_instagram_git_pull_results - when: "matrix_mx_puppet_instagram_enabled|bool and matrix_mx_puppet_instagram_container_image_self_build|bool" + when: "matrix_mx_puppet_instagram_enabled | bool and matrix_mx_puppet_instagram_container_image_self_build | bool" - name: Ensure mx-puppet-instagram Docker image is built docker_image: @@ -81,38 +84,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_instagram_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_instagram_enabled|bool and matrix_mx_puppet_instagram_container_image_self_build|bool" + when: "matrix_mx_puppet_instagram_enabled | bool and matrix_mx_puppet_instagram_container_image_self_build | bool" - name: Ensure mx-puppet-instagram config.yaml installed - copy: - content: "{{ matrix_mx_puppet_instagram_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_instagram_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_instagram_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-instagram-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_instagram_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_instagram_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_instagram_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-instagram.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-instagram.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-instagram.service" mode: 0644 register: matrix_mx_puppet_instagram_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-instagram.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_instagram_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-instagram.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-instagram.service" state: restarted - when: "matrix_mx_puppet_instagram_requires_restart|bool" + when: "matrix_mx_puppet_instagram_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml index e4435a3e..2d5a98aa 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-instagram service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-instagram.service" register: matrix_mx_puppet_instagram_service_stat - name: Ensure matrix-mx-puppet-instagram is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-instagram state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_instagram_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-instagram.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-instagram.service" state: absent when: "matrix_mx_puppet_instagram_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-instagram.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_instagram_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml index b6d9d994..383fe502 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-instagram/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-instagram/templates/config.yaml.j2 index 1c4bb1bd..57c5b0f0 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mx-puppet-instagram/templates/config.yaml.j2 @@ -18,7 +18,7 @@ presence: # Bridge Instagram online/offline status enabled: true # How often to send status to the homeserver in milliseconds - interval: 500 + interval: 5000 provisioning: # Regex of Matrix IDs allowed to use the puppet bridge @@ -61,7 +61,7 @@ logging: # Log level of console output # Allowed values starting with most verbose: # silly, debug, verbose, info, warn, error - console: info + console: warn # Date and time formatting lineDateFormat: MMM-D HH:mm:ss.SSS # Logging files diff --git a/roles/matrix-bridge-mx-puppet-skype/defaults/main.yml b/roles/matrix-bridge-mx-puppet-skype/defaults/main.yml deleted file mode 100644 index 905e5086..00000000 --- a/roles/matrix-bridge-mx-puppet-skype/defaults/main.yml +++ /dev/null @@ -1,112 +0,0 @@ ---- -# Mx Puppet Skype is a Matrix <-> Skype bridge -# See: https://github.com/Sorunome/mx-puppet-skype - -matrix_mx_puppet_skype_enabled: true - -matrix_mx_puppet_skype_container_image_self_build: false -matrix_mx_puppet_skype_container_image_self_build_repo: "https://github.com/Sorunome/mx-puppet-skype.git" - -matrix_mx_puppet_skype_version: latest -matrix_mx_puppet_skype_docker_image: "{{ matrix_mx_puppet_skype_docker_image_name_prefix }}sorunome/mx-puppet-skype:{{ matrix_mx_puppet_skype_version }}" -matrix_mx_puppet_skype_docker_image_name_prefix: "{{ 'localhost/' if matrix_mx_puppet_skype_container_image_self_build else matrix_container_global_registry_prefix }}" -matrix_mx_puppet_skype_docker_image_force_pull: "{{ matrix_mx_puppet_skype_docker_image.endswith(':latest') }}" - -matrix_mx_puppet_skype_base_path: "{{ matrix_base_data_path }}/mx-puppet-skype" -matrix_mx_puppet_skype_config_path: "{{ matrix_mx_puppet_skype_base_path }}/config" -matrix_mx_puppet_skype_data_path: "{{ matrix_mx_puppet_skype_base_path }}/data" -matrix_mx_puppet_skype_docker_src_files_path: "{{ matrix_mx_puppet_skype_base_path }}/docker-src" - -matrix_mx_puppet_skype_appservice_port: "8438" - -matrix_mx_puppet_skype_homeserver_address: "{{ matrix_homeserver_container_url }}" -matrix_mx_puppet_skype_appservice_address: 'http://matrix-mx-puppet-skype:{{ matrix_mx_puppet_skype_appservice_port }}' - -# "@user:server.com" to allow specific user -# "@.*:yourserver.com" to allow users on a specific homeserver -# "@.*" to allow anyone -matrix_mx_puppet_skype_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" - -# Leave empty to disable blacklist -# "@user:server.com" disallow a specific user -# "@.*:yourserver.com" disallow users on a specific homeserver -matrix_mx_puppet_skype_provisioning_blacklist: [] - -# Same as provisioning -matrix_mx_puppet_skype_relay_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" - -# Same as provisioning -matrix_mx_puppet_skype_relay_blacklist: [] - -# A list of extra arguments to pass to the container -matrix_mx_puppet_skype_container_extra_arguments: [] - -# List of systemd services that matrix-puppet-skype.service depends on. -matrix_mx_puppet_skype_systemd_required_services_list: ['docker.service'] - -# List of systemd services that matrix-puppet-skype.service wants -matrix_mx_puppet_skype_systemd_wanted_services_list: [] - -matrix_mx_puppet_skype_appservice_token: '' -matrix_mx_puppet_skype_homeserver_token: '' - -# Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). -matrix_mx_puppet_skype_login_shared_secret: '' - -# Database configuration, role default is `sqlite` but playbook default is `postgres` -matrix_mx_puppet_skype_database_engine: sqlite - -matrix_mx_puppet_skype_sqlite_database_path_local: "{{ matrix_mx_puppet_skype_data_path }}/database.db" -matrix_mx_puppet_skype_sqlite_database_path_in_container: "/data/database.db" - -matrix_mx_puppet_skype_database_username: matrix_mx_puppet_skype -matrix_mx_puppet_skype_database_password: ~ -matrix_mx_puppet_skype_database_hostname: 'matrix-postgres' -matrix_mx_puppet_skype_database_port: 5432 -matrix_mx_puppet_skype_database_name: matrix_mx_puppet_skype - -matrix_mx_puppet_skype_database_connection_string: 'postgresql://{{ matrix_mx_puppet_skype_database_username }}:{{ matrix_mx_puppet_skype_database_password }}@{{ matrix_mx_puppet_skype_database_hostname }}:{{ matrix_mx_puppet_skype_database_port }}/{{ matrix_mx_puppet_skype_database_name }}?sslmode=disable' - -# Default configuration template which covers the generic use case. -# You can customize it by controlling the various variables inside it. -# -# For a more advanced customization, you can extend the default (see `matrix_mx_puppet_skype_configuration_extension_yaml`) -# or completely replace this variable with your own template. -matrix_mx_puppet_skype_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" - -matrix_mx_puppet_skype_configuration_extension_yaml: | - # Your custom YAML configuration goes here. - # This configuration extends the default starting configuration (`matrix_mx_puppet_skype_configuration_yaml`). - # - # You can override individual variables from the default configuration, or introduce new ones. - # - # If you need something more special, you can take full control by - # completely redefining `matrix_mx_puppet_skype_configuration_yaml`. - -matrix_mx_puppet_skype_configuration_extension: "{{ matrix_mx_puppet_skype_configuration_extension_yaml|from_yaml if matrix_mx_puppet_skype_configuration_extension_yaml|from_yaml is mapping else {} }}" - -# Holds the final configuration (a combination of the default and its extension). -# You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_skype_configuration_yaml`. -matrix_mx_puppet_skype_configuration: "{{ matrix_mx_puppet_skype_configuration_yaml|from_yaml|combine(matrix_mx_puppet_skype_configuration_extension, recursive=True) }}" - -matrix_mx_puppet_skype_registration_yaml: | - as_token: "{{ matrix_mx_puppet_skype_appservice_token }}" - hs_token: "{{ matrix_mx_puppet_skype_homeserver_token }}" - id: skype-puppet - namespaces: - users: - - exclusive: true - regex: '@_skypepuppet_.*:{{ matrix_domain|regex_escape }}' - rooms: [] - aliases: - - exclusive: true - regex: '#_skypepuppet_.*:{{ matrix_domain|regex_escape }}' - protocols: [] - rate_limited: false - sender_localpart: _skypepuppet_bot - url: {{ matrix_mx_puppet_skype_appservice_address }} - de.sorunome.msc2409.push_ephemeral: true - -matrix_mx_puppet_skype_registration: "{{ matrix_mx_puppet_skype_registration_yaml|from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-skype/tasks/init.yml b/roles/matrix-bridge-mx-puppet-skype/tasks/init.yml deleted file mode 100644 index d28f6ca1..00000000 --- a/roles/matrix-bridge-mx-puppet-skype/tasks/init.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 -# and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 -- name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" - when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_skype_container_image_self_build and matrix_mx_puppet_skype_enabled" - -- set_fact: - matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-skype.service'] }}" - when: matrix_mx_puppet_skype_enabled|bool - -# If the matrix-synapse role is not used, these variables may not exist. -- set_fact: - matrix_synapse_container_extra_arguments: > - {{ matrix_synapse_container_extra_arguments|default([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_skype_config_path }}/registration.yaml,dst=/matrix-mx-puppet-skype-registration.yaml,ro"] - - matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-skype-registration.yaml"] }} - when: matrix_mx_puppet_skype_enabled|bool diff --git a/roles/matrix-bridge-mx-puppet-skype/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-skype/tasks/setup_install.yml deleted file mode 100644 index 96ae82e6..00000000 --- a/roles/matrix-bridge-mx-puppet-skype/tasks/setup_install.yml +++ /dev/null @@ -1,135 +0,0 @@ ---- - -# 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: - msg: >- - The matrix-bridge-mx-puppet-skype role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" - -- name: Ensure MX Puppet Skype paths exist - file: - path: "{{ item.path }}" - state: directory - mode: 0750 - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_groupname }}" - with_items: - - {path: "{{ matrix_mx_puppet_skype_base_path }}", when: true} - - {path: "{{ matrix_mx_puppet_skype_config_path }}", when: true} - - {path: "{{ matrix_mx_puppet_skype_data_path }}", when: true} - - {path: "{{ matrix_mx_puppet_skype_docker_src_files_path }}", when: "{{ matrix_mx_puppet_skype_container_image_self_build }}"} - when: matrix_mx_puppet_skype_enabled|bool and item.when|bool - -- name: Check if an old database file already exists - stat: - path: "{{ matrix_mx_puppet_skype_base_path }}/database.db" - register: matrix_mx_puppet_skype_stat_database - -- name: (Data relocation) Ensure matrix-mx-puppet-skype.service is stopped - service: - name: matrix-mx-puppet-skype - state: stopped - enabled: false - daemon_reload: true - failed_when: false - when: "matrix_mx_puppet_skype_stat_database.stat.exists" - -- name: (Data relocation) Move mx-puppet-skype database file to ./data directory - command: "mv {{ matrix_mx_puppet_skype_base_path }}/database.db {{ matrix_mx_puppet_skype_data_path }}/database.db" - when: "matrix_mx_puppet_skype_stat_database.stat.exists" - -- set_fact: - matrix_mx_puppet_skype_requires_restart: false - -- block: - - name: Check if an SQLite database already exists - stat: - path: "{{ matrix_mx_puppet_skype_sqlite_database_path_local }}" - register: matrix_mx_puppet_skype_sqlite_database_path_local_stat_result - - - block: - - set_fact: - matrix_postgres_db_migration_request: - src: "{{ matrix_mx_puppet_skype_sqlite_database_path_local }}" - dst: "{{ matrix_mx_puppet_skype_database_connection_string }}" - caller: "{{ role_path|basename }}" - engine_variable_name: 'matrix_mx_puppet_skype_database_engine' - engine_old: 'sqlite' - systemd_services_to_stop: ['matrix-mx-puppet-skype.service'] - - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - - - set_fact: - matrix_mx_puppet_skype_requires_restart: true - when: "matrix_mx_puppet_skype_sqlite_database_path_local_stat_result.stat.exists|bool" - when: "matrix_mx_puppet_skype_database_engine == 'postgres'" - -- name: Ensure MX Puppet Skype image is pulled - docker_image: - name: "{{ matrix_mx_puppet_skype_docker_image }}" - source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" - force_source: "{{ matrix_mx_puppet_skype_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_mx_puppet_skype_docker_image_force_pull }}" - when: matrix_mx_puppet_skype_enabled|bool and not matrix_mx_puppet_skype_container_image_self_build - register: result - retries: "{{ matrix_container_retries_count }}" - delay: "{{ matrix_container_retries_delay }}" - until: result is not failed - -- name: Ensure MX Puppet Skype repository is present on self build - git: - repo: "{{ matrix_mx_puppet_skype_container_image_self_build_repo }}" - dest: "{{ matrix_mx_puppet_skype_docker_src_files_path }}" - force: "yes" - become: true - become_user: "{{ matrix_user_username }}" - register: matrix_mx_puppet_skype_git_pull_results - when: "matrix_mx_puppet_skype_enabled|bool and matrix_mx_puppet_skype_container_image_self_build|bool" - -- name: Ensure MX Puppet Skype Docker image is built - docker_image: - name: "{{ matrix_mx_puppet_skype_docker_image }}" - source: build - force_source: "{{ matrix_mx_puppet_skype_git_pull_results.changed 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_mx_puppet_skype_git_pull_results.changed }}" - build: - dockerfile: Dockerfile - path: "{{ matrix_mx_puppet_skype_docker_src_files_path }}" - pull: true - when: "matrix_mx_puppet_skype_enabled|bool and matrix_mx_puppet_skype_container_image_self_build|bool" - -- name: Ensure mx-puppet-skype config.yaml installed - copy: - content: "{{ matrix_mx_puppet_skype_configuration|to_nice_yaml(indent=2, width=999999) }}" - dest: "{{ matrix_mx_puppet_skype_config_path }}/config.yaml" - mode: 0644 - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_groupname }}" - -- name: Ensure mx-puppet-skype skype-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_skype_registration|to_nice_yaml(indent=2, width=999999) }}" - dest: "{{ matrix_mx_puppet_skype_config_path }}/registration.yaml" - mode: 0644 - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_groupname }}" - -- name: Ensure matrix-mx-puppet-skype.service installed - template: - src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-skype.service.j2" - dest: "/etc/systemd/system/matrix-mx-puppet-skype.service" - mode: 0644 - register: matrix_mx_puppet_skype_systemd_service_result - -- name: Ensure systemd reloaded after matrix-mx-puppet-skype.service installation - service: - daemon_reload: true - when: "matrix_mx_puppet_skype_systemd_service_result.changed" - -- name: Ensure matrix-mx-puppet-skype.service restarted, if necessary - service: - name: "matrix-mx-puppet-skype.service" - state: restarted - when: "matrix_mx_puppet_skype_requires_restart|bool" diff --git a/roles/matrix-bridge-mx-puppet-skype/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-skype/tasks/setup_uninstall.yml deleted file mode 100644 index 838c3be5..00000000 --- a/roles/matrix-bridge-mx-puppet-skype/tasks/setup_uninstall.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- - -- name: Check existence of matrix-mx-puppet-skype service - stat: - path: "/etc/systemd/system/matrix-mx-puppet-skype.service" - register: matrix_mx_puppet_skype_service_stat - -- name: Ensure matrix-mx-puppet-skype is stopped - service: - name: matrix-mx-puppet-skype - state: stopped - enabled: false - daemon_reload: true - when: "matrix_mx_puppet_skype_service_stat.stat.exists" - -- name: Ensure matrix-mx-puppet-skype.service doesn't exist - file: - path: "/etc/systemd/system/matrix-mx-puppet-skype.service" - state: absent - when: "matrix_mx_puppet_skype_service_stat.stat.exists" - -- name: Ensure systemd reloaded after matrix-mx-puppet-skype.service removal - service: - daemon_reload: true - when: "matrix_mx_puppet_skype_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-skype/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-skype/templates/config.yaml.j2 deleted file mode 100644 index 1d6d4828..00000000 --- a/roles/matrix-bridge-mx-puppet-skype/templates/config.yaml.j2 +++ /dev/null @@ -1,118 +0,0 @@ -#jinja2: lstrip_blocks: "True" -bridge: - # Address for the bridge to bind to; if running as a Docker container, you - # probably want 0.0.0.0 here - bindAddress: 0.0.0.0 - # Port to host the bridge on which your homeserver will connect to - port: {{ matrix_mx_puppet_skype_appservice_port }} - # Name of your homeserver - domain: {{ matrix_domain }} - # URL where the bridge can connect to your homeserver - homeserverUrl: {{ matrix_mx_puppet_skype_homeserver_address }} - # Optionally specify a different media URL used for the media store - mediaURL: https://{{ matrix_server_fqn_matrix }} - # This enabled automatic double-puppeting: - # A map for shared secrets of the homeserver URL to the shared secret - # See https://github.com/devture/matrix-synapse-shared-secret-auth - #loginSharedSecretMap: - # yourserver.com: supersecretsharedsecret - {% if matrix_mx_puppet_skype_login_shared_secret != '' %} - loginSharedSecretMap: - {{ matrix_domain }}: {{ matrix_mx_puppet_skype_login_shared_secret }} - {% endif %} - # optionally override the display name of the bridge bot - #displayname: Protocol Bot - # optionally set the avatar of the bridge bot - #avatarUrl: mxc://yourserver.com/somefile - -logging: - # Log level of console output - # Allowed values starting with most verbose: - # silly, debug, verbose, info, warn, error - console: info - # Optionally, you can apply filters to the console logging - #console: - # level: info - # enabled: - # - Store - # disabled: - # - PresenceHandler - - # Date and time formatting - lineDateFormat: MMM-D HH:mm:ss.SSS - # Logging files - # Log files are rotated daily by default - files: [] - -database: -{% if matrix_mx_puppet_skype_database_engine == 'postgres' %} - # Use Postgres as a database backend - # If set, will be used instead of SQLite3 - # Connection string to connect to the Postgres instance - # with username "user", password "pass", host "localhost" and database name "dbname". - # Modify each value as necessary - connString: {{ matrix_mx_puppet_skype_database_connection_string|to_json }} -{% else %} - # Use SQLite3 as a database backend - # The name of the database file - filename: {{ matrix_mx_puppet_skype_sqlite_database_path_in_container|to_json }} -{% endif %} - -provisioning: - # Regex of Matrix IDs allowed to use the puppet bridge - whitelist: {{ matrix_mx_puppet_skype_provisioning_whitelist|to_json }} - # Allow a specific user - #- "@user:server\\.com" - # Allow users on a specific homeserver - #- "@.*:yourserver\\.com" - # Allow anyone - #- ".*" - - # Regex of Matrix IDs forbidden from using the puppet bridge - #blacklist: - # Disallow a specific user - #- "@user:server\\.com" - # Disallow users on a specific homeserver - #- "@.*:yourserver\\.com" - blacklist: {{ matrix_mx_puppet_skype_provisioning_blacklist|to_json }} - -presence: - # Bridge online/offline status - enabled: true - # How often to send status to the homeserver in milliseconds - interval: 500 - # if the im.vector.user_status state setting should be diabled - #disableStatusState: false - # A blacklist of remote user IDs for the im.vector.user_status state setting - #statusStateBlacklist: - # - baduser - -relay: - # Regex of Matrix IDs to allow to use the relay mode - # Same format as in provisioning - #whitelist: - #- "@.*:yourserver\\.com" - whitelist: {{ matrix_mx_puppet_skype_relay_whitelist|to_json }} - - #blacklist: - #- "@user:yourserver\\.com" - blacklist: {{ matrix_mx_puppet_skype_relay_blacklist|to_json }} - -# Map certain homeserver URLs to the C-S API endpoint -# Useful for double-puppeting if .well-known is unavailable for some reason -#homeserverUrlMap: -# yourserver.com: http://localhost:1234 - -namePatterns: - # Override the protocols set default name patterns - # Which variables are available depends on protocol implementation - user: :name - room: :name - -limits: - # Up to how many users should be auto-joined on room creation? -1 to disable - # Defaults to 200 - maxAutojoinUsers: 200 - # How long the delay between two autojoin users should be, in millisectonds. - # Defaults to 5000 - roomUserAutojoinDelay: 5000 diff --git a/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml b/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml index bb92c1d8..eae0b933 100644 --- a/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml @@ -1,6 +1,6 @@ --- # Mx Puppet Slack is a Matrix <-> Slack bridge -# See: https://gitlab.com/beeper/mx-puppet-monorepo (originally based on https://github.com/Sorunome/mx-puppet-slack) +# Project source code URL: https://gitlab.com/mx-puppet/slack/mx-puppet-slack matrix_mx_puppet_slack_enabled: true @@ -8,17 +8,17 @@ matrix_mx_puppet_slack_oauth_client_id: '' matrix_mx_puppet_slack_oauth_client_secret: '' matrix_mx_puppet_slack_container_image_self_build: false -matrix_mx_puppet_slack_container_image_self_build_repo: "https://gitlab.com/beeper/mx-puppet-monorepo.git" +matrix_mx_puppet_slack_container_image_self_build_repo: "https://gitlab.com/mx-puppet/slack/mx-puppet-slack.git" matrix_mx_puppet_slack_container_image_self_build_version: "{{ 'main' if matrix_mx_puppet_slack_version == 'latest' else matrix_mx_puppet_slack_version }}" -matrix_mx_puppet_slack_container_image_self_build_dockerfile_path: "docker/Dockerfile-slack" +matrix_mx_puppet_slack_container_image_self_build_dockerfile_path: "Dockerfile" # Controls whether the mx-puppet-slack container exposes its HTTP port (tcp/8432 in the container). # # Takes an ":" or "" value (e.g. "127.0.0.1:8432"), or empty string to not expose. matrix_mx_puppet_slack_container_http_host_bind_port: '' -matrix_mx_puppet_slack_version: latest -matrix_mx_puppet_slack_docker_image: "{{ matrix_mx_puppet_slack_docker_image_name_prefix }}beeper/mx-puppet-monorepo/slack:{{ matrix_mx_puppet_slack_version }}" +matrix_mx_puppet_slack_version: v0.1.2 +matrix_mx_puppet_slack_docker_image: "{{ matrix_mx_puppet_slack_docker_image_name_prefix }}mx-puppet/slack/mx-puppet-slack:{{ matrix_mx_puppet_slack_version }}" matrix_mx_puppet_slack_docker_image_name_prefix: "{{ 'localhost/' if matrix_mx_puppet_slack_container_image_self_build else 'registry.gitlab.com/' }}" matrix_mx_puppet_slack_docker_image_force_pull: "{{ matrix_mx_puppet_slack_docker_image.endswith(':latest') }}" @@ -40,7 +40,7 @@ matrix_mx_puppet_slack_redirect_uri: 'https://{{ matrix_server_fqn_matrix }}{{ m # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_slack_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -92,11 +92,11 @@ matrix_mx_puppet_slack_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_slack_configuration_yaml`. -matrix_mx_puppet_slack_configuration_extension: "{{ matrix_mx_puppet_slack_configuration_extension_yaml|from_yaml if matrix_mx_puppet_slack_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_slack_configuration_extension: "{{ matrix_mx_puppet_slack_configuration_extension_yaml | from_yaml if matrix_mx_puppet_slack_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_slack_configuration_yaml`. -matrix_mx_puppet_slack_configuration: "{{ matrix_mx_puppet_slack_configuration_yaml|from_yaml|combine(matrix_mx_puppet_slack_configuration_extension, recursive=True) }}" +matrix_mx_puppet_slack_configuration: "{{ matrix_mx_puppet_slack_configuration_yaml | from_yaml | combine(matrix_mx_puppet_slack_configuration_extension, recursive=True) }}" matrix_mx_puppet_slack_registration_yaml: | as_token: "{{ matrix_mx_puppet_slack_appservice_token }}" @@ -105,15 +105,15 @@ matrix_mx_puppet_slack_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain|regex_escape }}' + regex: '@_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain|regex_escape }}' + regex: '#_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _slackpuppet_bot url: {{ matrix_mx_puppet_slack_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_slack_registration: "{{ matrix_mx_puppet_slack_registration_yaml|from_yaml }}" +matrix_mx_puppet_slack_registration: "{{ matrix_mx_puppet_slack_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml index 66d51784..2213df55 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml @@ -2,42 +2,46 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the mx-puppet-slack image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_slack_container_image_self_build and matrix_mx_puppet_slack_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-slack.service'] }}" - when: matrix_mx_puppet_slack_enabled|bool + when: matrix_mx_puppet_slack_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([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_slack_config_path }}/registration.yaml,dst=/matrix-mx-puppet-slack-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mx_puppet_slack_config_path }}/registration.yaml,dst=/matrix-mx-puppet-slack-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-slack-registration.yaml"] }} - when: matrix_mx_puppet_slack_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mx-puppet-slack-registration.yaml"] + }} + when: matrix_mx_puppet_slack_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Slack Appservice's 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-mx-puppet-slack role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix MX Puppet Slack proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mx_puppet_slack_matrix_nginx_proxy_configuration: | location {{ matrix_mx_puppet_slack_redirect_path }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_mx_puppet_slack_appservice_address }}"; @@ -49,23 +53,23 @@ } - name: Register Slack Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mx_puppet_slack_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mx_puppet_slack_enabled|bool + when: matrix_mx_puppet_slack_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix Slack bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mx_puppet_slack_redirect_path }}` URL endpoint to the matrix-mx-puppet-slack container. You can expose the container's port using the `matrix_appservice_slack_container_http_host_bind_port` variable. - when: "matrix_mx_puppet_slack_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mx_puppet_slack_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml index 0e886d45..869afc49 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_slack_enabled | bool" tags: - setup-all - setup-mx-puppet-slack -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_slack_enabled | bool" tags: - setup-all - setup-mx-puppet-slack -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_slack_enabled | bool" tags: - setup-all - setup-mx-puppet-slack diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml index 3a7dfb40..70dac9ac 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml @@ -3,13 +3,13 @@ # 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-mx-puppet-slack role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Slack paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_slack_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_slack_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_slack_docker_src_files_path }}", when: "{{ matrix_mx_puppet_slack_container_image_self_build }}"} - when: matrix_mx_puppet_slack_enabled|bool and item.when|bool + when: matrix_mx_puppet_slack_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_slack_base_path }}/database.db" register: matrix_mx_puppet_slack_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-slack.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-slack state: stopped enabled: false @@ -36,30 +36,32 @@ failed_when: false when: "matrix_mx_puppet_slack_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_slack_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_slack_sqlite_database_path_local }}" register: matrix_mx_puppet_slack_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_slack_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_slack_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_slack_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-slack.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_slack_requires_restart: true - when: "matrix_mx_puppet_slack_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_slack_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_slack_database_engine == 'postgres'" - name: Ensure MX Puppet Slack image is pulled @@ -68,14 +70,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_slack_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_mx_puppet_slack_docker_image_force_pull }}" - when: matrix_mx_puppet_slack_enabled|bool and not matrix_mx_puppet_slack_container_image_self_build + when: matrix_mx_puppet_slack_enabled | bool and not matrix_mx_puppet_slack_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Slack repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_slack_container_image_self_build_repo }}" dest: "{{ matrix_mx_puppet_slack_docker_src_files_path }}" force: "yes" @@ -83,7 +85,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_slack_git_pull_results - when: "matrix_mx_puppet_slack_enabled|bool and matrix_mx_puppet_slack_container_image_self_build" + when: "matrix_mx_puppet_slack_enabled | bool and matrix_mx_puppet_slack_container_image_self_build" - name: Ensure MX Puppet Slack Docker image is built docker_image: @@ -95,42 +97,42 @@ dockerfile: "{{ matrix_mx_puppet_slack_container_image_self_build_dockerfile_path }}" path: "{{ matrix_mx_puppet_slack_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_slack_enabled|bool and matrix_mx_puppet_slack_container_image_self_build" + when: "matrix_mx_puppet_slack_enabled | bool and matrix_mx_puppet_slack_container_image_self_build" - name: (Data relocation) Move mx-puppet-slack database file to ./data directory - command: "mv {{ matrix_mx_puppet_slack_base_path }}/database.db {{ matrix_mx_puppet_slack_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_slack_base_path }}/database.db {{ matrix_mx_puppet_slack_data_path }}/database.db" when: "matrix_mx_puppet_slack_stat_database.stat.exists" - name: Ensure mx-puppet-slack config.yaml installed - copy: - content: "{{ matrix_mx_puppet_slack_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_slack_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_slack_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-slack slack-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_slack_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_slack_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_slack_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-slack.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-slack.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-slack.service" mode: 0644 register: matrix_mx_puppet_slack_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-slack.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_slack_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-slack.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-slack.service" state: restarted - when: "matrix_mx_puppet_slack_requires_restart|bool" + when: "matrix_mx_puppet_slack_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml index 3a119267..3f91b467 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-slack service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-slack.service" register: matrix_mx_puppet_slack_service_stat - name: Ensure matrix-mx-puppet-slack is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-slack state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_slack_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-slack.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-slack.service" state: absent when: "matrix_mx_puppet_slack_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-slack.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_slack_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml index 3a0bca11..ea917f97 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-slack/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-slack/templates/config.yaml.j2 index c7497a84..b84fe221 100644 --- a/roles/matrix-bridge-mx-puppet-slack/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mx-puppet-slack/templates/config.yaml.j2 @@ -32,7 +32,7 @@ presence: # Bridge Discord online/offline status enabled: true # How often to send status to the homeserver in milliseconds - interval: 500 + interval: 5000 provisioning: # Regex of Matrix IDs allowed to use the puppet bridge @@ -75,7 +75,7 @@ logging: # Log level of console output # Allowed values starting with most verbose: # silly, debug, verbose, info, warn, error - console: info + console: warn # Date and time formatting lineDateFormat: MMM-D HH:mm:ss.SSS # Logging files diff --git a/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml b/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml index 4e3d6bc6..89541162 100644 --- a/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml @@ -1,11 +1,12 @@ --- # Mx Puppet Steam is a Matrix <-> Steam bridge -# See: https://github.com/matrix-steam/mx-puppet-steam +# Project source code URL: https://github.com/icewind1991/mx-puppet-steam matrix_mx_puppet_steam_enabled: true matrix_mx_puppet_steam_container_image_self_build: false -matrix_mx_puppet_steam_container_image_self_build_repo: "https://github.com/tilosp/mx-puppet-steam.git" +matrix_mx_puppet_steam_container_image_self_build_repo: "https://github.com/icewind1991/mx-puppet-steam.git" +matrix_mx_puppet_steam_container_image_self_build_repo_version: "{{ 'master' if matrix_mx_puppet_steam_version == 'latest' else matrix_mx_puppet_steam_version }}" # Controls whether the mx-puppet-steam container exposes its HTTP port (tcp/8432 in the container). # @@ -32,7 +33,7 @@ matrix_mx_puppet_steam_appservice_address: 'http://matrix-mx-puppet-steam:{{ mat # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_steam_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -83,11 +84,11 @@ matrix_mx_puppet_steam_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_steam_configuration_yaml`. -matrix_mx_puppet_steam_configuration_extension: "{{ matrix_mx_puppet_steam_configuration_extension_yaml|from_yaml if matrix_mx_puppet_steam_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_steam_configuration_extension: "{{ matrix_mx_puppet_steam_configuration_extension_yaml | from_yaml if matrix_mx_puppet_steam_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_steam_configuration_yaml`. -matrix_mx_puppet_steam_configuration: "{{ matrix_mx_puppet_steam_configuration_yaml|from_yaml|combine(matrix_mx_puppet_steam_configuration_extension, recursive=True) }}" +matrix_mx_puppet_steam_configuration: "{{ matrix_mx_puppet_steam_configuration_yaml | from_yaml | combine(matrix_mx_puppet_steam_configuration_extension, recursive=True) }}" matrix_mx_puppet_steam_registration_yaml: | as_token: "{{ matrix_mx_puppet_steam_appservice_token }}" @@ -96,15 +97,15 @@ matrix_mx_puppet_steam_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain|regex_escape }}' + regex: '@_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain|regex_escape }}' + regex: '#_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _steampuppet_bot url: {{ matrix_mx_puppet_steam_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_steam_registration: "{{ matrix_mx_puppet_steam_registration_yaml|from_yaml }}" +matrix_mx_puppet_steam_registration: "{{ matrix_mx_puppet_steam_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml index efca4110..fb3257b2 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml @@ -2,23 +2,27 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the mx-puppet-steam image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_steam_container_image_self_build and matrix_mx_puppet_steam_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-steam.service'] }}" - when: matrix_mx_puppet_steam_enabled|bool + when: matrix_mx_puppet_steam_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([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_steam_config_path }}/registration.yaml,dst=/matrix-mx-puppet-steam-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mx_puppet_steam_config_path }}/registration.yaml,dst=/matrix-mx-puppet-steam-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-steam-registration.yaml"] }} - when: matrix_mx_puppet_steam_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mx-puppet-steam-registration.yaml"] + }} + when: matrix_mx_puppet_steam_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml index 733cfa90..236a7009 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_steam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_steam_enabled | bool" tags: - setup-all - setup-mx-puppet-steam -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_steam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_steam_enabled | bool" tags: - setup-all - setup-mx-puppet-steam -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_steam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_steam_enabled | bool" tags: - setup-all - setup-mx-puppet-steam diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml index ac2a2fda..80487630 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml @@ -3,13 +3,13 @@ # 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-mx-puppet-steam role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Steam paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_steam_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_steam_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_steam_docker_src_files_path }}", when: "{{ matrix_mx_puppet_steam_container_image_self_build }}"} - when: matrix_mx_puppet_steam_enabled|bool and item.when|bool + when: matrix_mx_puppet_steam_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_steam_base_path }}/database.db" register: matrix_mx_puppet_steam_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-steam.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-steam state: stopped enabled: false @@ -37,33 +37,35 @@ when: "matrix_mx_puppet_steam_stat_database.stat.exists" - name: (Data relocation) Move mx-puppet-steam database file to ./data directory - command: "mv {{ matrix_mx_puppet_steam_base_path }}/database.db {{ matrix_mx_puppet_steam_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_steam_base_path }}/database.db {{ matrix_mx_puppet_steam_data_path }}/database.db" when: "matrix_mx_puppet_steam_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_steam_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_steam_sqlite_database_path_local }}" register: matrix_mx_puppet_steam_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_steam_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_steam_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_steam_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-steam.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_steam_requires_restart: true - when: "matrix_mx_puppet_steam_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_steam_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_steam_database_engine == 'postgres'" - name: Ensure MX Puppet Steam image is pulled @@ -72,21 +74,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_steam_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_mx_puppet_steam_docker_image_force_pull }}" - when: matrix_mx_puppet_steam_enabled|bool and not matrix_mx_puppet_steam_container_image_self_build + when: matrix_mx_puppet_steam_enabled | bool and not matrix_mx_puppet_steam_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Steam repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_steam_container_image_self_build_repo }}" + version: "{{ matrix_mx_puppet_steam_container_image_self_build_repo_version }}" dest: "{{ matrix_mx_puppet_steam_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_steam_git_pull_results - when: "matrix_mx_puppet_steam_enabled|bool and matrix_mx_puppet_steam_container_image_self_build" + when: "matrix_mx_puppet_steam_enabled | bool and matrix_mx_puppet_steam_container_image_self_build" - name: Ensure MX Puppet Steam Docker image is built docker_image: @@ -98,38 +101,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_steam_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_steam_enabled|bool and matrix_mx_puppet_steam_container_image_self_build" + when: "matrix_mx_puppet_steam_enabled | bool and matrix_mx_puppet_steam_container_image_self_build" - name: Ensure mx-puppet-steam config.yaml installed - copy: - content: "{{ matrix_mx_puppet_steam_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_steam_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_steam_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-steam steam-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_steam_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_steam_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_steam_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-steam.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-steam.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-steam.service" mode: 0644 register: matrix_mx_puppet_steam_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-steam.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_steam_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-steam.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-steam.service" state: restarted - when: "matrix_mx_puppet_steam_requires_restart|bool" + when: "matrix_mx_puppet_steam_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml index 2e152ef6..d88e5472 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-steam service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-steam.service" register: matrix_mx_puppet_steam_service_stat - name: Ensure matrix-mx-puppet-steam is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-steam state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_steam_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-steam.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-steam.service" state: absent when: "matrix_mx_puppet_steam_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-steam.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_steam_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml index a8bc6a42..2e54d6ff 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 index fd59471d..0919907d 100644 --- a/roles/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 @@ -78,7 +78,7 @@ logging: # Log level of console output # Allowed values starting with most verbose: # silly, debug, verbose, info, warn, error - console: info + console: warn # Date and time formatting lineDateFormat: MMM-D HH:mm:ss.SSS # Logging files diff --git a/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml b/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml index 37be2be2..73674220 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml @@ -1,7 +1,7 @@ --- # Mx Puppet Twitter is a Matrix <-> Twitter bridge -# See: https://github.com/Sorunome/mx-puppet-twitter +# Project source code URL: https://github.com/Sorunome/mx-puppet-twitter matrix_mx_puppet_twitter_enabled: true @@ -41,7 +41,7 @@ matrix_mx_puppet_twitter_webhook_url: 'https://{{ matrix_server_fqn_matrix }}{{ # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_twitter_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -93,11 +93,11 @@ matrix_mx_puppet_twitter_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_twitter_configuration_yaml`. -matrix_mx_puppet_twitter_configuration_extension: "{{ matrix_mx_puppet_twitter_configuration_extension_yaml|from_yaml if matrix_mx_puppet_twitter_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_twitter_configuration_extension: "{{ matrix_mx_puppet_twitter_configuration_extension_yaml | from_yaml if matrix_mx_puppet_twitter_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_twitter_configuration_yaml`. -matrix_mx_puppet_twitter_configuration: "{{ matrix_mx_puppet_twitter_configuration_yaml|from_yaml|combine(matrix_mx_puppet_twitter_configuration_extension, recursive=True) }}" +matrix_mx_puppet_twitter_configuration: "{{ matrix_mx_puppet_twitter_configuration_yaml | from_yaml | combine(matrix_mx_puppet_twitter_configuration_extension, recursive=True) }}" # The prefix for user IDs and aliases matrix_mx_puppet_twitter_namespace_prefix: _twitterpuppet_ @@ -110,15 +110,15 @@ matrix_mx_puppet_twitter_registration_yaml: | namespaces: users: - exclusive: true - regex: '@{{ matrix_mx_puppet_twitter_namespace_prefix|regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain|regex_escape }}' + regex: '@{{ matrix_mx_puppet_twitter_namespace_prefix | regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#{{ matrix_mx_puppet_twitter_namespace_prefix|regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain|regex_escape }}' + regex: '#{{ matrix_mx_puppet_twitter_namespace_prefix | regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: "{{ matrix_mx_puppet_twitter_bot_localpart }}" url: {{ matrix_mx_puppet_twitter_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_twitter_registration: "{{ matrix_mx_puppet_twitter_registration_yaml|from_yaml }}" +matrix_mx_puppet_twitter_registration: "{{ matrix_mx_puppet_twitter_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml index 757f1f41..d6e65964 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml @@ -2,42 +2,46 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the mx-puppet-twitter image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mx_puppet_twitter_container_image_self_build and matrix_mx_puppet_twitter_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-twitter.service'] }}" - when: matrix_mx_puppet_twitter_enabled|bool + when: matrix_mx_puppet_twitter_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([]) }} - + - ["--mount type=bind,src={{ matrix_mx_puppet_twitter_config_path }}/registration.yaml,dst=/matrix-mx-puppet-twitter-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_mx_puppet_twitter_config_path }}/registration.yaml,dst=/matrix-mx-puppet-twitter-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-mx-puppet-twitter-registration.yaml"] }} - when: matrix_mx_puppet_twitter_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-mx-puppet-twitter-registration.yaml"] + }} + when: matrix_mx_puppet_twitter_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Twitter Appservice's 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-mx-puppet-twitter role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix MX Puppet Twitter proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mx_puppet_twitter_matrix_nginx_proxy_configuration: | location {{ matrix_mx_puppet_twitter_webhook_path }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_mx_puppet_twitter_appservice_address }}"; @@ -49,23 +53,23 @@ } - name: Register Twitter Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mx_puppet_twitter_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mx_puppet_twitter_enabled|bool + when: matrix_mx_puppet_twitter_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix Twitter bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mx_puppet_twitter_redirect_path }}` URL endpoint to the matrix-mx-puppet-twitter container. You can expose the container's port using the `matrix_mx_puppet_twitter_container_http_host_bind_port` variable. - when: "matrix_mx_puppet_twitter_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mx_puppet_twitter_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml index 7d65257c..20e4f686 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_twitter_enabled | bool" tags: - setup-all - setup-mx-puppet-twitter -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_twitter_enabled | bool" tags: - setup-all - setup-mx-puppet-twitter -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_twitter_enabled | bool" tags: - setup-all - setup-mx-puppet-twitter diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml index 6336b0a0..305cd5de 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml @@ -3,13 +3,13 @@ # 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-mx-puppet-twitter role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Twitter paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_twitter_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_twitter_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_twitter_docker_src_files_path }}", when: "{{ matrix_mx_puppet_twitter_container_image_self_build }}"} - when: matrix_mx_puppet_twitter_enabled|bool and item.when|bool + when: matrix_mx_puppet_twitter_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_twitter_base_path }}/database.db" register: matrix_mx_puppet_twitter_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-twitter.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-twitter state: stopped enabled: false @@ -37,33 +37,35 @@ when: "matrix_mx_puppet_twitter_stat_database.stat.exists" - name: (Data relocation) Move mx-puppet-twitter database file to ./data directory - command: "mv {{ matrix_mx_puppet_twitter_base_path }}/database.db {{ matrix_mx_puppet_twitter_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_twitter_base_path }}/database.db {{ matrix_mx_puppet_twitter_data_path }}/database.db" when: "matrix_mx_puppet_twitter_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_twitter_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_twitter_sqlite_database_path_local }}" register: matrix_mx_puppet_twitter_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_twitter_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_twitter_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_twitter_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-twitter.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_twitter_requires_restart: true - when: "matrix_mx_puppet_twitter_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_twitter_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_twitter_database_engine == 'postgres'" - name: Ensure MX Puppet Twitter image is pulled @@ -72,21 +74,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_twitter_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_mx_puppet_twitter_docker_image_force_pull }}" - when: matrix_mx_puppet_twitter_enabled|bool and not matrix_mx_puppet_twitter_container_image_self_build + when: matrix_mx_puppet_twitter_enabled | bool and not matrix_mx_puppet_twitter_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Twitter repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_twitter_container_image_self_build_repo }}" + version: master dest: "{{ matrix_mx_puppet_twitter_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_twitter_git_pull_results - when: "matrix_mx_puppet_twitter_enabled|bool and matrix_mx_puppet_twitter_container_image_self_build" + when: "matrix_mx_puppet_twitter_enabled | bool and matrix_mx_puppet_twitter_container_image_self_build" - name: Ensure MX Puppet Twitter Docker image is built docker_image: @@ -98,38 +101,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_twitter_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_twitter_enabled|bool and matrix_mx_puppet_twitter_container_image_self_build" + when: "matrix_mx_puppet_twitter_enabled | bool and matrix_mx_puppet_twitter_container_image_self_build" - name: Ensure mx-puppet-twitter config.yaml installed - copy: - content: "{{ matrix_mx_puppet_twitter_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_twitter_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_twitter_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-twitter twitter-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_twitter_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_twitter_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_twitter_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-twitter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-twitter.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-twitter.service" mode: 0644 register: matrix_mx_puppet_twitter_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-twitter.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_twitter_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-twitter.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-twitter.service" state: restarted - when: "matrix_mx_puppet_twitter_requires_restart|bool" + when: "matrix_mx_puppet_twitter_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml index 56dcd9ce..6db13de0 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-twitter service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-twitter.service" register: matrix_mx_puppet_twitter_service_stat - name: Ensure matrix-mx-puppet-twitter is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-twitter state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_twitter_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-twitter.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-twitter.service" state: absent when: "matrix_mx_puppet_twitter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-twitter.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_twitter_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml index d13a39e1..b5b7ef5b 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-twitter/templates/config.yaml.j2 b/roles/matrix-bridge-mx-puppet-twitter/templates/config.yaml.j2 index 1d269057..5418ccaf 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/templates/config.yaml.j2 +++ b/roles/matrix-bridge-mx-puppet-twitter/templates/config.yaml.j2 @@ -28,7 +28,7 @@ presence: # Bridge Twitter online/offline status enabled: true # How often to send status to the homeserver in milliseconds - interval: 500 + interval: 5000 provisioning: # Regex of Matrix IDs allowed to use the puppet bridge @@ -71,7 +71,7 @@ logging: # Log level of console output # Allowed values starting with most verbose: # silly, debug, verbose, info, warn, error - console: info + console: warn # Date and time formatting lineDateFormat: MMM-D HH:mm:ss.SSS # Logging files diff --git a/roles/matrix-bridge-sms/defaults/main.yml b/roles/matrix-bridge-sms/defaults/main.yml index 82ffce6e..b4755d71 100644 --- a/roles/matrix-bridge-sms/defaults/main.yml +++ b/roles/matrix-bridge-sms/defaults/main.yml @@ -1,6 +1,6 @@ --- # matrix-sms-bridge is a Matrix <-> SMS bridge -# See: https://github.com/benkuly/matrix-sms-bridge +# Project source code URL: https://github.com/benkuly/matrix-sms-bridge matrix_sms_bridge_enabled: true @@ -104,9 +104,9 @@ matrix_sms_bridge_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_sms_bridge_configuration_yaml`. -matrix_sms_bridge_configuration_extension: "{{ matrix_sms_bridge_configuration_extension_yaml|from_yaml if matrix_sms_bridge_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_sms_bridge_configuration_extension: "{{ matrix_sms_bridge_configuration_extension_yaml | from_yaml if matrix_sms_bridge_configuration_extension_yaml | from_yaml is mapping else {} }}" -matrix_sms_bridge_configuration: "{{ matrix_sms_bridge_configuration_yaml|from_yaml|combine(matrix_sms_bridge_configuration_extension, recursive=True) }}" +matrix_sms_bridge_configuration: "{{ matrix_sms_bridge_configuration_yaml | from_yaml | combine(matrix_sms_bridge_configuration_extension, recursive=True) }}" matrix_sms_bridge_registration_yaml: | id: sms @@ -115,12 +115,12 @@ matrix_sms_bridge_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@sms_.+:{{ matrix_sms_bridge_homserver_domain|regex_escape }}$' + regex: '^@sms_.+:{{ matrix_sms_bridge_homserver_domain | regex_escape }}$' aliases: - exclusive: true - regex: '^#sms_.+:{{ matrix_sms_bridge_homserver_domain|regex_escape }}$' + regex: '^#sms_.+:{{ matrix_sms_bridge_homserver_domain | regex_escape }}$' url: {{ matrix_sms_bridge_appservice_url }} sender_localpart: smsbot rate_limited: false -matrix_sms_bridge_registration: "{{ matrix_sms_bridge_registration_yaml|from_yaml }}" +matrix_sms_bridge_registration: "{{ matrix_sms_bridge_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-sms/tasks/init.yml b/roles/matrix-bridge-sms/tasks/init.yml index b8af8e60..85684b81 100644 --- a/roles/matrix-bridge-sms/tasks/init.yml +++ b/roles/matrix-bridge-sms/tasks/init.yml @@ -3,24 +3,28 @@ # 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-sms-bridge role needs to execute before the matrix-synapse role. - when: "matrix_sms_bridge_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_sms_bridge_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-sms-bridge.service'] }}" - when: matrix_sms_bridge_enabled|bool + when: matrix_sms_bridge_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([]) }} - + - ["--mount type=bind,src={{ matrix_sms_bridge_config_path }}/registration.yaml,dst=/matrix-sms-bridge-registration.yaml,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_sms_bridge_config_path }}/registration.yaml,dst=/matrix-sms-bridge-registration.yaml,ro"] + }} matrix_synapse_app_service_config_files: > - {{ matrix_synapse_app_service_config_files|default([]) }} - + - {{ ["/matrix-sms-bridge-registration.yaml"] }} - when: matrix_sms_bridge_enabled|bool + {{ + matrix_synapse_app_service_config_files | default([]) + + + ["/matrix-sms-bridge-registration.yaml"] + }} + when: matrix_sms_bridge_enabled | bool diff --git a/roles/matrix-bridge-sms/tasks/main.yml b/roles/matrix-bridge-sms/tasks/main.yml index b06e1a54..1a6b964b 100644 --- a/roles/matrix-bridge-sms/tasks/main.yml +++ b/roles/matrix-bridge-sms/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_sms_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_sms_bridge_enabled | bool" tags: - setup-all - setup-matrix-sms-bridge -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_sms_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_sms_bridge_enabled | bool" tags: - setup-all - setup-matrix-sms-bridge -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_sms_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_sms_bridge_enabled | bool" tags: - setup-all - setup-matrix-sms-bridge diff --git a/roles/matrix-bridge-sms/tasks/setup_install.yml b/roles/matrix-bridge-sms/tasks/setup_install.yml index 412c26fe..dcc317ba 100644 --- a/roles/matrix-bridge-sms/tasks/setup_install.yml +++ b/roles/matrix-bridge-sms/tasks/setup_install.yml @@ -10,7 +10,7 @@ until: result is not failed - name: Ensure matrix-sms-bridge paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -22,23 +22,23 @@ - "{{ matrix_sms_bridge_data_path }}" - name: Ensure matrix-sms-bridge application.yml installed - copy: - content: "{{ matrix_sms_bridge_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_sms_bridge_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_sms_bridge_config_path }}/application.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-sms-bridge registration.yaml installed - copy: - content: "{{ matrix_sms_bridge_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_sms_bridge_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_sms_bridge_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure android-sms-gateway-server cert installed - copy: + ansible.builtin.copy: src: "{{ matrix_sms_bridge_provider_android_truststore_local_path }}" dest: "{{ matrix_sms_bridge_config_path }}/matrix-sms-gateway-server.p12" mode: 0644 @@ -47,13 +47,13 @@ when: matrix_sms_bridge_provider_android_truststore_local_path != "" - name: Ensure matrix-sms-bridge.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-sms-bridge.service.j2" dest: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" mode: 0644 register: matrix_sms_bridge_systemd_service_result - name: Ensure systemd reloaded after matrix-sms-bridge.service installation - service: + ansible.builtin.service: daemon_reload: true when: matrix_sms_bridge_systemd_service_result.changed diff --git a/roles/matrix-bridge-sms/tasks/setup_uninstall.yml b/roles/matrix-bridge-sms/tasks/setup_uninstall.yml index d74476eb..322190f9 100644 --- a/roles/matrix-bridge-sms/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-sms/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-sms-bridge service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" register: matrix_sms_bridge_service_stat - name: Ensure matrix-sms-bridge is stopped - service: + ansible.builtin.service: name: matrix-sms-bridge state: stopped enabled: false @@ -14,7 +14,7 @@ when: "matrix_sms_bridge_service_stat.stat.exists" - name: Ensure matrix-sms-bridge.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" state: absent when: "matrix_sms_bridge_service_stat.stat.exists" diff --git a/roles/matrix-bridge-sms/tasks/validate_config.yml b/roles/matrix-bridge-sms/tasks/validate_config.yml index 96e41755..fa7dcfbd 100644 --- a/roles/matrix-bridge-sms/tasks/validate_config.yml +++ b/roles/matrix-bridge-sms/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-client-cinny/defaults/main.yml b/roles/matrix-client-cinny/defaults/main.yml index 2ded4048..743dc077 100644 --- a/roles/matrix-client-cinny/defaults/main.yml +++ b/roles/matrix-client-cinny/defaults/main.yml @@ -1,11 +1,12 @@ --- +# Project source code URL: https://github.com/ajbura/cinny matrix_client_cinny_enabled: true matrix_client_cinny_container_image_self_build: false matrix_client_cinny_container_image_self_build_repo: "https://github.com/ajbura/cinny.git" -matrix_client_cinny_version: v1.8.2 +matrix_client_cinny_version: v2.1.1 matrix_client_cinny_docker_image: "{{ matrix_client_cinny_docker_image_name_prefix }}ajbura/cinny:{{ matrix_client_cinny_version }}" matrix_client_cinny_docker_image_name_prefix: "{{ 'localhost/' if matrix_client_cinny_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_client_cinny_docker_image_force_pull: "{{ matrix_client_cinny_docker_image.endswith(':latest') }}" @@ -49,8 +50,8 @@ matrix_client_cinny_configuration_default: "{{ lookup('template', 'templates/con # completely redefining `matrix_client_cinny_configuration_default`. matrix_client_cinny_configuration_extension_json: '{}' -matrix_client_cinny_configuration_extension: "{{ matrix_client_cinny_configuration_extension_json|from_json if matrix_client_cinny_configuration_extension_json|from_json is mapping else {} }}" +matrix_client_cinny_configuration_extension: "{{ matrix_client_cinny_configuration_extension_json | from_json if matrix_client_cinny_configuration_extension_json | from_json is mapping else {} }}" # Holds the final cinny configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_client_cinny_configuration_default`. -matrix_client_cinny_configuration: "{{ matrix_client_cinny_configuration_default|combine(matrix_client_cinny_configuration_extension, recursive=True) }}" +matrix_client_cinny_configuration: "{{ matrix_client_cinny_configuration_default | combine(matrix_client_cinny_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-client-cinny/tasks/init.yml b/roles/matrix-client-cinny/tasks/init.yml index 04fbd8a2..00e46dc8 100644 --- a/roles/matrix-client-cinny/tasks/init.yml +++ b/roles/matrix-client-cinny/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: + ansible.builtin.fail: msg: "To self-build the Cinny image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_client_cinny_container_image_self_build and matrix_client_cinny_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-cinny.service'] }}" - when: matrix_client_cinny_enabled|bool + when: matrix_client_cinny_enabled | bool diff --git a/roles/matrix-client-cinny/tasks/main.yml b/roles/matrix-client-cinny/tasks/main.yml index 5c37d38e..9eb00781 100644 --- a/roles/matrix-client-cinny/tasks/main.yml +++ b/roles/matrix-client-cinny/tasks/main.yml @@ -1,30 +1,30 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_client_cinny_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_client_cinny_enabled | bool" tags: - setup-all - setup-client-cinny -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_client_cinny_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_client_cinny_enabled | bool" tags: - setup-all - setup-client-cinny -- import_tasks: "{{ role_path }}/tasks/self_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_client_cinny_enabled|bool" + when: "run_self_check | bool and matrix_client_cinny_enabled | bool" tags: - self-check -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_client_cinny_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_client_cinny_enabled | bool" tags: - setup-all - setup-client-cinny diff --git a/roles/matrix-client-cinny/tasks/self_check.yml b/roles/matrix-client-cinny/tasks/self_check.yml index d00408da..e0f9bfc1 100644 --- a/roles/matrix-client-cinny/tasks/self_check.yml +++ b/roles/matrix-client-cinny/tasks/self_check.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_client_cinny_url_endpoint_public: "https://{{ matrix_server_fqn_cinny }}/config.json" - name: Check Cinny - uri: + ansible.builtin.uri: url: "{{ matrix_client_cinny_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_client_cinny_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Cinny not working - fail: + ansible.builtin.fail: msg: "Failed checking Cinny is up at `{{ matrix_server_fqn_cinny }}` (checked endpoint: `{{ matrix_client_cinny_url_endpoint_public }}`). Is Cinny running? Is port 443 open in your firewall? Full error: {{ matrix_client_cinny_self_check_result }}" when: "matrix_client_cinny_self_check_result.failed or 'json' not in matrix_client_cinny_self_check_result" - name: Report working Cinny - debug: + ansible.builtin.debug: msg: "Cinny at `{{ matrix_server_fqn_cinny }}` is working (checked endpoint: `{{ matrix_client_cinny_url_endpoint_public }}`)" diff --git a/roles/matrix-client-cinny/tasks/setup_install.yml b/roles/matrix-client-cinny/tasks/setup_install.yml index da979f56..755b872f 100644 --- a/roles/matrix-client-cinny/tasks/setup_install.yml +++ b/roles/matrix-client-cinny/tasks/setup_install.yml @@ -1,6 +1,6 @@ --- - name: Ensure Cinny paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -9,7 +9,7 @@ with_items: - {path: "{{ matrix_client_cinny_data_path }}", when: true} - {path: "{{ matrix_client_cinny_docker_src_files_path }}", when: "{{ matrix_client_cinny_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Cinny Docker image is pulled docker_image: @@ -17,14 +17,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_client_cinny_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_client_cinny_docker_image_force_pull }}" - when: "not matrix_client_cinny_container_image_self_build|bool" + when: "not matrix_client_cinny_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Cinny repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_client_cinny_container_image_self_build_repo }}" dest: "{{ matrix_client_cinny_docker_src_files_path }}" version: "{{ matrix_client_cinny_docker_image.split(':')[1] }}" @@ -32,18 +32,18 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_client_cinny_git_pull_results - when: "matrix_client_cinny_container_image_self_build|bool" + when: "matrix_client_cinny_container_image_self_build | bool" - name: Ensure Cinny configuration installed - copy: - content: "{{ matrix_client_cinny_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_client_cinny_configuration | to_nice_json }}" dest: "{{ matrix_client_cinny_data_path }}/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Cinny additional config files installed - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ matrix_client_cinny_data_path }}/{{ item.name }}" mode: 0644 @@ -62,16 +62,16 @@ dockerfile: Dockerfile path: "{{ matrix_client_cinny_docker_src_files_path }}" pull: true - when: "matrix_client_cinny_container_image_self_build|bool" + when: "matrix_client_cinny_container_image_self_build | bool" - name: Ensure matrix-client-cinny.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-client-cinny.service.j2" dest: "{{ matrix_systemd_path }}/matrix-client-cinny.service" mode: 0644 register: matrix_client_cinny_systemd_service_result - name: Ensure systemd reloaded after matrix-client-cinny.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_cinny_systemd_service_result.changed|bool" + when: "matrix_client_cinny_systemd_service_result.changed | bool" diff --git a/roles/matrix-client-cinny/tasks/setup_uninstall.yml b/roles/matrix-client-cinny/tasks/setup_uninstall.yml index 507c5d70..e6f71b0b 100644 --- a/roles/matrix-client-cinny/tasks/setup_uninstall.yml +++ b/roles/matrix-client-cinny/tasks/setup_uninstall.yml @@ -1,31 +1,31 @@ --- - name: Check existence of matrix-client-cinny.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-client-cinny.service" register: matrix_client_cinny_service_stat - name: Ensure matrix-client-cinny is stopped - service: + ansible.builtin.service: name: matrix-client-cinny state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_cinny_service_stat.stat.exists|bool" + when: "matrix_client_cinny_service_stat.stat.exists | bool" - name: Ensure matrix-client-cinny.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-client-cinny.service" state: absent - when: "matrix_client_cinny_service_stat.stat.exists|bool" + when: "matrix_client_cinny_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-client-cinny.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_cinny_service_stat.stat.exists|bool" + when: "matrix_client_cinny_service_stat.stat.exists | bool" - name: Ensure Cinny paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_client_cinny_data_path }}" state: absent diff --git a/roles/matrix-client-cinny/tasks/validate_config.yml b/roles/matrix-client-cinny/tasks/validate_config.yml index d8e804c5..10f64fee 100644 --- a/roles/matrix-client-cinny/tasks/validate_config.yml +++ b/roles/matrix-client-cinny/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required Cinny settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) to use Cinny. when: "vars[item] == '' or vars[item] is none" diff --git a/roles/matrix-client-cinny/templates/config.json.j2 b/roles/matrix-client-cinny/templates/config.json.j2 index 9731a372..0da710ac 100644 --- a/roles/matrix-client-cinny/templates/config.json.j2 +++ b/roles/matrix-client-cinny/templates/config.json.j2 @@ -1,6 +1,6 @@ { "defaultHomeserver": 0, "homeserverList": [ - {{ matrix_client_cinny_default_hs_url|string|to_json }} + {{ matrix_client_cinny_default_hs_url | string|to_json }} ] } diff --git a/roles/matrix-client-element/defaults/main.yml b/roles/matrix-client-element/defaults/main.yml index 205f3480..5cefc3e3 100644 --- a/roles/matrix-client-element/defaults/main.yml +++ b/roles/matrix-client-element/defaults/main.yml @@ -1,15 +1,16 @@ --- +# Project source code URL: https://github.com/vector-im/element-web matrix_client_element_enabled: true matrix_client_element_container_image_self_build: false -matrix_client_element_container_image_self_build_repo: "https://github.com/vector-im/riot-web.git" +matrix_client_element_container_image_self_build_repo: "https://github.com/vector-im/element-web.git" # Controls whether to patch webpack.config.js when self-building, so that building can pass on low-memory systems (< 4 GB RAM): # - https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1357 # - https://github.com/vector-im/element-web/issues/19544 matrix_client_element_container_image_self_build_low_memory_system_patch_enabled: "{{ ansible_memtotal_mb < 4096 }}" -matrix_client_element_version: v1.10.10 +matrix_client_element_version: v1.11.2 matrix_client_element_docker_image: "{{ matrix_client_element_docker_image_name_prefix }}vectorim/element-web:{{ matrix_client_element_version }}" matrix_client_element_docker_image_name_prefix: "{{ 'localhost/' if matrix_client_element_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_client_element_docker_image_force_pull: "{{ matrix_client_element_docker_image.endswith(':latest') }}" @@ -38,9 +39,9 @@ matrix_client_element_integrations_ui_url: "https://scalar.vector.im/" matrix_client_element_integrations_rest_url: "https://scalar.vector.im/api" matrix_client_element_integrations_widgets_urls: ["https://scalar.vector.im/api"] matrix_client_element_integrations_jitsi_widget_url: "https://scalar.vector.im/api/widgets/jitsi.html" -matrix_client_element_permalinkPrefix: "https://matrix.to" +matrix_client_element_permalinkPrefix: "https://matrix.to" # noqa var-naming matrix_client_element_bug_report_endpoint_url: "https://element.io/bugreports/submit" -matrix_client_element_showLabsSettings: true +matrix_client_element_showLabsSettings: true # noqa var-naming # Element public room directory server(s) matrix_client_element_roomdir_servers: ['matrix.org'] matrix_client_element_welcome_user_id: ~ @@ -58,13 +59,13 @@ matrix_client_element_welcome_text: "_t('Decentralised, encrypted chat & col # Links, shown in footer of welcome page: # [{"text": "Link text", "url": "https://link.target"}, {"text": "Other link"}] -matrix_client_element_branding_authFooterLinks: ~ +matrix_client_element_branding_authFooterLinks: ~ # noqa var-naming # URL to image, shown during Login -matrix_client_element_branding_authHeaderLogoUrl: "{{ matrix_client_element_welcome_logo }}" +matrix_client_element_branding_authHeaderLogoUrl: "{{ matrix_client_element_welcome_logo }}" # noqa var-naming # URL to Wallpaper, shown in background of welcome page -matrix_client_element_branding_welcomeBackgroundUrl: ~ +matrix_client_element_branding_welcomeBackgroundUrl: ~ # noqa var-naming matrix_client_element_page_template_welcome_path: "{{ role_path }}/templates/welcome.html.j2" @@ -72,7 +73,7 @@ matrix_client_element_page_template_welcome_path: "{{ role_path }}/templates/wel # point this to a `home.html` template file on your local filesystem. matrix_client_element_embedded_pages_home_path: ~ -matrix_client_element_jitsi_preferredDomain: '' +matrix_client_element_jitsi_preferredDomain: '' # noqa var-naming # Controls whether the self-check feature should validate SSL certificates. matrix_client_element_self_check_validate_certificates: true @@ -88,6 +89,7 @@ matrix_client_element_enable_presence_by_hs_url: ~ # will be installed and enabled automatically. matrix_client_element_themes_enabled: false matrix_client_element_themes_repository_url: https://github.com/aaronraimist/element-themes +matrix_client_element_themes_repository_version: master # Controls the default theme matrix_client_element_default_theme: 'light' @@ -99,7 +101,7 @@ matrix_client_element_default_theme: 'light' # If you define your own themes here and set `matrix_client_element_themes_enabled: true`, your themes will be preserved as well. # # Note that for a custom theme to work well, all Element instances that you use must have the same theme installed. -matrix_client_element_settingDefaults_custom_themes: [] +matrix_client_element_settingDefaults_custom_themes: [] # noqa var-naming # Default Element configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -128,8 +130,8 @@ matrix_client_element_configuration_default: "{{ lookup('template', 'templates/c # } matrix_client_element_configuration_extension_json: '{}' -matrix_client_element_configuration_extension: "{{ matrix_client_element_configuration_extension_json|from_json if matrix_client_element_configuration_extension_json|from_json is mapping else {} }}" +matrix_client_element_configuration_extension: "{{ matrix_client_element_configuration_extension_json | from_json if matrix_client_element_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Element configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_client_element_configuration_default`. -matrix_client_element_configuration: "{{ matrix_client_element_configuration_default|combine(matrix_client_element_configuration_extension, recursive=True) }}" +matrix_client_element_configuration: "{{ matrix_client_element_configuration_default | combine(matrix_client_element_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-client-element/tasks/init.yml b/roles/matrix-client-element/tasks/init.yml index cb1df0b5..7bdad9e1 100644 --- a/roles/matrix-client-element/tasks/init.yml +++ b/roles/matrix-client-element/tasks/init.yml @@ -1,12 +1,12 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-element.service'] }}" - when: matrix_client_element_enabled|bool + when: matrix_client_element_enabled | bool # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: + ansible.builtin.fail: msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_client_element_container_image_self_build and matrix_client_element_enabled" diff --git a/roles/matrix-client-element/tasks/main.yml b/roles/matrix-client-element/tasks/main.yml index 28e23e8a..53a25afb 100644 --- a/roles/matrix-client-element/tasks/main.yml +++ b/roles/matrix-client-element/tasks/main.yml @@ -1,42 +1,42 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_client_element_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_client_element_enabled | bool" tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/prepare_themes.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/prepare_themes.yml" + when: run_setup | bool tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/migrate_riot_web.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_riot_web.yml" + when: run_setup | bool tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_client_element_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_client_element_enabled | bool" tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_client_element_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_client_element_enabled | bool" tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/self_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_client_element_enabled|bool" + when: "run_self_check | bool and matrix_client_element_enabled | bool" tags: - self-check diff --git a/roles/matrix-client-element/tasks/migrate_riot_web.yml b/roles/matrix-client-element/tasks/migrate_riot_web.yml index ee0fd446..23011e93 100644 --- a/roles/matrix-client-element/tasks/migrate_riot_web.yml +++ b/roles/matrix-client-element/tasks/migrate_riot_web.yml @@ -1,37 +1,37 @@ --- - name: Check existence of matrix-riot-web.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-riot-web.service" register: matrix_client_riot_web_service_stat - when: "matrix_client_element_enabled|bool" + when: "matrix_client_element_enabled | bool" - name: Ensure matrix-riot-web is stopped - service: + ansible.builtin.service: name: matrix-riot-web state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_service_stat.stat.exists" - name: Ensure matrix-riot-web.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-riot-web.service" state: absent - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-riot-web.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_service_stat.stat.exists" - name: Check existence of /matrix/riot-web - stat: + ansible.builtin.stat: path: "/matrix/riot-web" register: matrix_client_riot_web_dir_stat - when: "matrix_client_element_enabled|bool" + when: "matrix_client_element_enabled | bool" - name: Relocate /matrix/riot-web to /matrix/client-element - command: "mv /matrix/riot-web /matrix/client-element" - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_dir_stat.stat.exists" + ansible.builtin.command: "mv /matrix/riot-web /matrix/client-element" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_dir_stat.stat.exists" diff --git a/roles/matrix-client-element/tasks/prepare_themes.yml b/roles/matrix-client-element/tasks/prepare_themes.yml index bfb9837b..8185122c 100644 --- a/roles/matrix-client-element/tasks/prepare_themes.yml +++ b/roles/matrix-client-element/tasks/prepare_themes.yml @@ -6,32 +6,33 @@ - block: - name: Ensure Element themes repository is pulled - git: + ansible.builtin.git: repo: "{{ matrix_client_element_themes_repository_url }}" + version: "{{ matrix_client_element_themes_repository_version }}" dest: "{{ role_path }}/files/scratchpad/themes" - name: Find all Element theme files - find: + ansible.builtin.find: paths: "{{ role_path }}/files/scratchpad/themes" patterns: "*.json" recurse: true register: matrix_client_element_theme_file_list - name: Read Element theme - slurp: + ansible.builtin.slurp: path: "{{ item.path }}" register: "matrix_client_element_theme_file_contents" with_items: "{{ matrix_client_element_theme_file_list.files }}" - name: Load Element theme - set_fact: - matrix_client_element_settingDefaults_custom_themes: "{{ matrix_client_element_settingDefaults_custom_themes + [item['content'] | b64decode | from_json] }}" + ansible.builtin.set_fact: + matrix_client_element_settingDefaults_custom_themes: "{{ matrix_client_element_settingDefaults_custom_themes + [item['content'] | b64decode | from_json] }}" # noqa var-naming with_items: "{{ matrix_client_element_theme_file_contents.results }}" run_once: true delegate_to: 127.0.0.1 become: false - when: matrix_client_element_themes_enabled|bool + when: matrix_client_element_themes_enabled | bool # @@ -39,10 +40,10 @@ # - name: Ensure Element themes repository is removed - file: + ansible.builtin.file: path: "{{ role_path }}/files/scratchpad/themes" state: absent run_once: true delegate_to: 127.0.0.1 become: false - when: "not matrix_client_element_themes_enabled|bool" + when: "not matrix_client_element_themes_enabled | bool" diff --git a/roles/matrix-client-element/tasks/self_check.yml b/roles/matrix-client-element/tasks/self_check.yml index d05644c8..031bb5f9 100644 --- a/roles/matrix-client-element/tasks/self_check.yml +++ b/roles/matrix-client-element/tasks/self_check.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_client_element_url_endpoint_public: "https://{{ matrix_server_fqn_element }}/config.json" - name: Check Element - uri: + ansible.builtin.uri: url: "{{ matrix_client_element_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_client_element_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Element not working - fail: + ansible.builtin.fail: msg: "Failed checking Element is up at `{{ matrix_server_fqn_element }}` (checked endpoint: `{{ matrix_client_element_url_endpoint_public }}`). Is Element running? Is port 443 open in your firewall? Full error: {{ matrix_client_element_self_check_result }}" when: "matrix_client_element_self_check_result.failed or 'json' not in matrix_client_element_self_check_result" - name: Report working Element - debug: + ansible.builtin.debug: msg: "Element at `{{ matrix_server_fqn_element }}` is working (checked endpoint: `{{ matrix_client_element_url_endpoint_public }}`)" diff --git a/roles/matrix-client-element/tasks/setup_install.yml b/roles/matrix-client-element/tasks/setup_install.yml index 4d0af82d..5fa34fa6 100644 --- a/roles/matrix-client-element/tasks/setup_install.yml +++ b/roles/matrix-client-element/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Element paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -10,7 +10,7 @@ with_items: - {path: "{{ matrix_client_element_data_path }}", when: true} - {path: "{{ matrix_client_element_docker_src_files_path }}", when: "{{ matrix_client_element_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Element Docker image is pulled docker_image: @@ -18,14 +18,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_client_element_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_client_element_docker_image_force_pull }}" - when: "not matrix_client_element_container_image_self_build|bool" + when: "not matrix_client_element_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Element repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_client_element_container_image_self_build_repo }}" dest: "{{ matrix_client_element_docker_src_files_path }}" version: "{{ matrix_client_element_docker_image.split(':')[1] }}" @@ -33,21 +33,21 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_client_element_git_pull_results - when: "matrix_client_element_container_image_self_build|bool" + when: "matrix_client_element_container_image_self_build | bool" # See: # - https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1357 # - https://github.com/vector-im/element-web/issues/19544 - name: Patch webpack.config.js to support building on low-memory (<4G RAM) devices - lineinfile: + ansible.builtin.lineinfile: path: "{{ matrix_client_element_docker_src_files_path }}/webpack.config.js" regexp: '(\s+)splitChunks: \{' line: '\1splitChunks: { maxSize: 100000,' backrefs: true owner: root - group: root + ansible.builtin.group: root mode: '0644' - when: "matrix_client_element_container_image_self_build|bool and matrix_client_element_container_image_self_build_low_memory_system_patch_enabled|bool" + when: "matrix_client_element_container_image_self_build | bool and matrix_client_element_container_image_self_build_low_memory_system_patch_enabled | bool" - name: Ensure Element Docker image is built docker_image: @@ -59,18 +59,18 @@ dockerfile: Dockerfile path: "{{ matrix_client_element_docker_src_files_path }}" pull: true - when: "matrix_client_element_container_image_self_build|bool" + when: "matrix_client_element_container_image_self_build | bool" - name: Ensure Element configuration installed - copy: - content: "{{ matrix_client_element_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_client_element_configuration | to_nice_json }}" dest: "{{ matrix_client_element_data_path }}/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Element config files installed - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ matrix_client_element_data_path }}/{{ item.name }}" mode: 0644 @@ -83,7 +83,7 @@ when: "item.src is not none" - name: Ensure Element config files removed - file: + ansible.builtin.file: path: "{{ matrix_client_element_data_path }}/{{ item.name }}" state: absent with_items: @@ -91,13 +91,13 @@ when: "item.src is none" - name: Ensure matrix-client-element.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-client-element.service.j2" dest: "{{ matrix_systemd_path }}/matrix-client-element.service" mode: 0644 register: matrix_client_element_systemd_service_result - name: Ensure systemd reloaded after matrix-client-element.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_element_systemd_service_result.changed|bool" + when: "matrix_client_element_systemd_service_result.changed | bool" diff --git a/roles/matrix-client-element/tasks/setup_uninstall.yml b/roles/matrix-client-element/tasks/setup_uninstall.yml index 55bc20d6..b3cdd05e 100644 --- a/roles/matrix-client-element/tasks/setup_uninstall.yml +++ b/roles/matrix-client-element/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-client-element.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-client-element.service" register: matrix_client_element_service_stat - name: Ensure matrix-client-element is stopped - service: + ansible.builtin.service: name: matrix-client-element state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_element_service_stat.stat.exists|bool" + when: "matrix_client_element_service_stat.stat.exists | bool" - name: Ensure matrix-client-element.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-client-element.service" state: absent - when: "matrix_client_element_service_stat.stat.exists|bool" + when: "matrix_client_element_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-client-element.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_element_service_stat.stat.exists|bool" + when: "matrix_client_element_service_stat.stat.exists | bool" - name: Ensure Element paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_client_element_data_path }}" state: absent diff --git a/roles/matrix-client-element/tasks/validate_config.yml b/roles/matrix-client-element/tasks/validate_config.yml index d246b612..fdf74f07 100644 --- a/roles/matrix-client-element/tasks/validate_config.yml +++ b/roles/matrix-client-element/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Element settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) for using Element. when: "vars[item] == ''" @@ -9,7 +9,7 @@ - "matrix_client_element_default_hs_url" - name: (Deprecation) Catch and report riot-web variables - fail: + ansible.builtin.fail: msg: >- Riot has been renamed to Element (https://element.io/blog/welcome-to-element/). The playbook will migrate your existing configuration and data automatically, but you need to adjust variable names. diff --git a/roles/matrix-client-element/templates/config.json.j2 b/roles/matrix-client-element/templates/config.json.j2 index e87907e4..e3477398 100644 --- a/roles/matrix-client-element/templates/config.json.j2 +++ b/roles/matrix-client-element/templates/config.json.j2 @@ -1,25 +1,25 @@ { "default_server_config": { "m.homeserver": { - "base_url": {{ matrix_client_element_default_hs_url|string|to_json }}, - "server_name": {{ matrix_client_element_default_server_name|string|to_json }} + "base_url": {{ matrix_client_element_default_hs_url | string|to_json }}, + "server_name": {{ matrix_client_element_default_server_name | string|to_json }} }, "m.identity_server": { - "base_url": {{ matrix_client_element_default_is_url|string|to_json }} + "base_url": {{ matrix_client_element_default_is_url | string|to_json }} } }, "settingDefaults": { "custom_themes": {{ matrix_client_element_settingDefaults_custom_themes|to_json }} }, - "default_theme": {{ matrix_client_element_default_theme|string|to_json }}, - "permalinkPrefix": {{ matrix_client_element_permalinkPrefix|string|to_json }}, + "default_theme": {{ matrix_client_element_default_theme | string|to_json }}, + "permalinkPrefix": {{ matrix_client_element_permalinkPrefix | string|to_json }}, "disable_custom_urls": {{ matrix_client_element_disable_custom_urls|to_json }}, "disable_guests": {{ matrix_client_element_disable_guests|to_json }}, "brand": {{ matrix_client_element_brand|to_json }}, - "integrations_ui_url": {{ matrix_client_element_integrations_ui_url|string|to_json }}, - "integrations_rest_url": {{ matrix_client_element_integrations_rest_url|string|to_json }}, + "integrations_ui_url": {{ matrix_client_element_integrations_ui_url | string|to_json }}, + "integrations_rest_url": {{ matrix_client_element_integrations_rest_url | string|to_json }}, "integrations_widgets_urls": {{ matrix_client_element_integrations_widgets_urls|to_json }}, - "integrations_jitsi_widget_url": {{ matrix_client_element_integrations_jitsi_widget_url|string|to_json }}, + "integrations_jitsi_widget_url": {{ matrix_client_element_integrations_jitsi_widget_url | string|to_json }}, "bug_report_endpoint_url": {{ matrix_client_element_bug_report_endpoint_url|to_json }}, "showLabsSettings": {{ matrix_client_element_showLabsSettings|to_json }}, "roomDirectory": { @@ -30,7 +30,7 @@ "enable_presence_by_hs_url": {{ matrix_client_element_enable_presence_by_hs_url|to_json }}, {% endif %} "embeddedPages": { - "homeUrl": {{ matrix_client_element_embedded_pages_home_url|string|to_json }} + "homeUrl": {{ matrix_client_element_embedded_pages_home_url | string|to_json }} }, {% if matrix_client_element_jitsi_preferredDomain %} "jitsi": { diff --git a/roles/matrix-client-hydrogen/defaults/main.yml b/roles/matrix-client-hydrogen/defaults/main.yml index 4b91eb2b..4edfa20c 100644 --- a/roles/matrix-client-hydrogen/defaults/main.yml +++ b/roles/matrix-client-hydrogen/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/vector-im/hydrogen-web matrix_client_hydrogen_enabled: true @@ -7,7 +8,7 @@ matrix_client_hydrogen_enabled: true matrix_client_hydrogen_container_image_self_build: true matrix_client_hydrogen_container_image_self_build_repo: "https://github.com/vector-im/hydrogen-web.git" -matrix_client_hydrogen_version: v0.2.26 +matrix_client_hydrogen_version: v0.3.1 matrix_client_hydrogen_docker_image: "{{ matrix_client_hydrogen_docker_image_name_prefix }}vectorim/hydrogen-web:{{ matrix_client_hydrogen_version }}" matrix_client_hydrogen_docker_image_name_prefix: "{{ 'localhost/' if matrix_client_hydrogen_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_client_hydrogen_docker_image_force_pull: "{{ matrix_client_hydrogen_docker_image.endswith(':latest') }}" @@ -30,7 +31,13 @@ matrix_client_hydrogen_systemd_required_services_list: ['docker.service'] matrix_client_hydrogen_self_check_validate_certificates: true # config.json +matrix_client_hydrogen_push: + appId: io.element.hydrogen.web + gatewayUrl: https://matrix.org + applicationServerKey: "BC-gpSdVHEXhvHSHS0AzzWrQoukv2BE7KzpoPO_FfPacqOo3l1pdqz7rSgmB04pZCWaHPz7XRe6fjLaC-WPDopM" matrix_client_hydrogen_default_hs_url: "" +matrix_client_hydrogen_bugReportEndpointUrl: "https://element.io/bugreports/submit" # noqa var-naming + # Default Hydrogen configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -63,8 +70,8 @@ matrix_client_hydrogen_configuration_default: "{{ lookup('template', 'templates/ # } matrix_client_hydrogen_configuration_extension_json: '{}' -matrix_client_hydrogen_configuration_extension: "{{ matrix_client_hydrogen_configuration_extension_json|from_json if matrix_client_hydrogen_configuration_extension_json|from_json is mapping else {} }}" +matrix_client_hydrogen_configuration_extension: "{{ matrix_client_hydrogen_configuration_extension_json | from_json if matrix_client_hydrogen_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Hydrogen configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_client_hydrogen_configuration_default`. -matrix_client_hydrogen_configuration: "{{ matrix_client_hydrogen_configuration_default|combine(matrix_client_hydrogen_configuration_extension, recursive=True) }}" +matrix_client_hydrogen_configuration: "{{ matrix_client_hydrogen_configuration_default | combine(matrix_client_hydrogen_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-client-hydrogen/tasks/init.yml b/roles/matrix-client-hydrogen/tasks/init.yml index c6801e51..561018e1 100644 --- a/roles/matrix-client-hydrogen/tasks/init.yml +++ b/roles/matrix-client-hydrogen/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: + ansible.builtin.fail: msg: "To self-build the Hydrogen image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_client_hydrogen_container_image_self_build and matrix_client_hydrogen_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-hydrogen.service'] }}" - when: matrix_client_hydrogen_enabled|bool + when: matrix_client_hydrogen_enabled | bool diff --git a/roles/matrix-client-hydrogen/tasks/main.yml b/roles/matrix-client-hydrogen/tasks/main.yml index 13d157cc..89133364 100644 --- a/roles/matrix-client-hydrogen/tasks/main.yml +++ b/roles/matrix-client-hydrogen/tasks/main.yml @@ -1,23 +1,30 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_client_hydrogen_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_client_hydrogen_enabled | bool" tags: - setup-all - setup-client-hydrogen -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_client_hydrogen_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_client_hydrogen_enabled | bool" tags: - setup-all - setup-client-hydrogen -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_client_hydrogen_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_client_hydrogen_enabled | bool" tags: - setup-all - setup-client-hydrogen + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" + delegate_to: 127.0.0.1 + become: false + when: "run_self_check | bool and matrix_client_hydrogen_enabled | bool" + tags: + - self-check diff --git a/roles/matrix-client-hydrogen/tasks/self_check.yml b/roles/matrix-client-hydrogen/tasks/self_check.yml index 28af9c78..978e531f 100644 --- a/roles/matrix-client-hydrogen/tasks/self_check.yml +++ b/roles/matrix-client-hydrogen/tasks/self_check.yml @@ -1,10 +1,10 @@ --- -- set_fact: - matrix_client_hydrogen_url_endpoint_public: "https://{{ matrix_server_fqn_hydrogen }}" +- ansible.builtin.set_fact: + matrix_client_hydrogen_url_endpoint_public: "https://{{ matrix_server_fqn_hydrogen }}/config.json" - name: Check Hydrogen - uri: + ansible.builtin.uri: url: "{{ matrix_client_hydrogen_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_client_hydrogen_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Hydrogen not working - fail: + ansible.builtin.fail: msg: "Failed checking Hydrogen is up at `{{ matrix_server_fqn_hydrogen }}` (checked endpoint: `{{ matrix_client_hydrogen_url_endpoint_public }}`). Is Hydrogen running? Is port 443 open in your firewall? Full error: {{ matrix_client_hydrogen_self_check_result }}" when: "matrix_client_hydrogen_self_check_result.failed or 'json' not in matrix_client_hydrogen_self_check_result" - name: Report working Hydrogen - debug: + ansible.builtin.debug: msg: "Hydrogen at `{{ matrix_server_fqn_hydrogen }}` is working (checked endpoint: `{{ matrix_client_hydrogen_url_endpoint_public }}`)" diff --git a/roles/matrix-client-hydrogen/tasks/setup_install.yml b/roles/matrix-client-hydrogen/tasks/setup_install.yml index db866178..4cd445d0 100644 --- a/roles/matrix-client-hydrogen/tasks/setup_install.yml +++ b/roles/matrix-client-hydrogen/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Hydrogen paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -10,7 +10,7 @@ with_items: - {path: "{{ matrix_client_hydrogen_data_path }}", when: true} - {path: "{{ matrix_client_hydrogen_docker_src_files_path }}", when: "{{ matrix_client_hydrogen_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Hydrogen Docker image is pulled docker_image: @@ -18,14 +18,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_client_hydrogen_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_client_hydrogen_docker_image_force_pull }}" - when: "not matrix_client_hydrogen_container_image_self_build|bool" + when: "not matrix_client_hydrogen_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Hydrogen repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_client_hydrogen_container_image_self_build_repo }}" dest: "{{ matrix_client_hydrogen_docker_src_files_path }}" version: "{{ matrix_client_hydrogen_docker_image.split(':')[1] }}" @@ -33,19 +33,19 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_client_hydrogen_git_pull_results - when: "matrix_client_hydrogen_container_image_self_build|bool" + when: "matrix_client_hydrogen_container_image_self_build | bool" - name: Ensure Hydrogen configuration installed - copy: - content: "{{ matrix_client_hydrogen_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_client_hydrogen_configuration | to_nice_json }}" dest: "{{ matrix_client_hydrogen_docker_src_files_path }}/src/platform/web/assets/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: "matrix_client_hydrogen_container_image_self_build|bool" + when: "matrix_client_hydrogen_container_image_self_build | bool" - name: Ensure Hydrogen additional config files installed - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ matrix_client_hydrogen_data_path }}/{{ item.name }}" mode: 0644 @@ -66,16 +66,16 @@ dockerfile: Dockerfile path: "{{ matrix_client_hydrogen_docker_src_files_path }}" pull: true - when: "matrix_client_hydrogen_container_image_self_build|bool" + when: "matrix_client_hydrogen_container_image_self_build | bool" - name: Ensure matrix-client-hydrogen.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-client-hydrogen.service.j2" dest: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" mode: 0644 register: matrix_client_hydrogen_systemd_service_result - name: Ensure systemd reloaded after matrix-client-hydrogen.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_hydrogen_systemd_service_result.changed|bool" + when: "matrix_client_hydrogen_systemd_service_result.changed | bool" diff --git a/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml b/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml index 7aff2916..d543cbb3 100644 --- a/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml +++ b/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-client-hydrogen.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" register: matrix_client_hydrogen_service_stat - name: Ensure matrix-client-hydrogen is stopped - service: + ansible.builtin.service: name: matrix-client-hydrogen state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_hydrogen_service_stat.stat.exists|bool" + when: "matrix_client_hydrogen_service_stat.stat.exists | bool" - name: Ensure matrix-client-hydrogen.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" state: absent - when: "matrix_client_hydrogen_service_stat.stat.exists|bool" + when: "matrix_client_hydrogen_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-client-hydrogen.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_hydrogen_service_stat.stat.exists|bool" + when: "matrix_client_hydrogen_service_stat.stat.exists | bool" - name: Ensure Hydrogen paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_client_hydrogen_data_path }}" state: absent diff --git a/roles/matrix-client-hydrogen/tasks/validate_config.yml b/roles/matrix-client-hydrogen/tasks/validate_config.yml index d3b9a709..65b0e14f 100644 --- a/roles/matrix-client-hydrogen/tasks/validate_config.yml +++ b/roles/matrix-client-hydrogen/tasks/validate_config.yml @@ -1,9 +1,9 @@ --- - name: Fail if required Hydrogen settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) to use Hydrogen. - when: "(vars[item] == '' or vars[item] is none) and matrix_client_hydrogen_container_image_self_build|bool" + when: "(vars[item] == '' or vars[item] is none) and matrix_client_hydrogen_container_image_self_build | bool" with_items: - "matrix_client_hydrogen_default_hs_url" diff --git a/roles/matrix-client-hydrogen/templates/config.json.j2 b/roles/matrix-client-hydrogen/templates/config.json.j2 index 62a849b0..161ee47b 100644 --- a/roles/matrix-client-hydrogen/templates/config.json.j2 +++ b/roles/matrix-client-hydrogen/templates/config.json.j2 @@ -1,3 +1,12 @@ { - "defaultHomeServer": {{ matrix_client_hydrogen_default_hs_url|string|to_json }} + "push": {{ matrix_client_hydrogen_push | to_json }}, + "defaultHomeServer": {{ matrix_client_hydrogen_default_hs_url | string | to_json }}, + "bugReportEndpointUrl": {{ matrix_client_hydrogen_bugReportEndpointUrl | to_json }}, + "themeManifests": [ + "assets/theme-Element.json" + ], + "defaultTheme": { + "light": "element-light", + "dark": "element-dark" + } } diff --git a/roles/matrix-common-after/tasks/dump_runtime_results.yml b/roles/matrix-common-after/tasks/dump_runtime_results.yml index 44ae1a30..4074a625 100644 --- a/roles/matrix-common-after/tasks/dump_runtime_results.yml +++ b/roles/matrix-common-after/tasks/dump_runtime_results.yml @@ -1,7 +1,7 @@ --- # Ansible outputs the message in the `item=` field. # It's unnecessary to output it again in the actual message, so we don't. -- debug: +- ansible.builtin.debug: msg: "" with_items: "{{ matrix_playbook_runtime_results }}" when: "matrix_playbook_runtime_results is defined and matrix_playbook_runtime_results|length > 0" diff --git a/roles/matrix-common-after/tasks/main.yml b/roles/matrix-common-after/tasks/main.yml index f3ccf3a5..1b360698 100644 --- a/roles/matrix-common-after/tasks/main.yml +++ b/roles/matrix-common-after/tasks/main.yml @@ -1,19 +1,19 @@ --- -- import_tasks: "{{ role_path }}/tasks/start.yml" - when: run_start|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/start.yml" + when: run_start | bool tags: - start -- import_tasks: "{{ role_path }}/tasks/stop.yml" - when: run_stop|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/stop.yml" + when: run_stop | bool tags: - stop -- import_tasks: "{{ role_path }}/tasks/dump_runtime_results.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dump_runtime_results.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/run_docker_prune.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/run_docker_prune.yml" tags: - run-docker-prune diff --git a/roles/matrix-common-after/tasks/run_docker_prune.yml b/roles/matrix-common-after/tasks/run_docker_prune.yml index a7e35a03..02dfadc5 100644 --- a/roles/matrix-common-after/tasks/run_docker_prune.yml +++ b/roles/matrix-common-after/tasks/run_docker_prune.yml @@ -1,4 +1,7 @@ --- - name: Run Docker System Prune - command: "{{ matrix_host_command_docker }} system prune -a -f" + ansible.builtin.command: + cmd: "{{ matrix_host_command_docker }} system prune -a -f" + register: matrix_common_after_docker_prune_result + changed_when: matrix_common_after_docker_prune_result.rc == 0 diff --git a/roles/matrix-common-after/tasks/start.yml b/roles/matrix-common-after/tasks/start.yml index 02fa672e..890eabfa 100644 --- a/roles/matrix-common-after/tasks/start.yml +++ b/roles/matrix-common-after/tasks/start.yml @@ -1,22 +1,22 @@ --- - name: Determine whether we should make services autostart - set_fact: - matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled|default('') == '' else matrix_services_autostart_enabled|bool }}" + ansible.builtin.set_fact: + matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled | default('') == '' else matrix_services_autostart_enabled | bool }}" - name: Ensure systemd is reloaded - service: + ansible.builtin.service: daemon_reload: true - name: Ensure Matrix services are stopped - service: + ansible.builtin.service: name: "{{ item }}" state: stopped with_items: "{{ matrix_systemd_services_list }}" when: not ansible_check_mode - name: Ensure Matrix services are started - service: + ansible.builtin.service: name: "{{ item }}" enabled: "{{ matrix_services_autostart_enabled_bool }}" state: started @@ -29,17 +29,17 @@ # Waiting too long (30s) may not work for a similar reason, # as we may run into systemd's automatic restart logic retrying the service. - name: Wait a bit, so that services can start (or fail) - wait_for: + ansible.builtin.wait_for: timeout: "{{ matrix_common_after_systemd_service_start_wait_for_timeout_seconds }}" delegate_to: 127.0.0.1 become: false - block: - name: Populate service facts - service_facts: + ansible.builtin.service_facts: - name: Fail if service isn't detected to be running - fail: + ansible.builtin.fail: msg: >- {{ item }} was not detected to be running. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.). @@ -57,13 +57,13 @@ # service_facts is not collecting the data successfully. # Therefore iterating here manually - name: Fetch systemd information - systemd: + ansible.builtin.systemd: name: "{{ item }}" register: systemdstatus with_items: "{{ matrix_systemd_services_list }}" - name: Fail if service isn't detected to be running - fail: + ansible.builtin.fail: msg: >- {{ item.item }} was not detected to be running. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.). diff --git a/roles/matrix-common-after/tasks/stop.yml b/roles/matrix-common-after/tasks/stop.yml index 5ae0afbb..a343999c 100644 --- a/roles/matrix-common-after/tasks/stop.yml +++ b/roles/matrix-common-after/tasks/stop.yml @@ -1,7 +1,7 @@ --- - name: Ensure Matrix services stopped - service: + ansible.builtin.service: name: "{{ item }}" state: stopped with_items: "{{ matrix_systemd_services_list }}" diff --git a/roles/matrix-corporal/defaults/main.yml b/roles/matrix-corporal/defaults/main.yml index 66896e0e..bb1b8fa1 100644 --- a/roles/matrix-corporal/defaults/main.yml +++ b/roles/matrix-corporal/defaults/main.yml @@ -1,6 +1,6 @@ --- # matrix-corporal is a reconciliator and gateway for a managed Matrix server. -# See: https://github.com/devture/matrix-corporal +# Project source code URL: https://github.com/devture/matrix-corporal matrix_corporal_enabled: true @@ -23,7 +23,7 @@ matrix_corporal_container_extra_arguments: [] # List of systemd services that matrix-corporal.service depends on matrix_corporal_systemd_required_services_list: ['docker.service'] -matrix_corporal_version: 2.2.3 +matrix_corporal_version: 2.3.0 matrix_corporal_docker_image: "{{ matrix_corporal_docker_image_name_prefix }}devture/matrix-corporal:{{ matrix_corporal_docker_image_tag }}" matrix_corporal_docker_image_name_prefix: "{{ 'localhost/' if matrix_corporal_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_corporal_docker_image_tag: "{{ matrix_corporal_version }}" # for backward-compatibility @@ -100,8 +100,8 @@ matrix_corporal_configuration_default: "{{ lookup('template', 'templates/config. # } matrix_corporal_configuration_extension_json: '{}' -matrix_corporal_configuration_extension: "{{ matrix_corporal_configuration_extension_json|from_json if matrix_corporal_configuration_extension_json|from_json is mapping else {} }}" +matrix_corporal_configuration_extension: "{{ matrix_corporal_configuration_extension_json | from_json if matrix_corporal_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Corporal configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_corporal_configuration_default`. -matrix_corporal_configuration: "{{ matrix_corporal_configuration_default|combine(matrix_corporal_configuration_extension, recursive=True) }}" +matrix_corporal_configuration: "{{ matrix_corporal_configuration_default | combine(matrix_corporal_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-corporal/tasks/init.yml b/roles/matrix-corporal/tasks/init.yml index b2f50e93..dffdbe90 100644 --- a/roles/matrix-corporal/tasks/init.yml +++ b/roles/matrix-corporal/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Matrix Corporal image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_corporal_container_image_self_build and matrix_corporal_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-corporal.service'] }}" - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool diff --git a/roles/matrix-corporal/tasks/main.yml b/roles/matrix-corporal/tasks/main.yml index 7ff359d0..1699262b 100644 --- a/roles/matrix-corporal/tasks/main.yml +++ b/roles/matrix-corporal/tasks/main.yml @@ -1,24 +1,24 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_corporal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_corporal_enabled | bool" tags: - setup-all - setup-corporal -- import_tasks: "{{ role_path }}/tasks/setup_corporal.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_corporal.yml" + when: run_setup | bool tags: - setup-all - setup-corporal -- import_tasks: "{{ role_path }}/tasks/self_check_corporal.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_corporal.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_corporal_enabled|bool" + when: "run_self_check | bool and matrix_corporal_enabled | bool" tags: - self-check diff --git a/roles/matrix-corporal/tasks/self_check_corporal.yml b/roles/matrix-corporal/tasks/self_check_corporal.yml index b702c00f..3ddda8e0 100644 --- a/roles/matrix-corporal/tasks/self_check_corporal.yml +++ b/roles/matrix-corporal/tasks/self_check_corporal.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: corporal_client_api_url_endpoint_public: "https://{{ matrix_server_fqn_matrix }}/_matrix/client/corporal" - name: Check Matrix Corporal HTTP gateway - uri: + ansible.builtin.uri: url: "{{ corporal_client_api_url_endpoint_public }}" follow_redirects: none return_content: true @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Matrix Corporal HTTP gateway not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Corporal is fronting the Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ corporal_client_api_url_endpoint_public }}`). Is matrix-corporal running? Is port 443 open in your firewall? Full error: {{ result_corporal_client_api }}" when: "result_corporal_client_api.failed or 'Matrix Client-Server API protected by Matrix Corporal' not in result_corporal_client_api.content" - name: Report working Matrix Corporal HTTP gateway - debug: + ansible.builtin.debug: msg: "Matrix Corporal is fronting the Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ corporal_client_api_url_endpoint_public }}`)" diff --git a/roles/matrix-corporal/tasks/setup_corporal.yml b/roles/matrix-corporal/tasks/setup_corporal.yml index a3582592..583c27eb 100644 --- a/roles/matrix-corporal/tasks/setup_corporal.yml +++ b/roles/matrix-corporal/tasks/setup_corporal.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix Corporal paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -15,10 +15,10 @@ - "{{ matrix_corporal_config_dir_path }}" - "{{ matrix_corporal_cache_dir_path }}" - "{{ matrix_corporal_var_dir_path }}" - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool - name: Ensure Matrix Corporal repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_corporal_container_image_self_build_repo }}" dest: "{{ matrix_corporal_container_src_files_path }}" version: "{{ matrix_corporal_docker_image.split(':')[1] }}" @@ -26,7 +26,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_corporal_git_pull_results - when: "matrix_corporal_enabled|bool and matrix_corporal_container_image_self_build|bool" + when: "matrix_corporal_enabled | bool and matrix_corporal_container_image_self_build | bool" - name: Ensure Matrix Corporal Docker image is built docker_image: @@ -38,7 +38,7 @@ dockerfile: etc/docker/Dockerfile path: "{{ matrix_corporal_container_src_files_path }}" pull: true - when: "matrix_corporal_enabled|bool and matrix_corporal_container_image_self_build|bool" + when: "matrix_corporal_enabled | bool and matrix_corporal_container_image_self_build | bool" - name: Ensure Matrix Corporal Docker image is pulled docker_image: @@ -46,33 +46,33 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_corporal_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_corporal_docker_image_force_pull }}" - when: "matrix_corporal_enabled|bool and not matrix_corporal_container_image_self_build|bool" + when: "matrix_corporal_enabled | bool and not matrix_corporal_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Matrix Corporal config installed - copy: - content: "{{ matrix_corporal_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_corporal_configuration | to_nice_json }}" dest: "{{ matrix_corporal_config_dir_path }}/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool - name: Ensure matrix-corporal.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-corporal.service.j2" dest: "{{ matrix_systemd_path }}/matrix-corporal.service" mode: 0644 register: matrix_corporal_systemd_service_result - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool - name: Ensure systemd reloaded after matrix-corporal.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_corporal_enabled|bool and matrix_corporal_systemd_service_result.changed" + when: "matrix_corporal_enabled | bool and matrix_corporal_systemd_service_result.changed" # @@ -80,42 +80,42 @@ # - name: Check existence of matrix-corporal service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-corporal.service" register: matrix_corporal_service_stat - when: "not matrix_corporal_enabled|bool" + when: "not matrix_corporal_enabled | bool" - name: Ensure matrix-corporal is stopped - service: + ansible.builtin.service: name: matrix-corporal state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_corporal_enabled|bool and matrix_corporal_service_stat.stat.exists" + when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists" - name: Ensure matrix-corporal.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-corporal.service" state: absent - when: "not matrix_corporal_enabled|bool and matrix_corporal_service_stat.stat.exists" + when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-corporal.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_corporal_enabled|bool and matrix_corporal_service_stat.stat.exists" + when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists" - name: Ensure matrix-corporal files don't exist - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: - "{{ matrix_systemd_path }}/matrix-corporal.service" - "{{ matrix_corporal_config_dir_path }}/config.json" - when: "not matrix_corporal_enabled|bool" + when: "not matrix_corporal_enabled | bool" - name: Ensure Matrix Corporal Docker image doesn't exist docker_image: name: "{{ matrix_corporal_docker_image }}" state: absent - when: "not matrix_corporal_enabled|bool" + when: "not matrix_corporal_enabled | bool" diff --git a/roles/matrix-corporal/tasks/validate_config.yml b/roles/matrix-corporal/tasks/validate_config.yml index a8930e7e..26d16c6d 100644 --- a/roles/matrix-corporal/tasks/validate_config.yml +++ b/roles/matrix-corporal/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required matrix-corporal settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using matrix-corporal. when: "vars[item] == ''" @@ -12,12 +12,12 @@ - "matrix_corporal_policy_provider_config" - name: Fail if HTTP API enabled, but no token set - fail: + ansible.builtin.fail: msg: "The Matrix Corporal HTTP API is enabled (`matrix_corporal_http_api_enabled`), but no auth token has been set in `matrix_corporal_http_api_auth_token`" - when: "matrix_corporal_http_api_enabled|bool and matrix_corporal_http_api_auth_token == ''" + when: "matrix_corporal_http_api_enabled | bool and matrix_corporal_http_api_auth_token == ''" - name: (Deprecation) Catch and report renamed corporal variables - fail: + 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 }}`). diff --git a/roles/matrix-coturn/defaults/main.yml b/roles/matrix-coturn/defaults/main.yml index 46492e21..e1a544ba 100644 --- a/roles/matrix-coturn/defaults/main.yml +++ b/roles/matrix-coturn/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/coturn/coturn matrix_coturn_enabled: true @@ -7,7 +8,7 @@ matrix_coturn_container_image_self_build_repo: "https://github.com/coturn/coturn matrix_coturn_container_image_self_build_repo_version: "docker/{{ matrix_coturn_version }}" matrix_coturn_container_image_self_build_repo_dockerfile_path: "docker/coturn/alpine/Dockerfile" -matrix_coturn_version: 4.5.2-r11 +matrix_coturn_version: 4.5.2-r13 matrix_coturn_docker_image: "{{ matrix_coturn_docker_image_name_prefix }}coturn/coturn:{{ matrix_coturn_version }}-alpine" matrix_coturn_docker_image_name_prefix: "{{ 'localhost/' if matrix_coturn_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_coturn_docker_image_force_pull: "{{ matrix_coturn_docker_image.endswith(':latest') }}" diff --git a/roles/matrix-coturn/tasks/init.yml b/roles/matrix-coturn/tasks/init.yml index 93e4fa3a..315dfb65 100644 --- a/roles/matrix-coturn/tasks/init.yml +++ b/roles/matrix-coturn/tasks/init.yml @@ -2,14 +2,14 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the coturn image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_coturn_container_image_self_build and matrix_coturn_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-coturn.service'] }}" - when: matrix_coturn_enabled|bool + when: matrix_coturn_enabled | bool -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-coturn-reload.timer'] }}" - when: "matrix_coturn_enabled|bool and matrix_coturn_tls_enabled|bool" + when: "matrix_coturn_enabled | bool and matrix_coturn_tls_enabled | bool" diff --git a/roles/matrix-coturn/tasks/main.yml b/roles/matrix-coturn/tasks/main.yml index 76352df1..78f712f0 100644 --- a/roles/matrix-coturn/tasks/main.yml +++ b/roles/matrix-coturn/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_coturn_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_coturn_enabled | bool" tags: - setup-all - setup-coturn -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_coturn_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_coturn_enabled | bool" tags: - setup-all - setup-coturn -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_coturn_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_coturn_enabled | bool" tags: - setup-all - setup-coturn diff --git a/roles/matrix-coturn/tasks/setup_install.yml b/roles/matrix-coturn/tasks/setup_install.yml index a721f186..2a1af731 100644 --- a/roles/matrix-coturn/tasks/setup_install.yml +++ b/roles/matrix-coturn/tasks/setup_install.yml @@ -2,12 +2,12 @@ # This is a cleanup/migration task. It can be removed some time in the future. - name: (Migration) Remove deprecated cronjob - file: + ansible.builtin.file: path: "{{ matrix_cron_path }}/matrix-coturn-ssl-reload" state: absent - name: Ensure Matrix Coturn path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -15,7 +15,7 @@ group: "{{ matrix_user_groupname }}" with_items: - {path: "{{ matrix_coturn_docker_src_files_path }}", when: "{{ matrix_coturn_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Coturn image is pulled docker_image: @@ -23,7 +23,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_coturn_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_coturn_docker_image_force_pull }}" - when: "not matrix_coturn_container_image_self_build|bool" + when: "not matrix_coturn_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -31,7 +31,7 @@ - block: - name: Ensure Coturn repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_coturn_container_image_self_build_repo }}" dest: "{{ matrix_coturn_docker_src_files_path }}" version: "{{ matrix_coturn_container_image_self_build_repo_version }}" @@ -50,10 +50,10 @@ dockerfile: "{{ matrix_coturn_container_image_self_build_repo_dockerfile_path }}" path: "{{ matrix_coturn_docker_src_files_path }}" pull: true - when: "matrix_coturn_container_image_self_build|bool" + when: "matrix_coturn_container_image_self_build | bool" - name: Ensure Coturn configuration path exists - file: + ansible.builtin.file: path: "{{ matrix_coturn_base_path }}" state: directory mode: 0750 @@ -61,7 +61,7 @@ group: "{{ matrix_user_groupname }}" - name: Ensure turnserver.conf installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/turnserver.conf.j2" dest: "{{ matrix_coturn_config_path }}" mode: 0644 @@ -74,7 +74,7 @@ driver: bridge - name: Ensure matrix-coturn.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-coturn.service.j2" dest: "{{ matrix_systemd_path }}/matrix-coturn.service" mode: 0644 @@ -84,28 +84,28 @@ # We optimize for the common use-case though (short-lived Let's Encrypt certificates). # Reloading doesn't hurt anyway, so there's no need to make this more flexible. - name: Ensure reloading systemd units installed, if necessary - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/{{ item }}.j2" dest: "{{ matrix_systemd_path }}/{{ item }}" mode: 0644 register: "matrix_coturn_systemd_service_change_results" - when: "matrix_coturn_tls_enabled|bool" + when: "matrix_coturn_tls_enabled | bool" with_items: - matrix-coturn-reload.service - matrix-coturn-reload.timer # A similar task exists in `setup_uninstall.yml` - name: Ensure reloading systemd units uninstalled, if unnecessary - file: + ansible.builtin.file: path: "{{ item }}" state: absent register: "matrix_coturn_systemd_service_change_results" - when: "not matrix_coturn_tls_enabled|bool" + when: "not matrix_coturn_tls_enabled | bool" with_items: - matrix-coturn-reload.service - matrix-coturn-reload.timer - name: Ensure systemd reloaded if systemd units changed - service: + ansible.builtin.service: daemon_reload: true when: "matrix_coturn_systemd_service_change_results.changed" diff --git a/roles/matrix-coturn/tasks/setup_uninstall.yml b/roles/matrix-coturn/tasks/setup_uninstall.yml index 097ba873..5dd2788e 100644 --- a/roles/matrix-coturn/tasks/setup_uninstall.yml +++ b/roles/matrix-coturn/tasks/setup_uninstall.yml @@ -1,30 +1,30 @@ --- - name: Check existence of matrix-coturn service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-coturn.service" register: matrix_coturn_service_stat - when: "not matrix_coturn_enabled|bool" + when: "not matrix_coturn_enabled | bool" - name: Ensure matrix-coturn is stopped - service: + ansible.builtin.service: name: matrix-coturn state: stopped enabled: false daemon_reload: true - when: "matrix_coturn_service_stat.stat.exists|bool" + when: "matrix_coturn_service_stat.stat.exists | bool" - name: Ensure matrix-coturn-reload.timer is stopped - service: + ansible.builtin.service: name: matrix-coturn state: stopped enabled: false daemon_reload: true failed_when: false - when: "matrix_coturn_service_stat.stat.exists|bool" + when: "matrix_coturn_service_stat.stat.exists | bool" - name: Ensure systemd units don't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/{{ item }}" state: absent register: matrix_coturn_systemd_unit_uninstallation_result @@ -34,12 +34,12 @@ - matrix-coturn-reload.timer - name: Ensure systemd reloaded after unit removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_coturn_systemd_unit_uninstallation_result.changed|bool" + when: "matrix_coturn_systemd_unit_uninstallation_result.changed | bool" - name: Ensure Matrix coturn paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_coturn_base_path }}" state: absent diff --git a/roles/matrix-coturn/tasks/validate_config.yml b/roles/matrix-coturn/tasks/validate_config.yml index 637f720d..90e842e1 100644 --- a/roles/matrix-coturn/tasks/validate_config.yml +++ b/roles/matrix-coturn/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Coturn settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Coturn. when: "vars[item] == ''" diff --git a/roles/matrix-dendrite/defaults/main.yml b/roles/matrix-dendrite/defaults/main.yml index 7f2e629a..476f86a2 100644 --- a/roles/matrix-dendrite/defaults/main.yml +++ b/roles/matrix-dendrite/defaults/main.yml @@ -1,12 +1,12 @@ --- # Dendrite is a second-generation Matrix homeserver currently in Beta -# See: https://github.com/matrix-org/dendrite +# Project source code URL: https://github.com/matrix-org/dendrite matrix_dendrite_enabled: true matrix_dendrite_docker_image: "{{ matrix_dendrite_docker_image_name_prefix }}matrixdotorg/dendrite-monolith:{{ matrix_dendrite_docker_image_tag }}" matrix_dendrite_docker_image_name_prefix: "docker.io/" -matrix_dendrite_docker_image_tag: "v0.8.1" +matrix_dendrite_docker_image_tag: "v0.9.1" matrix_dendrite_docker_image_force_pull: "{{ matrix_dendrite_docker_image.endswith(':latest') }}" matrix_dendrite_base_path: "{{ matrix_base_data_path }}/dendrite" @@ -27,10 +27,10 @@ matrix_dendrite_http_bind_port: 8008 matrix_dendrite_https_bind_port: ~ # This is passed as an `-http-bind-address` flag to the Dendrite server in the container -matrix_dendrite_http_bind_address: "{{ (':' + matrix_dendrite_http_bind_port|string) if matrix_dendrite_http_bind_port else '' }}" +matrix_dendrite_http_bind_address: "{{ (':' + matrix_dendrite_http_bind_port | string) if matrix_dendrite_http_bind_port else '' }}" # This is passed as an `-https-bind-address` flag to the Dendrite server in the container -matrix_dendrite_https_bind_address: "{{ (':' + matrix_dendrite_https_bind_port|string) if matrix_dendrite_https_bind_port else '' }}" +matrix_dendrite_https_bind_address: "{{ (':' + matrix_dendrite_https_bind_port | string) if matrix_dendrite_https_bind_port else '' }}" # Controls whether the matrix-dendrite container exposes the HTTP port (tcp/{{ matrix_dendrite_http_bind_port }} in the container). # @@ -61,7 +61,7 @@ matrix_dendrite_systemd_wanted_services_list: [] # Specifies which template files to use when configuring Dendrite. # If you'd like to have your own different configuration, feel free to copy and paste # the original files into your inventory (e.g. in `inventory/host_vars//`) -# and then change the specific host's `vars.yaml` file like this: +# and then change the specific host's `vars.yml` file like this: # matrix_dendrite_template_dendrite_config: "{{ playbook_dir }}/inventory/host_vars//dendrite.yaml.j2" matrix_dendrite_template_dendrite_config: "{{ role_path }}/templates/dendrite/dendrite.yaml.j2" @@ -89,6 +89,7 @@ matrix_dendrite_registration_disabled: false matrix_dendrite_enable_registration_captcha: false matrix_dendrite_recaptcha_public_key: "" matrix_dendrite_recaptcha_private_key: "" +matrix_dendrite_recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify" # A list of additional "volumes" to mount in the container. # This list gets populated dynamically based on Dendrite extensions that have been enabled. @@ -167,8 +168,8 @@ matrix_dendrite_configuration_extension_yaml: | # system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ" # room_name: "Server Notices" -matrix_dendrite_configuration_extension: "{{ matrix_dendrite_configuration_extension_yaml|from_yaml if matrix_dendrite_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_dendrite_configuration_extension: "{{ matrix_dendrite_configuration_extension_yaml | from_yaml if matrix_dendrite_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final Dendrite configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_dendrite_configuration_yaml`. -matrix_dendrite_configuration: "{{ matrix_dendrite_configuration_yaml|from_yaml|combine(matrix_dendrite_configuration_extension, recursive=True) }}" +matrix_dendrite_configuration: "{{ matrix_dendrite_configuration_yaml | from_yaml | combine(matrix_dendrite_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-dendrite/tasks/dendrite/setup.yml b/roles/matrix-dendrite/tasks/dendrite/setup.yml index f988d918..1a849729 100644 --- a/roles/matrix-dendrite/tasks/dendrite/setup.yml +++ b/roles/matrix-dendrite/tasks/dendrite/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/dendrite/setup_install.yml" - when: matrix_dendrite_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dendrite/setup_install.yml" + when: matrix_dendrite_enabled | bool -- import_tasks: "{{ role_path }}/tasks/dendrite/setup_uninstall.yml" - when: "not matrix_dendrite_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dendrite/setup_uninstall.yml" + when: "not matrix_dendrite_enabled | bool" diff --git a/roles/matrix-dendrite/tasks/dendrite/setup_install.yml b/roles/matrix-dendrite/tasks/dendrite/setup_install.yml index a18ad065..3052e101 100644 --- a/roles/matrix-dendrite/tasks/dendrite/setup_install.yml +++ b/roles/matrix-dendrite/tasks/dendrite/setup_install.yml @@ -1,7 +1,7 @@ --- # This will throw a Permission Denied error if already mounted using fuse - name: Check Dendrite media store path - stat: + ansible.builtin.stat: path: "{{ matrix_dendrite_media_store_path }}" register: local_path_media_store_stat ignore_errors: true @@ -9,7 +9,7 @@ # This is separate and conditional, to ensure we don't execute it # if the path already exists or we failed to check, because it's mounted using fuse. - name: Ensure Dendrite media store path exists - file: + ansible.builtin.file: path: "{{ matrix_dendrite_media_store_path }}" state: directory mode: 0750 @@ -29,7 +29,7 @@ until: result is not failed - name: Check if a Dendrite signing key exists - stat: + ansible.builtin.stat: path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem" register: matrix_dendrite_signing_key_stat @@ -37,7 +37,7 @@ # We don't use the `docker_container` module, because using it with `cap_drop` requires # a very recent version, which is not available for a lot of people yet. - name: Generate Dendrite signing key - command: | + ansible.builtin.command: | docker run --rm --name=matrix-dendrite-config @@ -48,34 +48,34 @@ when: "not matrix_dendrite_signing_key_stat.stat.exists" - name: Ensure Dendrite server key exists - file: + ansible.builtin.file: path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Dendrite configuration installed - copy: - content: "{{ matrix_dendrite_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-dendrite.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/dendrite/systemd/matrix-dendrite.service.j2" dest: "{{ matrix_systemd_path }}/matrix-dendrite.service" mode: 0644 register: matrix_dendrite_systemd_service_result - name: Ensure systemd reloaded after matrix-dendrite.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_dendrite_systemd_service_result.changed|bool" + when: "matrix_dendrite_systemd_service_result.changed | bool" - name: Ensure matrix-dendrite-create-account script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/dendrite/usr-local-bin/matrix-dendrite-create-account.j2" dest: "{{ matrix_local_bin_path }}/matrix-dendrite-create-account" mode: 0750 diff --git a/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml b/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml index 89d5481c..b6d8cfac 100644 --- a/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml +++ b/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-dendrite service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-dendrite.service" register: matrix_dendrite_service_stat - name: Ensure matrix-dendrite is stopped - service: + ansible.builtin.service: name: matrix-dendrite state: stopped daemon_reload: true @@ -14,13 +14,13 @@ when: "matrix_dendrite_service_stat.stat.exists" - name: Ensure matrix-dendrite.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-dendrite.service" state: absent when: "matrix_dendrite_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-dendrite.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_dendrite_service_stat.stat.exists" diff --git a/roles/matrix-dendrite/tasks/init.yml b/roles/matrix-dendrite/tasks/init.yml index 524ef6ee..4ce641e9 100644 --- a/roles/matrix-dendrite/tasks/init.yml +++ b/roles/matrix-dendrite/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dendrite.service'] }}" - when: matrix_dendrite_enabled|bool + when: matrix_dendrite_enabled | bool diff --git a/roles/matrix-dendrite/tasks/main.yml b/roles/matrix-dendrite/tasks/main.yml index 5483adec..d14beb15 100644 --- a/roles/matrix-dendrite/tasks/main.yml +++ b/roles/matrix-dendrite/tasks/main.yml @@ -1,42 +1,42 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-dendrite -- import_tasks: "{{ role_path }}/tasks/setup_dendrite.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_dendrite.yml" + when: run_setup | bool tags: - setup-all - setup-dendrite -- import_tasks: "{{ role_path }}/tasks/register_user.yml" - when: run_dendrite_register_user|bool and matrix_dendrite_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/register_user.yml" + when: run_dendrite_register_user | bool and matrix_dendrite_enabled | bool tags: - register-user -- import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool and matrix_dendrite_enabled|bool + when: run_self_check | bool and matrix_dendrite_enabled | bool tags: - self-check -- import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool and matrix_dendrite_enabled|bool + when: run_self_check | bool and matrix_dendrite_enabled | bool tags: - self-check - name: Mark matrix-dendrite role as executed - set_fact: + ansible.builtin.set_fact: matrix_dendrite_role_executed: true tags: - always diff --git a/roles/matrix-dendrite/tasks/register_user.yml b/roles/matrix-dendrite/tasks/register_user.yml index b8e3ae5e..e1b97482 100644 --- a/roles/matrix-dendrite/tasks/register_user.yml +++ b/roles/matrix-dendrite/tasks/register_user.yml @@ -1,25 +1,28 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `username` variable needs to be provided to this playbook, via --extra-vars" when: "username is not defined or username == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `password` variable needs to be provided to this playbook, via --extra-vars" when: "password is not defined or password == ''" - name: Ensure matrix-dendrite is started - service: + ansible.builtin.service: name: matrix-dendrite state: started daemon_reload: true register: start_result - name: Wait a while, so that Dendrite can manage to start - pause: + ansible.builtin.pause: seconds: 7 - when: "start_result.changed" + when: start_result.changed | bool - name: Register user - command: "{{ matrix_local_bin_path }}/matrix-dendrite-create-account {{ username|quote }} {{ password|quote }}" + ansible.builtin.command: + cmd: "{{ matrix_local_bin_path }}/matrix-dendrite-create-account {{ username | quote }} {{ password | quote }}" + register: matrix_dendrite_register_user_result + changed_when: matrix_dendrite_register_user_result.rc == 0 diff --git a/roles/matrix-dendrite/tasks/self_check_client_api.yml b/roles/matrix-dendrite/tasks/self_check_client_api.yml index 2470d818..99b6cb40 100644 --- a/roles/matrix-dendrite/tasks/self_check_client_api.yml +++ b/roles/matrix-dendrite/tasks/self_check_client_api.yml @@ -1,6 +1,6 @@ --- - name: Check Matrix Client API - uri: + ansible.builtin.uri: url: "{{ matrix_dendrite_client_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_dendrite_self_check_validate_certificates }}" @@ -9,10 +9,10 @@ check_mode: false - name: Fail if Matrix Client API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Client API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_client_api_url_endpoint_public }}`). Is Dendrite running? Is port 443 open in your firewall? Full error: {{ result_matrix_dendrite_client_api }}" when: "(result_matrix_dendrite_client_api.failed or 'json' not in result_matrix_dendrite_client_api)" - name: Report working Matrix Client API - debug: + ansible.builtin.debug: msg: "The Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_client_api_url_endpoint_public }}`) is working" diff --git a/roles/matrix-dendrite/tasks/self_check_federation_api.yml b/roles/matrix-dendrite/tasks/self_check_federation_api.yml index 0afca2cb..25b2871c 100644 --- a/roles/matrix-dendrite/tasks/self_check_federation_api.yml +++ b/roles/matrix-dendrite/tasks/self_check_federation_api.yml @@ -1,6 +1,6 @@ --- - name: Check Matrix Federation API - uri: + ansible.builtin.uri: url: "{{ matrix_dendrite_federation_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_dendrite_self_check_validate_certificates }}" @@ -9,16 +9,16 @@ check_mode: false - name: Fail if Matrix Federation API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_federation_api_url_endpoint_public }}`). Is Dendrite running? Is port {{ matrix_federation_public_port }} open in your firewall? Full error: {{ result_matrix_dendrite_federation_api }}" - when: "matrix_dendrite_federation_enabled|bool and (result_matrix_dendrite_federation_api.failed or 'json' not in result_matrix_dendrite_federation_api)" + when: "matrix_dendrite_federation_enabled | bool and (result_matrix_dendrite_federation_api.failed or 'json' not in result_matrix_dendrite_federation_api)" - name: Fail if Matrix Federation API unexpectedly enabled - fail: + ansible.builtin.fail: msg: "Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_federation_api_url_endpoint_public }}`) despite being disabled." - when: "not matrix_dendrite_federation_enabled|bool and not result_matrix_dendrite_federation_api.failed" + when: "not matrix_dendrite_federation_enabled | bool and not result_matrix_dendrite_federation_api.failed" - name: Report working Matrix Federation API - debug: + ansible.builtin.debug: msg: "The Matrix Federation API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_federation_api_url_endpoint_public }}`) is working" - when: "matrix_dendrite_federation_enabled|bool" + when: "matrix_dendrite_federation_enabled | bool" diff --git a/roles/matrix-dendrite/tasks/setup_dendrite.yml b/roles/matrix-dendrite/tasks/setup_dendrite.yml index fc306759..f74f08c2 100644 --- a/roles/matrix-dendrite/tasks/setup_dendrite.yml +++ b/roles/matrix-dendrite/tasks/setup_dendrite.yml @@ -1,6 +1,6 @@ --- - name: Ensure Dendrite paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -10,6 +10,6 @@ - {path: "{{ matrix_dendrite_config_dir_path }}", when: true} - {path: "{{ matrix_dendrite_ext_path }}", when: true} - {path: "{{ matrix_dendrite_nats_storage_path }}", when: true} - when: "matrix_dendrite_enabled|bool and item.when" + when: "matrix_dendrite_enabled | bool and item.when" -- import_tasks: "{{ role_path }}/tasks/dendrite/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dendrite/setup.yml" diff --git a/roles/matrix-dendrite/tasks/validate_config.yml b/roles/matrix-dendrite/tasks/validate_config.yml index 2d2cf4c5..390da938 100644 --- a/roles/matrix-dendrite/tasks/validate_config.yml +++ b/roles/matrix-dendrite/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required Dendrite settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Dendrite. when: "vars[item] == ''" @@ -8,7 +8,7 @@ - "matrix_dendrite_registration_shared_secret" - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). diff --git a/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 b/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 index fcede405..62f8caba 100644 --- a/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 +++ b/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 @@ -165,7 +165,7 @@ client_api: # If set, allows registration by anyone who knows the shared secret, regardless of # whether registration is otherwise disabled. - registration_shared_secret: {{ matrix_dendrite_registration_shared_secret|string|to_json }} + registration_shared_secret: {{ matrix_dendrite_registration_shared_secret | string|to_json }} # Whether to require reCAPTCHA for registration. enable_registration_captcha: {{ matrix_dendrite_enable_registration_captcha|to_json }} @@ -174,7 +174,7 @@ client_api: recaptcha_public_key: {{ matrix_dendrite_recaptcha_public_key|to_json }} recaptcha_private_key: {{ matrix_dendrite_recaptcha_private_key|to_json }} recaptcha_bypass_secret: "" - recaptcha_siteverify_api: "" + recaptcha_siteverify_api: {{ matrix_dendrite_recaptcha_siteverify_api|to_json }} # TURN server information that this homeserver should send to clients. turn: diff --git a/roles/matrix-dendrite/templates/dendrite/systemd/matrix-dendrite.service.j2 b/roles/matrix-dendrite/templates/dendrite/systemd/matrix-dendrite.service.j2 index 0457917a..0613f443 100644 --- a/roles/matrix-dendrite/templates/dendrite/systemd/matrix-dendrite.service.j2 +++ b/roles/matrix-dendrite/templates/dendrite/systemd/matrix-dendrite.service.j2 @@ -46,13 +46,13 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-dendrite \ {% endfor %} {{ matrix_dendrite_docker_image }} \ -config /data/dendrite.yaml \ + {{ matrix_dendrite_process_extra_arguments|join(' ') }} \ {% if matrix_dendrite_http_bind_address %} -http-bind-address {{ matrix_dendrite_http_bind_address }} {% endif %} {% if matrix_dendrite_https_bind_address %} -https-bind-address {{ matrix_dendrite_https_bind_address }} {% endif %} - {{ matrix_dendrite_process_extra_arguments|join(' ') }} ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-dendrite 2>/dev/null || true' ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-dendrite 2>/dev/null || true' diff --git a/roles/matrix-dendrite/vars/main.yml b/roles/matrix-dendrite/vars/main.yml index 60d5f4eb..fcf020c2 100644 --- a/roles/matrix-dendrite/vars/main.yml +++ b/roles/matrix-dendrite/vars/main.yml @@ -5,7 +5,7 @@ matrix_dendrite_federation_api_url_endpoint_public: "https://{{ matrix_server_fq # Tells whether this role had executed or not. Toggled to `true` during runtime. matrix_dendrite_role_executed: false -matrix_dendrite_media_store_parent_path: "{{ matrix_dendrite_media_store_path|dirname }}" -matrix_dendrite_media_store_directory_name: "{{ matrix_dendrite_media_store_path|basename }}" +matrix_dendrite_media_store_parent_path: "{{ matrix_dendrite_media_store_path | dirname }}" +matrix_dendrite_media_store_directory_name: "{{ matrix_dendrite_media_store_path | basename }}" -matrix_dendrite_signing_key_file_name: "{{ matrix_dendrite_signing_key|basename }}" +matrix_dendrite_signing_key_file_name: "{{ matrix_dendrite_signing_key | basename }}" diff --git a/roles/matrix-dimension/defaults/main.yml b/roles/matrix-dimension/defaults/main.yml index c4da906d..ea1dde10 100644 --- a/roles/matrix-dimension/defaults/main.yml +++ b/roles/matrix-dimension/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/turt2live/matrix-dimension matrix_dimension_enabled: false @@ -47,7 +48,7 @@ matrix_dimension_integrations_rest_url: "https://{{ matrix_server_fqn_dimension matrix_dimension_integrations_widgets_urls: ["https://{{ matrix_server_fqn_dimension }}/widgets"] matrix_dimension_integrations_jitsi_widget_url: "https://{{ matrix_server_fqn_dimension }}/widgets/jitsi" -matrix_dimension_homeserver_federationUrl: "" +matrix_dimension_homeserver_federationUrl: "" # noqa var-naming # Database-related configuration fields. @@ -92,8 +93,8 @@ matrix_dimension_configuration_extension_yaml: | # botToken: "YourTokenHere" # -matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml|from_yaml if matrix_dimension_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml | from_yaml if matrix_dimension_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final Dimension configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_dimension_configuration_yaml`. -matrix_dimension_configuration: "{{ matrix_dimension_configuration_yaml|from_yaml|combine(matrix_dimension_configuration_extension, recursive=True) }}" +matrix_dimension_configuration: "{{ matrix_dimension_configuration_yaml | from_yaml | combine(matrix_dimension_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-dimension/tasks/init.yml b/roles/matrix-dimension/tasks/init.yml index 6336cb4d..c60a2fe2 100644 --- a/roles/matrix-dimension/tasks/init.yml +++ b/roles/matrix-dimension/tasks/init.yml @@ -1,4 +1,4 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dimension.service'] }}" - when: matrix_dimension_enabled|bool + when: matrix_dimension_enabled | bool diff --git a/roles/matrix-dimension/tasks/main.yml b/roles/matrix-dimension/tasks/main.yml index c2f01399..6eef50d6 100644 --- a/roles/matrix-dimension/tasks/main.yml +++ b/roles/matrix-dimension/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-dimension -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: run_setup|bool and matrix_dimension_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: run_setup | bool and matrix_dimension_enabled | bool tags: - setup-all - setup-dimension -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: run_setup|bool and not matrix_dimension_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: run_setup | bool and not matrix_dimension_enabled | bool tags: - setup-all - setup-dimension diff --git a/roles/matrix-dimension/tasks/setup_install.yml b/roles/matrix-dimension/tasks/setup_install.yml index b999383e..7060285a 100644 --- a/roles/matrix-dimension/tasks/setup_install.yml +++ b/roles/matrix-dimension/tasks/setup_install.yml @@ -1,21 +1,21 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_dimension_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_dimension_sqlite_database_path_local }}" register: matrix_dimension_sqlite_database_path_local_stat_result - block: # pgloader makes a few columns `smallint`, instead of `boolean`. # We need to fix them up. - - set_fact: + - ansible.builtin.set_fact: matrix_dimension_pgloader_additional_psql_statements_list: [] - - set_fact: + - ansible.builtin.set_fact: matrix_dimension_pgloader_additional_psql_statements_list: | {{ matrix_dimension_pgloader_additional_psql_statements_list @@ -49,11 +49,11 @@ - {'table': 'dimension_bridges', 'column': 'isEnabled', 'default': ''} - {'table': 'dimension_bridges', 'column': 'isPublic', 'default': ''} - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_dimension_sqlite_database_path_local }}" dst: "{{ matrix_dimension_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_dimension_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-dimension.service'] @@ -61,15 +61,17 @@ additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}" additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}" - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_dimension_requires_restart: true - when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_dimension_database_engine == 'postgres'" - name: Ensure Dimension base path exists - file: + ansible.builtin.file: path: "{{ matrix_dimension_base_path }}" state: directory mode: 0770 @@ -77,8 +79,8 @@ group: "{{ matrix_dimension_user_gid }}" - name: Ensure Dimension config installed - copy: - content: "{{ matrix_dimension_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_dimension_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_dimension_base_path }}/config.yaml" mode: 0640 owner: "{{ matrix_user_username }}" @@ -90,21 +92,21 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_dimension_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_dimension_docker_image_force_pull }}" - when: "not matrix_dimension_container_image_self_build|bool" + when: "not matrix_dimension_container_image_self_build | bool" register: matrix_dimension_pull_results retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: matrix_dimension_pull_results is not failed - name: Ensure dimension repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_dimension_container_image_self_build_repo }}" dest: "{{ matrix_dimension_docker_src_files_path }}" version: "{{ matrix_dimension_container_image_self_build_branch }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" - when: "matrix_dimension_container_image_self_build|bool" + when: "matrix_dimension_container_image_self_build | bool" register: matrix_dimension_git_pull_results - name: Ensure Dimension Docker image is built @@ -117,22 +119,22 @@ dockerfile: Dockerfile path: "{{ matrix_dimension_docker_src_files_path }}" pull: true - when: "matrix_dimension_container_image_self_build|bool" + when: "matrix_dimension_container_image_self_build | bool" - name: Ensure matrix-dimension.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-dimension.service.j2" dest: "{{ matrix_systemd_path }}/matrix-dimension.service" mode: 0644 register: matrix_dimension_systemd_service_result - name: Ensure systemd reloaded after matrix-dimension.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_dimension_systemd_service_result.changed|bool" + when: "matrix_dimension_systemd_service_result.changed | bool" - name: Ensure matrix-dimension.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-dimension.service" state: restarted - when: "matrix_dimension_requires_restart|bool" + when: "matrix_dimension_requires_restart | bool" diff --git a/roles/matrix-dimension/tasks/setup_uninstall.yml b/roles/matrix-dimension/tasks/setup_uninstall.yml index cdfbe07a..3e2026a1 100644 --- a/roles/matrix-dimension/tasks/setup_uninstall.yml +++ b/roles/matrix-dimension/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-dimension service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-dimension.service" register: matrix_dimension_service_stat - name: Ensure matrix-dimension is stopped - service: + ansible.builtin.service: name: matrix-dimension state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_dimension_service_stat.stat.exists|bool" + when: "matrix_dimension_service_stat.stat.exists | bool" - name: Ensure matrix-dimension.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-dimension.service" state: absent - when: "matrix_dimension_service_stat.stat.exists|bool" + when: "matrix_dimension_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-dimension.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_dimension_service_stat.stat.exists|bool" + when: "matrix_dimension_service_stat.stat.exists | bool" - name: Ensure Dimension base directory doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_dimension_base_path }}" state: absent diff --git a/roles/matrix-dimension/tasks/validate_config.yml b/roles/matrix-dimension/tasks/validate_config.yml index 8413c42f..5af0ba6d 100644 --- a/roles/matrix-dimension/tasks/validate_config.yml +++ b/roles/matrix-dimension/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required Dimension settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Dimension. with_items: @@ -8,7 +8,7 @@ when: "matrix_dimension_enabled and vars[item] == ''" - name: (Deprecation) Catch and report renamed Dimension variables - fail: + 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 }}`). diff --git a/roles/matrix-dimension/templates/config.yaml.j2 b/roles/matrix-dimension/templates/config.yaml.j2 index 39721d71..592c65ac 100644 --- a/roles/matrix-dimension/templates/config.yaml.j2 +++ b/roles/matrix-dimension/templates/config.yaml.j2 @@ -73,13 +73,3 @@ dimension: # This is where Dimension is accessible from clients. Be sure to set this # to your own Dimension instance. publicUrl: "https://{{ matrix_server_fqn_dimension }}" - -# Settings for controlling how logging works -logging: - file: /dev/null - console: true - consoleLevel: verbose - fileLevel: info - rotate: - size: 52428800 # bytes, default is 50mb - count: 5 diff --git a/roles/matrix-dimension/vars/main.yml b/roles/matrix-dimension/vars/main.yml index 131024cc..0415989f 100644 --- a/roles/matrix-dimension/vars/main.yml +++ b/roles/matrix-dimension/vars/main.yml @@ -2,4 +2,4 @@ # Doing `|from_yaml` when the extension contains nothing yields an empty string (""). # We need to ensure it's a dictionary or `|combine` (when building `matrix_dimension_configuration`) will fail later. -matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml|from_yaml if matrix_dimension_configuration_extension_yaml|from_yaml else {} }}" +matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml | from_yaml if matrix_dimension_configuration_extension_yaml | from_yaml else {} }}" diff --git a/roles/matrix-dynamic-dns/defaults/main.yml b/roles/matrix-dynamic-dns/defaults/main.yml index 5d733eb3..2d15db6c 100644 --- a/roles/matrix-dynamic-dns/defaults/main.yml +++ b/roles/matrix-dynamic-dns/defaults/main.yml @@ -1,11 +1,13 @@ --- +# Project source code URL: https://github.com/linuxserver/docker-ddclient + # Whether dynamic dns is enabled matrix_dynamic_dns_enabled: true # The dynamic dns daemon interval matrix_dynamic_dns_daemon_interval: '300' -matrix_dynamic_dns_version: v3.9.1-ls79 +matrix_dynamic_dns_version: v3.9.1-ls94 # The docker container to use when in mode matrix_dynamic_dns_docker_image: "{{ matrix_dynamic_dns_docker_image_name_prefix }}linuxserver/ddclient:{{ matrix_dynamic_dns_version }}" @@ -27,6 +29,7 @@ matrix_dynamic_dns_systemd_required_services_list: ['docker.service'] # Build the container from source when running in mode matrix_dynamic_dns_container_image_self_build: false matrix_dynamic_dns_container_image_self_build_repo: "https://github.com/linuxserver/docker-ddclient.git" +matrix_dynamic_dns_container_image_self_build_repo_branch: "{{ matrix_dynamic_dns_version }}" # Config paths matrix_dynamic_dns_base_path: "{{ matrix_base_data_path }}/dynamic-dns" diff --git a/roles/matrix-dynamic-dns/tasks/init.yml b/roles/matrix-dynamic-dns/tasks/init.yml index 6ea6a60b..9c906441 100644 --- a/roles/matrix-dynamic-dns/tasks/init.yml +++ b/roles/matrix-dynamic-dns/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Dynamic DNS image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_dynamic_dns_container_image_self_build and matrix_dynamic_dns_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dynamic-dns.service'] }}" - when: "matrix_dynamic_dns_enabled|bool" + when: "matrix_dynamic_dns_enabled | bool" diff --git a/roles/matrix-dynamic-dns/tasks/install.yml b/roles/matrix-dynamic-dns/tasks/install.yml index 60f07937..e83637bf 100644 --- a/roles/matrix-dynamic-dns/tasks/install.yml +++ b/roles/matrix-dynamic-dns/tasks/install.yml @@ -6,14 +6,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_dynamic_dns_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_dynamic_dns_docker_image_force_pull }}" - when: matrix_dynamic_dns_enabled|bool and not matrix_dynamic_dns_container_image_self_build + when: matrix_dynamic_dns_enabled | bool and not matrix_dynamic_dns_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Dynamic DNS paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0751 @@ -23,17 +23,18 @@ - {path: "{{ matrix_dynamic_dns_base_path }}", when: true} - {path: "{{ matrix_dynamic_dns_config_path }}", when: true} - {path: "{{ matrix_dynamic_dns_docker_src_files_path }}", when: "{{ matrix_dynamic_dns_container_image_self_build }}"} - when: matrix_dynamic_dns_enabled|bool and item.when|bool + when: matrix_dynamic_dns_enabled | bool and item.when | bool - name: Ensure Dynamic DNS repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_dynamic_dns_container_image_self_build_repo }}" + version: "{{ matrix_dynamic_dns_container_image_self_build_repo_branch }}" dest: "{{ matrix_dynamic_dns_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_dynamic_dns_git_pull_results - when: "matrix_dynamic_dns_enabled|bool and matrix_dynamic_dns_container_image_self_build|bool" + when: "matrix_dynamic_dns_enabled | bool and matrix_dynamic_dns_container_image_self_build | bool" - name: Ensure Dynamic DNS Docker image is built docker_image: @@ -45,10 +46,10 @@ dockerfile: Dockerfile path: "{{ matrix_dynamic_dns_docker_src_files_path }}" pull: true - when: "matrix_dynamic_dns_enabled|bool and matrix_dynamic_dns_container_image_self_build|bool" + when: "matrix_dynamic_dns_enabled | bool and matrix_dynamic_dns_container_image_self_build | bool" - name: Ensure Dynamic DNS ddclient.conf installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/ddclient.conf.j2" dest: "{{ matrix_dynamic_dns_config_path }}/ddclient.conf" mode: 0644 @@ -56,13 +57,13 @@ group: "{{ matrix_user_groupname }}" - name: Ensure matrix-dynamic-dns.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-dynamic-dns.service.j2" dest: "/etc/systemd/system/matrix-dynamic-dns.service" mode: 0644 register: matrix_dynamic_dns_systemd_service_result - name: Ensure systemd reloaded after matrix-dynamic-dns.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_dynamic_dns_systemd_service_result.changed" diff --git a/roles/matrix-dynamic-dns/tasks/main.yml b/roles/matrix-dynamic-dns/tasks/main.yml index 8b8b306c..2f33af86 100644 --- a/roles/matrix-dynamic-dns/tasks/main.yml +++ b/roles/matrix-dynamic-dns/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_dynamic_dns_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_dynamic_dns_enabled | bool" tags: - setup-all - setup-dynamic-dns -- import_tasks: "{{ role_path }}/tasks/install.yml" - when: "run_setup|bool and matrix_dynamic_dns_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/install.yml" + when: "run_setup | bool and matrix_dynamic_dns_enabled | bool" tags: - setup-all - setup-dynamic-dns -- import_tasks: "{{ role_path }}/tasks/uninstall.yml" - when: "run_setup|bool and not matrix_dynamic_dns_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/uninstall.yml" + when: "run_setup | bool and not matrix_dynamic_dns_enabled | bool" tags: - setup-all - setup-dynamic-dns diff --git a/roles/matrix-dynamic-dns/tasks/uninstall.yml b/roles/matrix-dynamic-dns/tasks/uninstall.yml index 80842c9c..5e6b429c 100644 --- a/roles/matrix-dynamic-dns/tasks/uninstall.yml +++ b/roles/matrix-dynamic-dns/tasks/uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-dynamic-dns service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-dynamic-dns.service" register: matrix_dynamic_dns_service_stat - name: Ensure matrix-dynamic-dns is stopped - service: + ansible.builtin.service: name: matrix-dynamic-dns state: stopped enabled: false @@ -14,13 +14,13 @@ when: "matrix_dynamic_dns_service_stat.stat.exists" - name: Ensure matrix-dynamic-dns.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-dynamic-dns.service" state: absent when: "matrix_dynamic_dns_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-dynamic-dns.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_dynamic_dns_service_stat.stat.exists" diff --git a/roles/matrix-dynamic-dns/tasks/validate_config.yml b/roles/matrix-dynamic-dns/tasks/validate_config.yml index 8f0001ea..610dc2f8 100644 --- a/roles/matrix-dynamic-dns/tasks/validate_config.yml +++ b/roles/matrix-dynamic-dns/tasks/validate_config.yml @@ -1,13 +1,13 @@ --- - name: Fail if no configurations specified - fail: + ansible.builtin.fail: msg: >- You need to define at least one configuration in `matrix_dynamic_dns_domain_configurations` for using matrix-dynamic-dns. when: "matrix_dynamic_dns_domain_configurations|length == 0" - name: Fail if required settings not defined in configuration blocks - fail: + ansible.builtin.fail: msg: >- One of the configurations in matrix_dynamic_dns_domain_configurations is missing a required key (domain, provider, protocol). when: "'domain' not in configuration or 'provider' not in configuration or 'protocol' not in configuration" diff --git a/roles/matrix-email2matrix/defaults/main.yml b/roles/matrix-email2matrix/defaults/main.yml index fe5d3399..b24cc76c 100644 --- a/roles/matrix-email2matrix/defaults/main.yml +++ b/roles/matrix-email2matrix/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/devture/email2matrix matrix_email2matrix_enabled: true @@ -10,7 +11,7 @@ matrix_email2matrix_container_image_self_build: false matrix_email2matrix_container_image_self_build_repo: "https://github.com/devture/email2matrix.git" matrix_email2matrix_container_image_self_build_branch: "{{ matrix_email2matrix_version }}" -matrix_email2matrix_version: 1.0.3 +matrix_email2matrix_version: 1.1.0 matrix_email2matrix_docker_image_prefix: "{{ 'localhost/' if matrix_email2matrix_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_email2matrix_docker_image: "{{ matrix_email2matrix_docker_image_prefix }}devture/email2matrix:{{ matrix_email2matrix_version }}" matrix_email2matrix_docker_image_force_pull: "{{ matrix_email2matrix_docker_image.endswith(':latest') }}" diff --git a/roles/matrix-email2matrix/tasks/init.yml b/roles/matrix-email2matrix/tasks/init.yml index 5f582212..02dbc9ee 100644 --- a/roles/matrix-email2matrix/tasks/init.yml +++ b/roles/matrix-email2matrix/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-email2matrix.service'] }}" - when: matrix_email2matrix_enabled|bool + when: matrix_email2matrix_enabled | bool diff --git a/roles/matrix-email2matrix/tasks/main.yml b/roles/matrix-email2matrix/tasks/main.yml index 35bda4fa..3adbc646 100644 --- a/roles/matrix-email2matrix/tasks/main.yml +++ b/roles/matrix-email2matrix/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_email2matrix_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_email2matrix_enabled | bool" tags: - setup-all - setup-email2matrix -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_email2matrix_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_email2matrix_enabled | bool" tags: - setup-all - setup-email2matrix -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_email2matrix_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_email2matrix_enabled | bool" tags: - setup-all - setup-email2matrix diff --git a/roles/matrix-email2matrix/tasks/setup_install.yml b/roles/matrix-email2matrix/tasks/setup_install.yml index a2470728..2a782a1a 100644 --- a/roles/matrix-email2matrix/tasks/setup_install.yml +++ b/roles/matrix-email2matrix/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Email2Matrix paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -11,10 +11,10 @@ - {path: "{{ matrix_email2matrix_base_path }}", when: true} - {path: "{{ matrix_email2matrix_config_dir_path }}", when: true} - {path: "{{ matrix_email2matrix_docker_src_files_path }}", when: "{{ matrix_email2matrix_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Email2Matrix configuration file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/config.json.j2" dest: "{{ matrix_email2matrix_config_dir_path }}/config.json" owner: "{{ matrix_user_username }}" @@ -27,14 +27,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_email2matrix_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_email2matrix_docker_image_force_pull }}" - when: "not matrix_email2matrix_container_image_self_build|bool" + when: "not matrix_email2matrix_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Email2Matrix repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_email2matrix_container_image_self_build_repo }}" dest: "{{ matrix_email2matrix_docker_src_files_path }}" version: "{{ matrix_email2matrix_container_image_self_build_branch }}" @@ -42,7 +42,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_email2matrix_git_pull_results - when: "matrix_email2matrix_container_image_self_build|bool" + when: "matrix_email2matrix_container_image_self_build | bool" - name: Ensure Email2Matrix Docker image is built docker_image: @@ -54,16 +54,16 @@ dockerfile: etc/docker/Dockerfile path: "{{ matrix_email2matrix_docker_src_files_path }}" pull: true - when: "matrix_email2matrix_container_image_self_build|bool" + when: "matrix_email2matrix_container_image_self_build | bool" - name: Ensure matrix-email2matrix.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-email2matrix.service.j2" dest: "{{ matrix_systemd_path }}/matrix-email2matrix.service" mode: 0644 register: matrix_email2matrix_systemd_service_result - name: Ensure systemd reloaded after matrix-email2matrix.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_email2matrix_systemd_service_result.changed|bool" + when: "matrix_email2matrix_systemd_service_result.changed | bool" diff --git a/roles/matrix-email2matrix/tasks/setup_uninstall.yml b/roles/matrix-email2matrix/tasks/setup_uninstall.yml index 27d35f2d..a713a65a 100644 --- a/roles/matrix-email2matrix/tasks/setup_uninstall.yml +++ b/roles/matrix-email2matrix/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-email2matrix service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-email2matrix.service" register: matrix_email2matrix_service_stat - name: Ensure matrix-email2matrix is stopped - service: + ansible.builtin.service: name: matrix-email2matrix state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_email2matrix_service_stat.stat.exists|bool" + when: "matrix_email2matrix_service_stat.stat.exists | bool" - name: Ensure matrix-email2matrix.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-email2matrix.service" state: absent - when: "matrix_email2matrix_service_stat.stat.exists|bool" + when: "matrix_email2matrix_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-email2matrix.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_email2matrix_service_stat.stat.exists|bool" + when: "matrix_email2matrix_service_stat.stat.exists | bool" - name: Ensure Email2Matrix data path doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_email2matrix_base_path }}" state: absent diff --git a/roles/matrix-email2matrix/tasks/validate_config.yml b/roles/matrix-email2matrix/tasks/validate_config.yml index d8beecf4..59a3581e 100644 --- a/roles/matrix-email2matrix/tasks/validate_config.yml +++ b/roles/matrix-email2matrix/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if no mappings - fail: + ansible.builtin.fail: msg: > You need to define at least one mapping in `matrix_email2matrix_matrix_mappings` for enabling Email2Matrix. when: "matrix_email2matrix_matrix_mappings|length == 0" diff --git a/roles/matrix-email2matrix/templates/config.json.j2 b/roles/matrix-email2matrix/templates/config.json.j2 index c1be97fd..a7ca7bc4 100644 --- a/roles/matrix-email2matrix/templates/config.json.j2 +++ b/roles/matrix-email2matrix/templates/config.json.j2 @@ -6,7 +6,7 @@ "Workers": 10 }, "Matrix": { - "Mappings": {{ matrix_email2matrix_matrix_mappings|to_nice_json }} + "Mappings": {{ matrix_email2matrix_matrix_mappings | to_nice_json }} }, "Misc": { "Debug": {{ matrix_email2matrix_misc_debug|to_json }} diff --git a/roles/matrix-etherpad/defaults/main.yml b/roles/matrix-etherpad/defaults/main.yml index 0daf24a3..8281f27f 100644 --- a/roles/matrix-etherpad/defaults/main.yml +++ b/roles/matrix-etherpad/defaults/main.yml @@ -1,10 +1,11 @@ --- +# Project source code URL: https://github.com/ether/etherpad-lite matrix_etherpad_enabled: false matrix_etherpad_base_path: "{{ matrix_base_data_path }}/etherpad" -matrix_etherpad_version: 1.8.16 +matrix_etherpad_version: 1.8.18 matrix_etherpad_docker_image: "{{ matrix_container_global_registry_prefix }}etherpad/etherpad:{{ matrix_etherpad_version }}" matrix_etherpad_docker_image_force_pull: "{{ matrix_etherpad_docker_image.endswith(':latest') }}" @@ -87,8 +88,8 @@ matrix_etherpad_configuration_default: "{{ lookup('template', 'templates/setting # matrix_etherpad_configuration_extension_json: '{}' -matrix_etherpad_configuration_extension: "{{ matrix_etherpad_configuration_extension_json|from_json if matrix_etherpad_configuration_extension_json|from_json is mapping else {} }}" +matrix_etherpad_configuration_extension: "{{ matrix_etherpad_configuration_extension_json | from_json if matrix_etherpad_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Etherpad configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_etherpad_configuration_json`. -matrix_etherpad_configuration: "{{ matrix_etherpad_configuration_default|combine(matrix_etherpad_configuration_extension, recursive=True) }}" +matrix_etherpad_configuration: "{{ matrix_etherpad_configuration_default | combine(matrix_etherpad_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-etherpad/tasks/init.yml b/roles/matrix-etherpad/tasks/init.yml index 392addd0..e16b78dd 100644 --- a/roles/matrix-etherpad/tasks/init.yml +++ b/roles/matrix-etherpad/tasks/init.yml @@ -1,26 +1,26 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-etherpad.service'] }}" - when: matrix_etherpad_enabled|bool + when: matrix_etherpad_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Etherpad's 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-etherpad role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Etherpad proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_etherpad_matrix_nginx_proxy_configuration: | rewrite ^{{ matrix_etherpad_public_endpoint }}$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_etherpad_public_endpoint }}/ permanent; location {{ matrix_etherpad_public_endpoint }}/ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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; proxy_pass http://matrix-etherpad:9001/; @@ -42,23 +42,23 @@ } - name: Register Etherpad proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks | default([]) + [matrix_etherpad_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_etherpad_enabled|bool + when: matrix_etherpad_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Etherpad tool but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_etherpad_public_endpoint }}` URL endpoint to the matrix-etherpad container. You can expose the container's port using the `matrix_etherpad_container_http_host_bind_port` variable. - when: "matrix_etherpad_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_etherpad_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-etherpad/tasks/main.yml b/roles/matrix-etherpad/tasks/main.yml index bf59d838..b1c8ab55 100644 --- a/roles/matrix-etherpad/tasks/main.yml +++ b/roles/matrix-etherpad/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: run_setup|bool and matrix_etherpad_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: run_setup | bool and matrix_etherpad_enabled | bool tags: - setup-all - setup-etherpad -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: run_setup|bool and not matrix_etherpad_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: run_setup | bool and not matrix_etherpad_enabled | bool tags: - setup-all - setup-etherpad -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool and matrix_etherpad_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool and matrix_etherpad_enabled | bool tags: - setup-all - setup-etherpad diff --git a/roles/matrix-etherpad/tasks/setup_install.yml b/roles/matrix-etherpad/tasks/setup_install.yml index 6f276e05..0243e9d7 100644 --- a/roles/matrix-etherpad/tasks/setup_install.yml +++ b/roles/matrix-etherpad/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Etherpad base path exists - file: + ansible.builtin.file: path: "{{ matrix_etherpad_base_path }}" state: directory mode: 0770 @@ -9,8 +9,8 @@ group: "{{ matrix_etherpad_user_gid }}" - name: Ensure Etherpad config installed - copy: - content: "{{ matrix_etherpad_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_etherpad_configuration | to_nice_json }}" dest: "{{ matrix_etherpad_base_path }}/settings.json" mode: 0640 owner: "{{ matrix_etherpad_user_uid }}" @@ -28,13 +28,13 @@ until: result is not failed - name: Ensure matrix-etherpad.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-etherpad.service.j2" dest: "{{ matrix_systemd_path }}/matrix-etherpad.service" mode: 0644 register: matrix_etherpad_systemd_service_result - name: Ensure systemd reloaded after matrix-etherpad.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_etherpad_systemd_service_result.changed|bool" + when: "matrix_etherpad_systemd_service_result.changed | bool" diff --git a/roles/matrix-etherpad/tasks/setup_uninstall.yml b/roles/matrix-etherpad/tasks/setup_uninstall.yml index ae1f2604..38697366 100644 --- a/roles/matrix-etherpad/tasks/setup_uninstall.yml +++ b/roles/matrix-etherpad/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-etherpad service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-etherpad.service" register: matrix_etherpad_service_stat - name: Ensure matrix-etherpad is stopped - service: + ansible.builtin.service: name: matrix-etherpad state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_etherpad_service_stat.stat.exists|bool" + when: "matrix_etherpad_service_stat.stat.exists | bool" - name: Ensure matrix-etherpad.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-etherpad.service" state: absent - when: "matrix_etherpad_service_stat.stat.exists|bool" + when: "matrix_etherpad_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-etherpad.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_etherpad_service_stat.stat.exists|bool" + when: "matrix_etherpad_service_stat.stat.exists | bool" - name: Ensure Etherpad base directory doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_etherpad_base_path }}" state: absent diff --git a/roles/matrix-etherpad/tasks/validate_config.yml b/roles/matrix-etherpad/tasks/validate_config.yml index f9438e7b..bf78c36f 100644 --- a/roles/matrix-etherpad/tasks/validate_config.yml +++ b/roles/matrix-etherpad/tasks/validate_config.yml @@ -1,13 +1,13 @@ --- - name: Fail if Etherpad is enabled without the Dimension integrations manager - fail: + ansible.builtin.fail: msg: >- To integrate Etherpad notes with Matrix rooms you need to set "matrix_dimension_enabled" to true - when: "not matrix_dimension_enabled|bool" + when: "not matrix_dimension_enabled | bool" - name: Fail if no database is configured for Etherpad - fail: + ansible.builtin.fail: msg: >- Etherpad requires a dedicated Postgres database. Please enable the built in one, or configure an external DB by redefining "matrix_etherpad_database_hostname" when: matrix_etherpad_database_hostname == "matrix-postgres" and not matrix_postgres_enabled diff --git a/roles/matrix-grafana/defaults/main.yml b/roles/matrix-grafana/defaults/main.yml index 0ee7a86a..fb166359 100644 --- a/roles/matrix-grafana/defaults/main.yml +++ b/roles/matrix-grafana/defaults/main.yml @@ -1,10 +1,11 @@ --- # matrix-grafana is open source visualization and analytics software # See: https://github.com/matrix-org/synapse/blob/master/docs/metrics-howto.md +# Project source code URL: https://github.com/grafana/grafana matrix_grafana_enabled: false -matrix_grafana_version: 8.4.1 +matrix_grafana_version: 9.0.6 matrix_grafana_docker_image: "{{ matrix_container_global_registry_prefix }}grafana/grafana:{{ matrix_grafana_version }}" matrix_grafana_docker_image_force_pull: "{{ matrix_grafana_docker_image.endswith(':latest') }}" diff --git a/roles/matrix-grafana/tasks/init.yml b/roles/matrix-grafana/tasks/init.yml index 4c2cbf06..7b363ee7 100644 --- a/roles/matrix-grafana/tasks/init.yml +++ b/roles/matrix-grafana/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-grafana.service'] }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool diff --git a/roles/matrix-grafana/tasks/main.yml b/roles/matrix-grafana/tasks/main.yml index c93fd500..34a3f415 100644 --- a/roles/matrix-grafana/tasks/main.yml +++ b/roles/matrix-grafana/tasks/main.yml @@ -1,16 +1,16 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_grafana_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_grafana_enabled | bool" tags: - setup-all - setup-grafana -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-grafana diff --git a/roles/matrix-grafana/tasks/setup.yml b/roles/matrix-grafana/tasks/setup.yml index 95a0ba53..591c0222 100644 --- a/roles/matrix-grafana/tasks/setup.yml +++ b/roles/matrix-grafana/tasks/setup.yml @@ -10,14 +10,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_grafana_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_grafana_docker_image_force_pull }}" - when: "matrix_grafana_enabled|bool" + when: "matrix_grafana_enabled | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure grafana paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -31,37 +31,37 @@ - "{{ matrix_grafana_config_path }}/provisioning/dashboards" - "{{ matrix_grafana_config_path }}/dashboards" - "{{ matrix_grafana_data_path }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure grafana.ini present - template: + ansible.builtin.template: src: "{{ role_path }}/templates/grafana.ini.j2" dest: "{{ matrix_grafana_config_path }}/grafana.ini" mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure provisioning/datasources/default.yaml present - template: + ansible.builtin.template: src: "{{ role_path }}/templates/datasources.yaml.j2" dest: "{{ matrix_grafana_config_path }}/provisioning/datasources/default.yaml" mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure provisioning/dashboards/default.yaml present - template: + ansible.builtin.template: src: "{{ role_path }}/templates/dashboards.yaml.j2" dest: "{{ matrix_grafana_config_path }}/provisioning/dashboards/default.yaml" mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure dashboard(s) downloaded - get_url: + ansible.builtin.get_url: url: "{{ item }}" dest: "{{ matrix_grafana_config_path }}/dashboards/" force: true @@ -69,46 +69,50 @@ owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" with_items: "{{ matrix_grafana_dashboard_download_urls_all }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool + register: result + retries: "{{ matrix_geturl_retries_count }}" + delay: "{{ matrix_geturl_retries_delay }}" + until: result is not failed - name: Ensure matrix-grafana.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-grafana.service.j2" dest: "{{ matrix_systemd_path }}/matrix-grafana.service" mode: 0644 register: matrix_grafana_systemd_service_result - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure systemd reloaded after matrix-grafana.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_grafana_enabled|bool and matrix_grafana_systemd_service_result.changed" + when: "matrix_grafana_enabled | bool and matrix_grafana_systemd_service_result.changed" # # Tasks related to getting rid of matrix-grafana (if it was previously enabled) # - name: Check existence of matrix-grafana service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-grafana.service" register: matrix_grafana_service_stat - name: Ensure matrix-grafana is stopped - service: + ansible.builtin.service: name: matrix-grafana state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_grafana_enabled|bool and matrix_grafana_service_stat.stat.exists" + when: "not matrix_grafana_enabled | bool and matrix_grafana_service_stat.stat.exists" - name: Ensure matrix-grafana.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-grafana.service" state: absent - when: "not matrix_grafana_enabled|bool and matrix_grafana_service_stat.stat.exists" + when: "not matrix_grafana_enabled | bool and matrix_grafana_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-grafana.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_grafana_enabled|bool and matrix_grafana_service_stat.stat.exists" + when: "not matrix_grafana_enabled | bool and matrix_grafana_service_stat.stat.exists" diff --git a/roles/matrix-grafana/tasks/validate_config.yml b/roles/matrix-grafana/tasks/validate_config.yml index 63d4919a..cc48c559 100644 --- a/roles/matrix-grafana/tasks/validate_config.yml +++ b/roles/matrix-grafana/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if Prometheus not enabled - fail: + ansible.builtin.fail: msg: > You need to enable `matrix_prometheus_enabled` to use Prometheus as data source for Grafana. when: "not matrix_prometheus_enabled" diff --git a/roles/matrix-jitsi/defaults/main.yml b/roles/matrix-jitsi/defaults/main.yml index c3268267..2bec0247 100644 --- a/roles/matrix-jitsi/defaults/main.yml +++ b/roles/matrix-jitsi/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/jitsi/docker-jitsi-meet matrix_jitsi_enabled: true @@ -70,7 +71,7 @@ matrix_jitsi_jibri_recorder_password: '' matrix_jitsi_enable_lobby: false -matrix_jitsi_version: stable-7001 +matrix_jitsi_version: stable-7577 matrix_jitsi_container_image_tag: "{{ matrix_jitsi_version }}" # for backward-compatibility matrix_jitsi_web_docker_image: "{{ matrix_container_global_registry_prefix }}jitsi/web:{{ matrix_jitsi_container_image_tag }}" @@ -131,7 +132,7 @@ matrix_jitsi_web_config_start_audio_muted_after_nth_participant: ~ # Controls after which participant video will be muted. If not specified, defaults to Jitsi's default value (likely 10) matrix_jitsi_web_config_start_video_muted_after_nth_participant: ~ -matrix_jitsi_web_config_defaultLanguage: 'en' +matrix_jitsi_web_config_defaultLanguage: 'en' # noqa var-naming # Ideal and also maximum resolution width. If not specified, defaults to Jitsi's default value (likely 1280) matrix_jitsi_web_config_resolution_width_ideal_and_max: ~ diff --git a/roles/matrix-jitsi/tasks/init.yml b/roles/matrix-jitsi/tasks/init.yml index efab8745..8606c4b3 100644 --- a/roles/matrix-jitsi/tasks/init.yml +++ b/roles/matrix-jitsi/tasks/init.yml @@ -1,5 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-jitsi-web.service', 'matrix-jitsi-prosody.service', 'matrix-jitsi-jicofo.service', 'matrix-jitsi-jvb.service'] }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool + +- name: Fail if on an unsupported architecture + ansible.builtin.fail: + msg: "Jitsi only supports the amd64 architecture right now. See https://github.com/jitsi/docker-jitsi-meet/issues/1069 and https://github.com/jitsi/docker-jitsi-meet/issues/1214" + when: matrix_jitsi_enabled | bool and matrix_architecture not in ['amd64', 'arm64'] diff --git a/roles/matrix-jitsi/tasks/main.yml b/roles/matrix-jitsi/tasks/main.yml index fe9da205..7da6ebf9 100644 --- a/roles/matrix-jitsi/tasks/main.yml +++ b/roles/matrix-jitsi/tasks/main.yml @@ -1,41 +1,41 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_jitsi_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_jitsi_enabled | bool" tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_base.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_base.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_web.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_web.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_prosody.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_prosody.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_jicofo.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_jicofo.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_jvb.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_jvb.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_base.yml b/roles/matrix-jitsi/tasks/setup_jitsi_base.yml index 4b390c18..a91949e1 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_base.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_base.yml @@ -1,13 +1,13 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" # # Tasks related to setting up jitsi # - name: Ensure Matrix jitsi base path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -15,7 +15,7 @@ group: "{{ matrix_user_groupname }}" with_items: - {path: "{{ matrix_jitsi_base_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when # # Tasks related to getting rid of jitsi (if it was previously enabled) diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml b/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml index 0cb7043f..8b2ec6a7 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-jicofo path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -14,7 +14,7 @@ with_items: - {path: "{{ matrix_jitsi_jicofo_base_path }}", when: true} - {path: "{{ matrix_jitsi_jicofo_config_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-jicofo Docker image is pulled docker_image: @@ -22,23 +22,23 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_jicofo_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_jitsi_jicofo_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-jicofo environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jicofo/env.j2" dest: "{{ matrix_jitsi_jicofo_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure jitsi-jicofo configuration files created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jicofo/{{ item }}.j2" dest: "{{ matrix_jitsi_jicofo_config_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -47,18 +47,18 @@ with_items: - sip-communicator.properties - logging.properties - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-jicofo.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jicofo/matrix-jitsi-jicofo.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-jicofo.service" mode: 0644 register: matrix_jitsi_jicofo_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd reloaded after matrix-jitsi-jicofo.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_jicofo_systemd_service_result.changed" @@ -67,36 +67,36 @@ # - name: Check existence of matrix-jitsi-jicofo service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-jicofo.service" register: matrix_jitsi_jicofo_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-jicofo is stopped - service: + ansible.builtin.service: name: matrix-jitsi-jicofo state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jicofo_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jicofo_service_stat.stat.exists" - name: Ensure matrix-jitsi-jicofo.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-jicofo.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jicofo_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jicofo_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-jitsi-jicofo.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jicofo_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jicofo_service_stat.stat.exists" - name: Ensure Matrix jitsi-jicofo paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_jicofo_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml b/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml index 90bf4a69..cdb94ebd 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-jvb path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -14,7 +14,7 @@ with_items: - {path: "{{ matrix_jitsi_jvb_base_path }}", when: true} - {path: "{{ matrix_jitsi_jvb_config_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-jvb Docker image is pulled docker_image: @@ -22,14 +22,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_jvb_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_jitsi_jvb_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-jvb configuration files created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jvb/{{ item }}.j2" dest: "{{ matrix_jitsi_jvb_config_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -38,27 +38,27 @@ with_items: - custom-sip-communicator.properties - logging.properties - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure jitsi-jvb environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jvb/env.j2" dest: "{{ matrix_jitsi_jvb_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-jvb.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jvb/matrix-jitsi-jvb.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-jvb.service" mode: 0644 register: matrix_jitsi_jvb_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd reloaded after matrix-jitsi-jvb.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_jvb_systemd_service_result.changed" @@ -67,36 +67,36 @@ # - name: Check existence of matrix-jitsi-jvb service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-jvb.service" register: matrix_jitsi_jvb_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-jvb is stopped - service: + ansible.builtin.service: name: matrix-jitsi-jvb state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jvb_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jvb_service_stat.stat.exists" - name: Ensure matrix-jitsi-jvb.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-jvb.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jvb_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jvb_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-jitsi-jvb.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jvb_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jvb_service_stat.stat.exists" - name: Ensure Matrix jitsi-jvb paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_jvb_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml b/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml index 6db954b8..9383b48b 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-prosody environment exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -15,7 +15,7 @@ - {path: "{{ matrix_jitsi_prosody_base_path }}", when: true} - {path: "{{ matrix_jitsi_prosody_config_path }}", when: true} - {path: "{{ matrix_jitsi_prosody_plugins_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-prosody Docker image is pulled docker_image: @@ -23,40 +23,40 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_prosody_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_jitsi_prosody_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-prosody environment variables file is created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/prosody/env.j2" dest: "{{ matrix_jitsi_prosody_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-prosody.service file is installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/prosody/matrix-jitsi-prosody.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-prosody.service" mode: 0644 register: matrix_jitsi_prosody_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd service is reloaded after matrix-jitsi-prosody.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_prosody_systemd_service_result.changed" - name: Ensure authentication is properly configured - include_tasks: + ansible.builtin.include_tasks: file: "{{ role_path }}/tasks/util/setup_jitsi_auth.yml" when: - - matrix_jitsi_enabled|bool - - matrix_jitsi_enable_auth|bool + - matrix_jitsi_enabled | bool + - matrix_jitsi_enable_auth | bool # @@ -64,36 +64,36 @@ # - name: Ensure matrix-jitsi-prosody.service file exists - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-prosody.service" register: matrix_jitsi_prosody_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-prosody is stopped - service: + ansible.builtin.service: name: matrix-jitsi-prosody state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_prosody_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_prosody_service_stat.stat.exists" - name: Ensure matrix-jitsi-prosody.service file doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-prosody.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_prosody_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_prosody_service_stat.stat.exists" - name: Ensure systemd is reloaded after matrix-jitsi-prosody.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_prosody_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_prosody_service_stat.stat.exists" - name: Ensure Matrix jitsi-prosody paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_prosody_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_web.yml b/roles/matrix-jitsi/tasks/setup_jitsi_web.yml index feda4ace..1c7daa4b 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_web.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_web.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-web path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -16,7 +16,7 @@ - {path: "{{ matrix_jitsi_web_config_path }}", when: true} - {path: "{{ matrix_jitsi_web_transcripts_path }}", when: true} - {path: "{{ matrix_jitsi_web_crontabs_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-web Docker image is pulled docker_image: @@ -24,23 +24,23 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_web_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_jitsi_web_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-web environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/web/env.j2" dest: "{{ matrix_jitsi_web_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure jitsi-web configuration files created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/web/{{ item }}.j2" dest: "{{ matrix_jitsi_web_config_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -49,18 +49,18 @@ with_items: - custom-config.js - custom-interface_config.js - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-web.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/web/matrix-jitsi-web.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-web.service" mode: 0644 register: matrix_jitsi_web_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd reloaded after matrix-jitsi-web.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_web_systemd_service_result.changed" @@ -69,36 +69,36 @@ # - name: Check existence of matrix-jitsi-web service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-web.service" register: matrix_jitsi_web_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-web is stopped - service: + ansible.builtin.service: name: matrix-jitsi-web state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_web_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_web_service_stat.stat.exists" - name: Ensure matrix-jitsi-web.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-web.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_web_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_web_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-jitsi-web.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_web_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_web_service_stat.stat.exists" - name: Ensure Matrix jitsi-web paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_web_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml b/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml index 50973acb..d9da9ebe 100644 --- a/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml +++ b/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml @@ -4,7 +4,7 @@ # - name: Ensure matrix-jitsi-prosody container is running - systemd: + ansible.builtin.systemd: state: started name: matrix-jitsi-prosody register: matrix_jitsi_prosody_start_result @@ -15,11 +15,13 @@ # - name: Ensure Jitsi internal authentication users are configured - shell: "docker exec matrix-jitsi-prosody prosodyctl --config /config/prosody.cfg.lua register {{ item.username | quote }} meet.jitsi {{ item.password | quote }}" + ansible.builtin.shell: "{{ matrix_host_command_docker }} exec matrix-jitsi-prosody prosodyctl --config /config/prosody.cfg.lua register {{ item.username | quote }} meet.jitsi {{ item.password | quote }}" with_items: "{{ matrix_jitsi_prosody_auth_internal_accounts }}" when: - matrix_jitsi_auth_type == "internal" - matrix_jitsi_prosody_auth_internal_accounts|length > 0 + register: matrix_jitsi_user_configuration_result + changed_when: matrix_jitsi_user_configuration_result.rc == 0 # # Tasks related to configuring other Jitsi authentication mechanisms @@ -33,7 +35,7 @@ # Stop Necessary Services # - name: Ensure matrix-jitsi-prosody container is stopped if necessary - systemd: + ansible.builtin.systemd: state: stopped name: matrix-jitsi-prosody - when: matrix_jitsi_prosody_start_result.changed|bool + when: matrix_jitsi_prosody_start_result.changed | bool diff --git a/roles/matrix-jitsi/tasks/validate_config.yml b/roles/matrix-jitsi/tasks/validate_config.yml index 5131396d..df87b758 100644 --- a/roles/matrix-jitsi/tasks/validate_config.yml +++ b/roles/matrix-jitsi/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Jitsi settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to properly configure Jitsi. @@ -21,19 +21,19 @@ - name: Fail if a Jitsi internal authentication account is not defined - fail: + ansible.builtin.fail: msg: >- At least one Jitsi user needs to be defined in `matrix_jitsi_prosody_auth_internal_accounts` when using internal authentication. If you're setting up Jitsi for the first time, you may have missed a step. Refer to our setup instructions (docs/configuring-playbook-jitsi.md). when: - - matrix_jitsi_enable_auth|bool + - matrix_jitsi_enable_auth | bool - matrix_jitsi_auth_type == 'internal' - matrix_jitsi_prosody_auth_internal_accounts|length == 0 - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). diff --git a/roles/matrix-ma1sd/defaults/main.yml b/roles/matrix-ma1sd/defaults/main.yml index f1d57049..3755a46a 100644 --- a/roles/matrix-ma1sd/defaults/main.yml +++ b/roles/matrix-ma1sd/defaults/main.yml @@ -1,6 +1,6 @@ --- # ma1sd is a Federated Matrix Identity Server -# See: https://github.com/ma1uta/ma1sd +# Project source code URL: https://github.com/ma1uta/ma1sd matrix_ma1sd_enabled: true @@ -93,9 +93,9 @@ matrix_ma1sd_dns_overwrite_homeserver_client_value: "" # https://github.com/ma1uta/ma1sd/blob/master/docs/threepids/session/session-views.md matrix_ma1sd_view_session_custom_templates_enabled: false # Defaults to: https://github.com/ma1uta/ma1sd/blob/master/src/main/resources/templates/session/tokenSubmitSuccess.html -matrix_ma1sd_view_session_custom_onTokenSubmit_success_template: "" +matrix_ma1sd_view_session_custom_onTokenSubmit_success_template: "" # noqa var-naming # Defaults to: https://github.com/ma1uta/ma1sd/blob/master/src/main/resources/templates/session/tokenSubmitFailure.html -matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template: "" +matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template: "" # noqa var-naming # Override the default email templates # To use this, fill in the template variables with the full desired template as a multi-line YAML variable @@ -156,8 +156,8 @@ matrix_ma1sd_configuration_extension_yaml: | # bindDn: CN=My Ma1sd User,OU=Users,DC=example,DC=org # bindPassword: TheUserPassword -matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml|from_yaml if matrix_ma1sd_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml | from_yaml if matrix_ma1sd_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final ma1sd configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_ma1sd_configuration_yaml`. -matrix_ma1sd_configuration: "{{ matrix_ma1sd_configuration_yaml|from_yaml|combine(matrix_ma1sd_configuration_extension, recursive=True) }}" +matrix_ma1sd_configuration: "{{ matrix_ma1sd_configuration_yaml | from_yaml | combine(matrix_ma1sd_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-ma1sd/tasks/init.yml b/roles/matrix-ma1sd/tasks/init.yml index a7c914db..48226aa0 100644 --- a/roles/matrix-ma1sd/tasks/init.yml +++ b/roles/matrix-ma1sd/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" - when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_ma1sd_container_image_self_build and matrix_ma1sd_enabled|bool" + ansible.builtin.fail: + msg: "To self-build the ma1sd image, you should use Ansible 2.8 or higher. See docs/ansible.md" + when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_ma1sd_container_image_self_build and matrix_ma1sd_enabled | bool" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ma1sd.service'] }}" - when: matrix_ma1sd_enabled|bool + when: matrix_ma1sd_enabled | bool diff --git a/roles/matrix-ma1sd/tasks/main.yml b/roles/matrix-ma1sd/tasks/main.yml index 2902c05d..f55e7891 100644 --- a/roles/matrix-ma1sd/tasks/main.yml +++ b/roles/matrix-ma1sd/tasks/main.yml @@ -1,30 +1,30 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_ma1sd_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_ma1sd_enabled | bool" tags: - setup-all - setup-ma1sd -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_ma1sd_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_ma1sd_enabled | bool" tags: - setup-all - setup-ma1sd -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_ma1sd_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_ma1sd_enabled | bool" tags: - setup-all - setup-ma1sd -- import_tasks: "{{ role_path }}/tasks/self_check_ma1sd.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_ma1sd.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_ma1sd_enabled|bool" + when: "run_self_check | bool and matrix_ma1sd_enabled | bool" tags: - self-check diff --git a/roles/matrix-ma1sd/tasks/migrate_mxisd.yml b/roles/matrix-ma1sd/tasks/migrate_mxisd.yml index 720afa76..7457001c 100644 --- a/roles/matrix-ma1sd/tasks/migrate_mxisd.yml +++ b/roles/matrix-ma1sd/tasks/migrate_mxisd.yml @@ -3,24 +3,24 @@ # This task is for migrating existing mxisd data when transitioning to the ma1sd fork. - name: Check for existent mxisd data - stat: + ansible.builtin.stat: path: "{{ matrix_base_data_path }}/mxisd/data" register: ma1sd_migrate_mxisd_data_dir_stat - name: Warn if mxisd data detected - debug: + ansible.builtin.debug: msg: > You seem to have an existing mxisd folder in `{{ matrix_base_data_path }}/mxisd`. We are going to migrate it to ma1sd and rename the folder to mxisd.migrated. when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists" - name: Check existence of old matrix-mxisd service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mxisd.service" register: matrix_mxisd_service_stat - name: Ensure matrix-mxisd is stopped - service: + ansible.builtin.service: name: matrix-mxisd state: stopped enabled: false @@ -28,13 +28,13 @@ when: "matrix_mxisd_service_stat.stat.exists" - name: Check existence of matrix-ma1sd service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-ma1sd.service" register: matrix_ma1sd_service_stat when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists" - name: Ensure matrix-ma1sd is stopped - service: + ansible.builtin.service: name: matrix-ma1sd state: stopped daemon_reload: true @@ -44,28 +44,37 @@ # recursively copy remote directories (like `/matrix/mxisd/data/sign.key`) in older versions of Ansible. - block: - name: Copy mxisd data files to ma1sd folder - command: "cp -ar {{ matrix_base_data_path }}/mxisd/data {{ matrix_ma1sd_base_path }}" + ansible.builtin.command: + cmd: "cp -ar {{ matrix_base_data_path }}/mxisd/data {{ matrix_ma1sd_base_path }}" + register: matrix_ma1sd_migrate_mxisd_data_files_copying_result + changed_when: matrix_ma1sd_migrate_mxisd_data_files_copying_result.rc == 0 - name: Check existence of mxisd.db file - stat: + ansible.builtin.stat: path: "{{ matrix_ma1sd_data_path }}/mxisd.db" register: matrix_ma1sd_mxisd_db_stat - name: Rename database (mxisd.db -> ma1sd.db) - command: "mv {{ matrix_ma1sd_data_path }}/mxisd.db {{ matrix_ma1sd_data_path }}/ma1sd.db" + ansible.builtin.command: + cmd: "mv {{ matrix_ma1sd_data_path }}/mxisd.db {{ matrix_ma1sd_data_path }}/ma1sd.db" + register: matrix_ma1sd_migrate_mxisd_move_db_result + changed_when: matrix_ma1sd_migrate_mxisd_move_db_result.rc == 0 when: "matrix_ma1sd_mxisd_db_stat.stat.exists" - name: Rename mxisd folder - command: "mv {{ matrix_base_data_path }}/mxisd {{ matrix_base_data_path }}/mxisd.migrated" + ansible.builtin.command: + cmd: "mv {{ matrix_base_data_path }}/mxisd {{ matrix_base_data_path }}/mxisd.migrated" + register: matrix_ma1sd_migrate_mxisd_move_directory_result + changed_when: matrix_ma1sd_migrate_mxisd_move_directory_result.rc == 0 when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists" - name: Ensure outdated matrix-mxisd.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mxisd.service" state: absent when: "matrix_mxisd_service_stat.stat.exists" - name: Ensure systemd reloaded after removing outdated matrix-mxisd.service - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mxisd_service_stat.stat.exists" diff --git a/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml b/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml index 4a4c7136..6fde9dd2 100644 --- a/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml +++ b/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: ma1sd_url_endpoint_public: "https://{{ matrix_server_fqn_matrix }}/_matrix/identity/api/v1" - name: Check ma1sd Identity Service - uri: + ansible.builtin.uri: url: "{{ ma1sd_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_ma1sd_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if ma1sd Identity Service not working - fail: + ansible.builtin.fail: msg: "Failed checking ma1sd is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ ma1sd_url_endpoint_public }}`). Is ma1sd running? Is port 443 open in your firewall? Full error: {{ result_ma1sd }}" when: "result_ma1sd.failed or 'json' not in result_ma1sd" - name: Report working ma1sd Identity Service - debug: + ansible.builtin.debug: msg: "ma1sd at `{{ matrix_server_fqn_matrix }}` is working (checked endpoint: `{{ ma1sd_url_endpoint_public }}`)" diff --git a/roles/matrix-ma1sd/tasks/setup_install.yml b/roles/matrix-ma1sd/tasks/setup_install.yml index e3347a4d..ef32288f 100644 --- a/roles/matrix-ma1sd/tasks/setup_install.yml +++ b/roles/matrix-ma1sd/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure ma1sd paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -11,38 +11,40 @@ - {path: "{{ matrix_ma1sd_config_path }}", when: true} - {path: "{{ matrix_ma1sd_data_path }}", when: true} - {path: "{{ matrix_ma1sd_docker_src_files_path }}", when: "{{ matrix_ma1sd_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" -- import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml" # These (SQLite -> Postgres) migration tasks are usually at the top, # but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist. -- set_fact: +- ansible.builtin.set_fact: matrix_ma1sd_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_ma1sd_sqlite_database_path_local }}" register: matrix_ma1sd_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_ma1sd_sqlite_database_path_local }}" dst: "{{ matrix_ma1sd_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_ma1sd_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-ma1sd.service'] pgloader_options: ['--with "quote identifiers"'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_ma1sd_requires_restart: true - when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_ma1sd_database_engine == 'postgres'" - name: Ensure ma1sd image is pulled @@ -51,7 +53,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_ma1sd_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_ma1sd_docker_image_force_pull }}" - when: "not matrix_ma1sd_container_image_self_build|bool" + when: "not matrix_ma1sd_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -59,7 +61,7 @@ - block: - name: Ensure gradle is installed for self-building (Debian) - apt: + ansible.builtin.apt: name: - gradle state: present @@ -67,7 +69,7 @@ when: (ansible_os_family == 'Debian') - name: Ensure gradle is installed for self-building (RedHat) - fail: + ansible.builtin.fail: msg: "Installing gradle on RedHat ({{ ansible_distribution }}) is currently not supported, so self-building ma1sd cannot happen at this time" when: ansible_os_family == 'RedHat' @@ -75,12 +77,12 @@ pacman: name: - gradle - state: latest + state: present update_cache: true when: ansible_distribution == 'Archlinux' - name: Ensure ma1sd repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_ma1sd_container_image_self_build_repo }}" dest: "{{ matrix_ma1sd_docker_src_files_path }}" version: "{{ matrix_ma1sd_container_image_self_build_branch }}" @@ -90,9 +92,11 @@ register: matrix_ma1sd_git_pull_results - name: Ensure ma1sd Docker image is built - shell: "DOCKER_BUILDKIT=1 ./gradlew dockerBuild" - args: + ansible.builtin.command: + cmd: ./gradlew dockerBuild chdir: "{{ matrix_ma1sd_docker_src_files_path }}" + environment: + DOCKER_BUILDKIT: 1 when: matrix_ma1sd_git_pull_results.changed - name: Ensure ma1sd Docker image is tagged correctly @@ -107,18 +111,18 @@ repository: "{{ matrix_ma1sd_docker_image }}" force_tag: true source: local - when: "matrix_ma1sd_container_image_self_build|bool" + when: "matrix_ma1sd_container_image_self_build | bool" - name: Ensure ma1sd config installed - copy: - content: "{{ matrix_ma1sd_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_ma1sd_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure custom view templates are installed, if any - copy: + ansible.builtin.copy: content: "{{ item.value }}" dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}" mode: 0644 @@ -127,10 +131,10 @@ with_items: - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'} - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'} - when: "matrix_ma1sd_view_session_custom_templates_enabled|bool and item.value" + when: "matrix_ma1sd_view_session_custom_templates_enabled | bool and item.value" - name: Ensure custom email templates are installed, if any - copy: + ansible.builtin.copy: content: "{{ item.value }}" dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}" mode: 0644 @@ -141,11 +145,11 @@ - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'} - when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value" + when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value" # Only cleaning up for people who define the respective templates - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/) - file: + ansible.builtin.file: path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}" state: absent with_items: @@ -153,22 +157,22 @@ - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'} - when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value" + when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value" - name: Ensure matrix-ma1sd.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2" dest: "{{ matrix_systemd_path }}/matrix-ma1sd.service" mode: 0644 register: matrix_ma1sd_systemd_service_result - name: Ensure systemd reloaded after matrix-ma1sd.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_ma1sd_systemd_service_result.changed|bool" + when: "matrix_ma1sd_systemd_service_result.changed | bool" - name: Ensure matrix-ma1sd.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-ma1sd.service" state: restarted - when: "matrix_ma1sd_requires_restart|bool" + when: "matrix_ma1sd_requires_restart | bool" diff --git a/roles/matrix-ma1sd/tasks/setup_uninstall.yml b/roles/matrix-ma1sd/tasks/setup_uninstall.yml index 30a1bfda..2bc505b0 100644 --- a/roles/matrix-ma1sd/tasks/setup_uninstall.yml +++ b/roles/matrix-ma1sd/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-ma1sd service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-ma1sd.service" register: matrix_ma1sd_service_stat - name: Ensure matrix-ma1sd is stopped - service: + ansible.builtin.service: name: matrix-ma1sd state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_ma1sd_service_stat.stat.exists|bool" + when: "matrix_ma1sd_service_stat.stat.exists | bool" - name: Ensure matrix-ma1sd.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-ma1sd.service" state: absent - when: "matrix_ma1sd_service_stat.stat.exists|bool" + when: "matrix_ma1sd_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-ma1sd.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_ma1sd_service_stat.stat.exists|bool" + when: "matrix_ma1sd_service_stat.stat.exists | bool" - name: Ensure Matrix ma1sd paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_ma1sd_base_path }}" state: absent diff --git a/roles/matrix-ma1sd/tasks/validate_config.yml b/roles/matrix-ma1sd/tasks/validate_config.yml index 5f621fca..af12dd3f 100644 --- a/roles/matrix-ma1sd/tasks/validate_config.yml +++ b/roles/matrix-ma1sd/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Warn about ma1sd variables that are not used anymore - fail: + ansible.builtin.fail: msg: > The `{{ item }}` variable defined in your configuration is not used by this playbook anymore! You'll need to adapt to the new way of extending ma1sd configuration. @@ -31,7 +31,7 @@ - 'matrix_ma1sd_architecture' - name: Ensure ma1sd configuration does not contain any dot-notation keys - fail: + ansible.builtin.fail: msg: > Since version 1.3.0, ma1sd will not accept property-style configuration keys. You have defined a key (`{{ item.key }}`) which contains a dot. @@ -40,7 +40,7 @@ with_dict: "{{ matrix_ma1sd_configuration }}" - name: Fail if required ma1sd settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) for using ma1sd. when: "vars[item] == ''" @@ -49,7 +49,7 @@ - "matrix_ma1sd_dns_overwrite_homeserver_client_value" - name: (Deprecation) Catch and report renamed ma1sd variables - fail: + 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 }}`). @@ -60,7 +60,7 @@ - {'old': 'matrix_ma1sd_default_port', 'new': 'matrix_ma1sd_container_port'} - name: (Deprecation) Catch and report mxisd variables - fail: + ansible.builtin.fail: msg: >- mxisd is deprecated and has been replaced with ma1sd (https://github.com/ma1uta/ma1sd), a compatible fork. The playbook will migrate your existing mxisd configuration and data automatically, but you need to adjust variable names. diff --git a/roles/matrix-ma1sd/vars/main.yml b/roles/matrix-ma1sd/vars/main.yml index b6c97a59..3adc735e 100644 --- a/roles/matrix-ma1sd/vars/main.yml +++ b/roles/matrix-ma1sd/vars/main.yml @@ -2,4 +2,4 @@ # Doing `|from_yaml` when the extension contains nothing yields an empty string (""). # We need to ensure it's a dictionary or `|combine` (when building `matrix_ma1sd_configuration`) will fail later. -matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml|from_yaml if matrix_ma1sd_configuration_extension_yaml|from_yaml else {} }}" +matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml | from_yaml if matrix_ma1sd_configuration_extension_yaml | from_yaml else {} }}" diff --git a/roles/matrix-mailer/defaults/main.yml b/roles/matrix-mailer/defaults/main.yml index 682126d2..48cd638c 100644 --- a/roles/matrix-mailer/defaults/main.yml +++ b/roles/matrix-mailer/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/devture/exim-relay matrix_mailer_enabled: true @@ -9,7 +10,7 @@ matrix_mailer_container_image_self_build_repository_url: "https://github.com/dev matrix_mailer_container_image_self_build_src_files_path: "{{ matrix_mailer_base_path }}/docker-src" matrix_mailer_container_image_self_build_version: "{{ matrix_mailer_docker_image.split(':')[1] }}" -matrix_mailer_version: 4.95-r0-2 +matrix_mailer_version: 4.95-r0-4 matrix_mailer_docker_image: "{{ matrix_mailer_docker_image_name_prefix }}devture/exim-relay:{{ matrix_mailer_version }}" matrix_mailer_docker_image_name_prefix: "{{ 'localhost/' if matrix_mailer_container_image_self_build else matrix_container_global_registry_prefix }}" matrix_mailer_docker_image_force_pull: "{{ matrix_mailer_docker_image.endswith(':latest') }}" diff --git a/roles/matrix-mailer/tasks/init.yml b/roles/matrix-mailer/tasks/init.yml index c928d557..487ed0c9 100644 --- a/roles/matrix-mailer/tasks/init.yml +++ b/roles/matrix-mailer/tasks/init.yml @@ -2,10 +2,10 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Matrix Mailer image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_mailer_container_image_self_build and matrix_mailer_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mailer.service'] }}" - when: matrix_mailer_enabled|bool + when: matrix_mailer_enabled | bool diff --git a/roles/matrix-mailer/tasks/main.yml b/roles/matrix-mailer/tasks/main.yml index c69dad20..e49ff26d 100644 --- a/roles/matrix-mailer/tasks/main.yml +++ b/roles/matrix-mailer/tasks/main.yml @@ -1,11 +1,11 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_mailer.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_mailer.yml" + when: run_setup | bool tags: - setup-all - setup-mailer diff --git a/roles/matrix-mailer/tasks/setup_mailer.yml b/roles/matrix-mailer/tasks/setup_mailer.yml index d2f8f917..2ab39df5 100644 --- a/roles/matrix-mailer/tasks/setup_mailer.yml +++ b/roles/matrix-mailer/tasks/setup_mailer.yml @@ -5,7 +5,7 @@ # - name: Ensure mailer base path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,17 +14,17 @@ with_items: - {path: "{{ matrix_mailer_base_path }}", when: true} - {path: "{{ matrix_mailer_container_image_self_build_src_files_path }}", when: "{{ matrix_mailer_container_image_self_build }}"} - when: "matrix_mailer_enabled|bool and item.when" + when: "matrix_mailer_enabled | bool and item.when" - name: Ensure mailer environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/env-mailer.j2" dest: "{{ matrix_mailer_base_path }}/env-mailer" mode: 0640 - when: matrix_mailer_enabled|bool + when: matrix_mailer_enabled | bool - name: Ensure exim-relay repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mailer_container_image_self_build_repository_url }}" dest: "{{ matrix_mailer_container_image_self_build_src_files_path }}" version: "{{ matrix_mailer_container_image_self_build_version }}" @@ -32,7 +32,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mailer_git_pull_results - when: "matrix_mailer_enabled|bool and matrix_mailer_container_image_self_build|bool" + when: "matrix_mailer_enabled | bool and matrix_mailer_container_image_self_build | bool" - name: Ensure exim-relay Docker image is built docker_image: @@ -44,7 +44,7 @@ dockerfile: Dockerfile path: "{{ matrix_mailer_container_image_self_build_src_files_path }}" pull: true - when: "matrix_mailer_enabled|bool and matrix_mailer_container_image_self_build|bool" + when: "matrix_mailer_enabled | bool and matrix_mailer_container_image_self_build | bool" - name: Ensure exim-relay image is pulled docker_image: @@ -52,63 +52,63 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mailer_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_mailer_docker_image_force_pull }}" - when: "matrix_mailer_enabled|bool and not matrix_mailer_container_image_self_build|bool" + when: "matrix_mailer_enabled | bool and not matrix_mailer_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-mailer.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mailer.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mailer.service" mode: 0644 register: matrix_mailer_systemd_service_result - when: matrix_mailer_enabled|bool + when: matrix_mailer_enabled | bool - name: Ensure systemd reloaded after matrix-mailer.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_mailer_enabled|bool and matrix_mailer_systemd_service_result.changed" + when: "matrix_mailer_enabled | bool and matrix_mailer_systemd_service_result.changed" # # Tasks related to getting rid of the mailer (if it was previously enabled) # - name: Check existence of matrix-mailer service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mailer.service" register: matrix_mailer_service_stat - when: "not matrix_mailer_enabled|bool" + when: "not matrix_mailer_enabled | bool" - name: Ensure matrix-mailer is stopped - service: + ansible.builtin.service: name: matrix-mailer state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_mailer_enabled|bool and matrix_mailer_service_stat.stat.exists" + when: "not matrix_mailer_enabled | bool and matrix_mailer_service_stat.stat.exists" - name: Ensure matrix-mailer.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mailer.service" state: absent - when: "not matrix_mailer_enabled|bool and matrix_mailer_service_stat.stat.exists" + when: "not matrix_mailer_enabled | bool and matrix_mailer_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mailer.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_mailer_enabled|bool and matrix_mailer_service_stat.stat.exists" + when: "not matrix_mailer_enabled | bool and matrix_mailer_service_stat.stat.exists" - name: Ensure Matrix mailer environment variables path doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_mailer_base_path }}" state: absent - when: "not matrix_mailer_enabled|bool" + when: "not matrix_mailer_enabled | bool" - name: Ensure mailer Docker image doesn't exist docker_image: name: "{{ matrix_mailer_docker_image }}" state: absent - when: "not matrix_mailer_enabled|bool" + when: "not matrix_mailer_enabled | bool" diff --git a/roles/matrix-nginx-proxy/defaults/main.yml b/roles/matrix-nginx-proxy/defaults/main.yml index 8d606273..44cf8411 100644 --- a/roles/matrix-nginx-proxy/defaults/main.yml +++ b/roles/matrix-nginx-proxy/defaults/main.yml @@ -1,6 +1,7 @@ --- +# Project source code URL: https://github.com/nginx/nginx matrix_nginx_proxy_enabled: true -matrix_nginx_proxy_version: 1.21.6-alpine +matrix_nginx_proxy_version: 1.23.0-alpine # We use an official nginx image, which we fix-up to run unprivileged. # An alternative would be an `nginxinc/nginx-unprivileged` image, but @@ -174,6 +175,10 @@ matrix_nginx_proxy_proxy_hydrogen_hostname: "{{ matrix_server_fqn_hydrogen }}" matrix_nginx_proxy_proxy_cinny_enabled: false matrix_nginx_proxy_proxy_cinny_hostname: "{{ matrix_server_fqn_cinny }}" +# Controls whether proxying the buscarron domain should be done. +matrix_nginx_proxy_proxy_buscarron_enabled: false +matrix_nginx_proxy_proxy_buscarron_hostname: "{{ matrix_server_fqn_buscarron }}" + # Controls whether proxying the matrix domain should be done. matrix_nginx_proxy_proxy_matrix_enabled: false matrix_nginx_proxy_proxy_matrix_hostname: "{{ matrix_server_fqn_matrix }}" @@ -203,6 +208,62 @@ matrix_nginx_proxy_proxy_grafana_hostname: "{{ matrix_server_fqn_grafana }}" matrix_nginx_proxy_proxy_sygnal_enabled: false matrix_nginx_proxy_proxy_sygnal_hostname: "{{ matrix_server_fqn_sygnal }}" +# Controls whether proxying the ntfy domain should be done. +matrix_nginx_proxy_proxy_ntfy_enabled: false +matrix_nginx_proxy_proxy_ntfy_hostname: "{{ matrix_server_fqn_ntfy }}" + +# Controls whether proxying for (Prometheus) metrics (`/metrics/*`) for the various services should be done (on the matrix domain) +# If the internal Prometheus server (`matrix-prometheus` role) is used, proxying is not necessary, since Prometheus can access each container directly. +# This is only useful when an external Prometheus will be collecting metrics. +# +# To control what kind of metrics are exposed under `/metrics/` (e.g `/metrics/node-exporter`, `/metrics/postgres-exporter`, etc.), +# use `matrix_SERVICE_metrics_proxying_enabled` variables in each respective role. +# Roles inject themselves into the matrix-nginx-proxy configuration. +# +# To protect the metrics endpoints, see `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled` +matrix_nginx_proxy_proxy_matrix_metrics_enabled: false + +# Controls whether Basic Auth is enabled for all `/metrics/*` endpoints. +# +# You can provide the Basic Auth credentials in 2 ways: +# 1. A single username/password pair using `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username` and `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password` +# 2. Using raw content (`htpasswd`-generated file) provided in `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content` +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled: false + +# `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username` and `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password` specify +# the Basic Auth username/password for protecting `/metrics/*` endpoints. +# Alternatively, use `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content`. +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username: "" +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password: "" + +# `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content` value will be written verbatim to the htpasswd file protecting `/metrics/*` endpoints. +# Use this when a single username/password is not enough and you'd like to get more control over credentials. +# +# Read the manpage at `man 1 htpasswd` to learn more, then encrypt your password, and paste the encrypted value here. +# e.g. `htpasswd -c mypass.htpasswd prometheus` and enter `mysecurepw` when prompted yields `prometheus:$apr1$wZhqsn.U$7LC3kMmjUbjNAZjyMyvYv/` +# The whole thing is needed here. matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content: "prometheus:$apr1$wZhqsn.U$7LC3kMmjUbjNAZjyMyvYv/" +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content: "" + +# Specifies the path to the htpasswd file holding the htpasswd credentials for protecting `/metrics/*` endpoints +# This is not meant to be modified. +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_path: "{{ matrix_nginx_proxy_data_path_in_container if matrix_nginx_proxy_enabled else matrix_nginx_proxy_data_path }}/matrix-metrics-htpasswd" + +# Specifies the Apache container image to use +# when `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username` and `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password` are provided. +# This image provides the `htpasswd` tool which we use for generating the htpasswd file protecting `/metrics/*`. +# To avoid using this, use `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content` instead of supplying username/password. +# Learn more in: `roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml`. +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image: "{{ matrix_container_global_registry_prefix }}httpd:{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image_tag }}" +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image_tag: "2.4.54-alpine3.16" +matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_force_pull: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image_tag.endswith(':latest') }}" + +# A list of strings containing additional configuration blocks to add to the `location /metrics` configuration (matrix-domain.conf). +# Do not modify `matrix_nginx_proxy_proxy_matrix_metrics_additional_location_configuration_blocks` and `matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks`. +# If you'd like to inject your own configuration blocks, use `matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks`. +matrix_nginx_proxy_proxy_matrix_metrics_additional_location_configuration_blocks: "{{ matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks + matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks }}" +matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: [] +matrix_nginx_proxy_proxy_matrix_metrics_additional_user_location_configuration_blocks: [] + # Controls whether proxying for the matrix-corporal API (`/_matrix/corporal`) should be done (on the matrix domain) matrix_nginx_proxy_proxy_matrix_corporal_api_enabled: false matrix_nginx_proxy_proxy_matrix_corporal_api_addr_with_container: "matrix-corporal:41081" @@ -227,16 +288,6 @@ matrix_nginx_proxy_proxy_matrix_identity_api_enabled: false matrix_nginx_proxy_proxy_matrix_identity_api_addr_with_container: "matrix-ma1sd:{{ matrix_ma1sd_container_port }}" matrix_nginx_proxy_proxy_matrix_identity_api_addr_sans_container: "127.0.0.1:{{ matrix_ma1sd_container_port }}" -# Controls whether proxying for metrics (`/_synapse/metrics`) should be done (on the matrix domain) -matrix_nginx_proxy_proxy_synapse_metrics: false -matrix_nginx_proxy_synapse_workers_enabled_list: [] -matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled: false -# The following value will be written verbatim to the htpasswd file that stores the password for nginx to check against and needs to be encoded appropriately. -# Read the manpage at `man 1 htpasswd` to learn more, then encrypt your password, and paste the encrypted value here. -# e.g. `htpasswd -c mypass.htpasswd prometheus` and enter `mysecurepw` when prompted yields `prometheus:$apr1$wZhqsn.U$7LC3kMmjUbjNAZjyMyvYv/` -# The part after `prometheus:` is needed here. matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_key: "$apr1$wZhqsn.U$7LC3kMmjUbjNAZjyMyvYv/" -matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_key: "" - # The addresses where the Matrix Client API is. # Certain extensions (like matrix-corporal) may override this in order to capture all traffic. matrix_nginx_proxy_proxy_matrix_client_api_addr_with_container: "matrix-nginx-proxy:12080" @@ -269,8 +320,6 @@ matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes: | (['/_synapse/oidc'] if matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_synapse_oidc_api_enabled else []) + (['/_synapse/admin'] if matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_synapse_admin_api_enabled else []) - + - (['/_synapse.*/metrics'] if matrix_nginx_proxy_proxy_synapse_metrics else []) }} # Specifies where requests for the root URI (`/`) on the `matrix.` domain should be redirected. @@ -282,7 +331,7 @@ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain: "" # Controls whether proxying for the Matrix Federation API should be done. matrix_nginx_proxy_proxy_matrix_federation_api_enabled: false matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container: "matrix-nginx-proxy:12088" -matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container: "localhost:12088" +matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container: "127.0.0.1:12088" matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb: "{{ (matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb | int) * 3 }}" matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate: "{{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem" matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key: "{{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem" @@ -290,7 +339,7 @@ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_trusted_certificate: "{{ matr # The tmpfs at /tmp needs to be large enough to handle multiple concurrent file uploads. matrix_nginx_proxy_tmp_directory_size_mb: "{{ (matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb | int) * 50 }}" - +matrix_nginx_proxy_tmp_cache_directory_size_mb: "{{ (matrix_nginx_proxy_synapse_cache_max_size_mb | int) * 2 }}" # A list of strings containing additional configuration blocks to add to the nginx server configuration (nginx.conf). # for big matrixservers to enlarge the number of open files to prevent timeouts # matrix_nginx_proxy_proxy_additional_configuration_blocks: @@ -318,6 +367,9 @@ matrix_nginx_proxy_proxy_hydrogen_additional_server_configuration_blocks: [] # A list of strings containing additional configuration blocks to add to Cinny's server configuration (matrix-client-cinny.conf). matrix_nginx_proxy_proxy_cinny_additional_server_configuration_blocks: [] +# A list of strings containing additional configuration blocks to add to buscarron's server configuration (matrix-bot-buscarron.conf). +matrix_nginx_proxy_proxy_buscarron_additional_server_configuration_blocks: [] + # A list of strings containing additional configuration blocks to add to Dimension's server configuration (matrix-dimension.conf). matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks: [] @@ -333,6 +385,9 @@ matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks: [] # A list of strings containing additional configuration blocks to add to Sygnal's server configuration (matrix-sygnal.conf). matrix_nginx_proxy_proxy_sygnal_additional_server_configuration_blocks: [] +# A list of strings containing additional configuration blocks to add to ntfy's server configuration (matrix-ntfy.conf). +matrix_nginx_proxy_proxy_ntfy_additional_server_configuration_blocks: [] + # A list of strings containing additional configuration blocks to add to the base domain server configuration (matrix-base-domain.conf). matrix_nginx_proxy_proxy_domain_additional_server_configuration_blocks: [] @@ -492,7 +547,7 @@ matrix_ssl_lets_encrypt_staging: false # Learn more here: https://eff-certbot.readthedocs.io/en/stable/using.html#changing-the-acme-server matrix_ssl_lets_encrypt_server: '' -matrix_ssl_lets_encrypt_certbot_docker_image: "{{ matrix_container_global_registry_prefix }}certbot/certbot:{{ matrix_ssl_architecture }}-v1.23.0" +matrix_ssl_lets_encrypt_certbot_docker_image: "{{ matrix_container_global_registry_prefix }}certbot/certbot:{{ matrix_ssl_architecture }}-v1.28.0" matrix_ssl_lets_encrypt_certbot_docker_image_force_pull: "{{ matrix_ssl_lets_encrypt_certbot_docker_image.endswith(':latest') }}" matrix_ssl_lets_encrypt_certbot_standalone_http_port: 2402 matrix_ssl_lets_encrypt_support_email: ~ @@ -572,6 +627,16 @@ matrix_nginx_proxy_synapse_media_repository_locations: [] matrix_nginx_proxy_synapse_user_dir_locations: [] matrix_nginx_proxy_synapse_frontend_proxy_locations: [] +# synapse content caching +matrix_nginx_proxy_synapse_cache_enabled: false +matrix_nginx_proxy_synapse_cache_path: "{{ '/tmp/synapse-cache' if matrix_nginx_proxy_enabled else matrix_nginx_proxy_data_path+'/synapse-cache' }}" +matrix_nginx_proxy_synapse_cache_keys_zone_name: "STATIC" +matrix_nginx_proxy_synapse_cache_keys_zone_size: "10m" +matrix_nginx_proxy_synapse_cache_inactive_time: "48h" +matrix_nginx_proxy_synapse_cache_max_size_mb: 1024 +matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time: "24h" + + # The amount of worker processes and connections # Consider increasing these when you are expecting high amounts of traffic # http://nginx.org/en/docs/ngx_core_module.html#worker_connections diff --git a/roles/matrix-nginx-proxy/tasks/init.yml b/roles/matrix-nginx-proxy/tasks/init.yml index ddc8cb47..eb4249cb 100644 --- a/roles/matrix-nginx-proxy/tasks/init.yml +++ b/roles/matrix-nginx-proxy/tasks/init.yml @@ -1,9 +1,9 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-nginx-proxy.service'] }}" - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + [item.name] }}" - when: "item.applicable|bool and item.enableable|bool" + when: "item.applicable | bool and item.enableable | bool" with_items: "{{ matrix_ssl_renewal_systemd_units_list }}" diff --git a/roles/matrix-nginx-proxy/tasks/main.yml b/roles/matrix-nginx-proxy/tasks/main.yml index 74f8e8d1..9c34d1f5 100644 --- a/roles/matrix-nginx-proxy/tasks/main.yml +++ b/roles/matrix-nginx-proxy/tasks/main.yml @@ -1,39 +1,39 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always # Always validating the configuration, even if `matrix_nginx_proxy: false`. # This role performs actions even if the role is disabled, so we need # to ensure there's a valid configuration in any case. -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-nginx-proxy -- import_tasks: "{{ role_path }}/tasks/ssl/main.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/main.yml" + when: run_setup | bool tags: - setup-all - setup-nginx-proxy - setup-ssl -- import_tasks: "{{ role_path }}/tasks/setup_nginx_proxy.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_nginx_proxy.yml" + when: run_setup | bool tags: - setup-all - setup-nginx-proxy -- import_tasks: "{{ role_path }}/tasks/self_check_well_known.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_well_known.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool + when: run_self_check | bool tags: - self-check - name: Mark matrix-nginx-proxy role as executed - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_role_executed: true tags: - always diff --git a/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml b/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml new file mode 100644 index 00000000..c511e402 --- /dev/null +++ b/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml @@ -0,0 +1,60 @@ +--- + +# When we're dealing with raw htpasswd content, we just store it in the file directly. +- name: Ensure matrix-metrics-htpasswd is present when generated from raw content (protecting /metrics/* URIs) + ansible.builtin.copy: + content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content }}" + dest: "{{ matrix_nginx_proxy_data_path }}/matrix-metrics-htpasswd" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: 0600 + when: not matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username + +# Alternatively, we need to use the `htpasswd` tool to generate the htpasswd file. +# There's an Ansible module that helps with that, but it requires passlib (a Python module) to be installed on the server. +# See: https://docs.ansible.com/ansible/2.3/htpasswd_module.html#requirements-on-host-that-executes-module +# We support various distros, with various versions of Python. Installing additional Python modules can be a hassle. +# As a workaround, we run `htpasswd` from an Apache container image. +- block: + - name: Ensure Apache Docker image is pulled for generating matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs) + docker_image: + name: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_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_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_force_pull }}" + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + + # We store the password in a file and make the `htpasswd` tool read it from there, + # as opposed to passing it directly on stdin (which will expose it to other processes on the server). + - name: Store metrics password in a temporary file + ansible.builtin.copy: + content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password }}" + dest: "/tmp/matrix-nginx-proxy-metrics-password" + mode: 0400 + owner: "{{ matrix_user_uid }}" + group: "{{ matrix_user_gid }}" + + - name: Generate matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs) + ansible.builtin.command: + cmd: >- + {{ matrix_host_command_docker }} run + --rm + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --cap-drop=ALL + --network=none + --mount type=bind,src={{ matrix_nginx_proxy_data_path }},dst=/data + --mount type=bind,src=/tmp/matrix-nginx-proxy-metrics-password,dst=/password,ro + --entrypoint=/bin/sh + {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }} + -c + 'cat /password | htpasswd -i -c /data/matrix-metrics-htpasswd {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username }} && chmod 600 /data/matrix-metrics-htpasswd' + changed_when: true + + - name: Delete temporary metrics password file + ansible.builtin.file: + path: /tmp/matrix-nginx-proxy-metrics-password + state: absent + when: matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username != '' diff --git a/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml b/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml index be1b6555..2a5042d5 100644 --- a/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml +++ b/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml @@ -1,7 +1,7 @@ --- - name: Determine well-known files to check (Matrix) - set_fact: + ansible.builtin.set_fact: well_known_file_checks: - path: /.well-known/matrix/client purpose: Client Discovery @@ -10,7 +10,7 @@ validate_certs: "{{ matrix_nginx_proxy_self_check_validate_certificates }}" - block: - - set_fact: + - ansible.builtin.set_fact: well_known_file_check_matrix_server: path: /.well-known/matrix/server purpose: Server Discovery @@ -19,12 +19,12 @@ validate_certs: "{{ matrix_nginx_proxy_self_check_validate_certificates }}" - name: Determine domains that we require certificates for (ma1sd) - set_fact: + ansible.builtin.set_fact: well_known_file_checks: "{{ well_known_file_checks + [well_known_file_check_matrix_server] }}" - when: matrix_well_known_matrix_server_enabled|bool + when: matrix_well_known_matrix_server_enabled | bool - name: Perform well-known checks - include_tasks: "{{ role_path }}/tasks/self_check_well_known_file.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/self_check_well_known_file.yml" with_items: "{{ well_known_file_checks }}" loop_control: loop_var: well_known_file_check diff --git a/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml b/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml index 588cd1e7..95a43dea 100644 --- a/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml +++ b/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml @@ -1,13 +1,13 @@ --- -- set_fact: +- ansible.builtin.set_fact: well_known_url_matrix: "https://{{ matrix_server_fqn_matrix }}{{ well_known_file_check.path }}" well_known_url_identity: "https://{{ matrix_domain }}{{ well_known_file_check.path }}" # These well-known files may be served without a `Content-Type: application/json` header, # so we can't rely on the uri module's automatic parsing of JSON. - name: Check .well-known on the matrix hostname - uri: + ansible.builtin.uri: url: "{{ well_known_url_matrix }}" follow_redirects: none return_content: true @@ -19,25 +19,25 @@ ignore_errors: true - name: Fail if .well-known not working on the matrix hostname - fail: + ansible.builtin.fail: msg: "Failed checking that the well-known file for {{ well_known_file_check.purpose }} is configured at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`). Is port 443 open in your firewall? Full error: {{ result_well_known_matrix }}" when: "result_well_known_matrix.failed" - name: Parse JSON for well-known payload at the matrix hostname - set_fact: - well_known_matrix_payload: "{{ result_well_known_matrix.content|from_json }}" + ansible.builtin.set_fact: + well_known_matrix_payload: "{{ result_well_known_matrix.content | from_json }}" - name: Fail if .well-known not CORS-aware on the matrix hostname - fail: + ansible.builtin.fail: msg: "The well-known file for {{ well_known_file_check.purpose }} on `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`) is not CORS-aware. The file needs to be served with an Access-Control-Allow-Origin header set." when: "well_known_file_check.cors and 'access_control_allow_origin' not in result_well_known_matrix" - name: Report working .well-known on the matrix hostname - debug: + ansible.builtin.debug: msg: "well-known for {{ well_known_file_check.purpose }} is configured correctly for `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`)" - name: Check .well-known on the identity hostname - uri: + ansible.builtin.uri: url: "{{ well_known_url_identity }}" follow_redirects: "{{ well_known_file_check.follow_redirects }}" return_content: true @@ -49,25 +49,25 @@ ignore_errors: true - name: Fail if .well-known not working on the identity hostname - fail: + ansible.builtin.fail: msg: "Failed checking that the well-known file for {{ well_known_file_check.purpose }} is configured at `{{ matrix_domain }}` (checked endpoint: `{{ well_known_url_identity }}`). Is port 443 open in your firewall? Full error: {{ result_well_known_identity }}" when: "result_well_known_identity.failed" - name: Parse JSON for well-known payload at the identity hostname - set_fact: - well_known_identity_payload: "{{ result_well_known_identity.content|from_json }}" + ansible.builtin.set_fact: + well_known_identity_payload: "{{ result_well_known_identity.content | from_json }}" - name: Fail if .well-known not CORS-aware on the identity hostname - fail: + ansible.builtin.fail: msg: "The well-known file for {{ well_known_file_check.purpose }} on `{{ matrix_domain }}` (checked endpoint: `{{ well_known_url_identity }}`) is not CORS-aware. The file needs to be served with an Access-Control-Allow-Origin header set. See docs/configuring-well-known.md" when: "well_known_file_check.cors and 'access_control_allow_origin' not in result_well_known_identity" # For people who manually copy the well-known file, try to detect if it's outdated - name: Fail if well-known is different on matrix hostname and identity hostname - fail: + ansible.builtin.fail: msg: "The well-known files for {{ well_known_file_check.purpose }} at `{{ matrix_server_fqn_matrix }}` and `{{ matrix_domain }}` are different. Perhaps you copied the file ({{ well_known_file_check.path }}) manually before and now it's outdated?" when: "well_known_matrix_payload != well_known_identity_payload" - name: Report working .well-known on the identity hostname - debug: + ansible.builtin.debug: msg: "well-known for {{ well_known_file_check.purpose }} ({{ well_known_file_check.path }}) is configured correctly for `{{ matrix_domain }}` (checked endpoint: `{{ well_known_url_identity }}`)" diff --git a/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml b/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml index c546a083..2f65e656 100644 --- a/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml +++ b/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml @@ -11,74 +11,62 @@ # to be unnecessary. # - name: Ensure Matrix nginx-proxy paths exist - file: - path: "{{ item }}" + ansible.builtin.file: + path: "{{ item.path }}" state: directory mode: 0750 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" with_items: - - "{{ matrix_nginx_proxy_base_path }}" - - "{{ matrix_nginx_proxy_data_path }}" - - "{{ matrix_nginx_proxy_confd_path }}" + - {path: "{{ matrix_nginx_proxy_base_path }}", when: true} + - {path: "{{ matrix_nginx_proxy_data_path }}", when: true} + - {path: "{{ matrix_nginx_proxy_confd_path }}", when: true} + - {path: "{{ matrix_nginx_proxy_synapse_cache_path }}", when: "{{ matrix_nginx_proxy_synapse_cache_enabled and not matrix_nginx_proxy_enabled }}"} + when: item.when | bool - name: Ensure Matrix nginx-proxy configured (main config override) - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/nginx.conf.j2" dest: "{{ matrix_nginx_proxy_base_path }}/nginx.conf" mode: 0644 - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool -- name: Ensure matrix-synapse-metrics-htpasswd is present (protecting /_synapse/metrics URI) - template: - src: "{{ role_path }}/templates/nginx/matrix-synapse-metrics-htpasswd.j2" - dest: "{{ matrix_nginx_proxy_data_path }}/matrix-synapse-metrics-htpasswd" - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_groupname }}" - mode: 0400 - when: "matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled|bool and matrix_nginx_proxy_proxy_synapse_metrics|bool" - -- name: Generate sample prometheus.yml for external scraping - template: - src: "{{ role_path }}/templates/prometheus/external_prometheus.yml.example.j2" - dest: "{{ matrix_base_data_path }}/external_prometheus.yml.example" - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_groupname }}" - mode: 0644 - when: matrix_nginx_proxy_proxy_synapse_metrics|bool +- name: Setup metrics + ansible.builtin.include_tasks: "{{ role_path }}/tasks/nginx-proxy/setup_metrics_auth.yml" + when: matrix_nginx_proxy_proxy_matrix_metrics_enabled | bool and matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled | bool - name: Ensure Matrix nginx-proxy configured (generic) - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/nginx-http.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/nginx-http.conf" mode: 0644 - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool - name: Ensure Matrix nginx-proxy configuration for matrix-synapse exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-synapse.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-synapse.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_synapse_enabled|bool + when: matrix_nginx_proxy_proxy_synapse_enabled | bool - name: Ensure Matrix nginx-proxy configuration for matrix-synapse deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-synapse.conf" state: absent - when: "not matrix_nginx_proxy_proxy_synapse_enabled|bool" + when: "not matrix_nginx_proxy_proxy_synapse_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for matrix-dendrite exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-dendrite.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-dendrite.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_dendrite_enabled|bool + when: matrix_nginx_proxy_proxy_dendrite_enabled | bool - name: Ensure Matrix nginx-proxy configuration for matrix-dendrite deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-dendrite.conf" state: absent - when: "not matrix_nginx_proxy_proxy_dendrite_enabled|bool" + when: "not matrix_nginx_proxy_proxy_dendrite_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for matrix-conduit exists template: @@ -94,98 +82,112 @@ when: "not matrix_nginx_proxy_proxy_conduit_enabled|bool" - name: Ensure Matrix nginx-proxy configuration for Element domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-client-element.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-element.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_element_enabled|bool + when: matrix_nginx_proxy_proxy_element_enabled | bool - name: Ensure Matrix nginx-proxy configuration for riot domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-riot-web.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-riot-web.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_riot_compat_redirect_enabled|bool + when: matrix_nginx_proxy_proxy_riot_compat_redirect_enabled | bool - name: Ensure Matrix nginx-proxy configuration for Hydrogen domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-client-hydrogen.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-hydrogen.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_hydrogen_enabled|bool + when: matrix_nginx_proxy_proxy_hydrogen_enabled | bool - name: Ensure Matrix nginx-proxy configuration for Cinny domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-client-cinny.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-cinny.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_cinny_enabled|bool + when: matrix_nginx_proxy_proxy_cinny_enabled | bool + +- name: Ensure Matrix nginx-proxy configuration for buscarron domain exists + ansible.builtin.template: + src: "{{ role_path }}/templates/nginx/conf.d/matrix-bot-buscarron.conf.j2" + dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-buscarron.conf" + mode: 0644 + when: matrix_nginx_proxy_proxy_buscarron_enabled | bool - name: Ensure Matrix nginx-proxy configuration for dimension domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-dimension.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-dimension.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_dimension_enabled|bool + when: matrix_nginx_proxy_proxy_dimension_enabled | bool - name: Ensure Matrix nginx-proxy configuration for goneb domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-bot-go-neb.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-go-neb.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_bot_go_neb_enabled|bool + when: matrix_nginx_proxy_proxy_bot_go_neb_enabled | bool - name: Ensure Matrix nginx-proxy configuration for jitsi domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-jitsi.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-jitsi.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_jitsi_enabled|bool + when: matrix_nginx_proxy_proxy_jitsi_enabled | bool - name: Ensure Matrix nginx-proxy configuration for grafana domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-grafana.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-grafana.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_grafana_enabled|bool + when: matrix_nginx_proxy_proxy_grafana_enabled | bool - name: Ensure Matrix nginx-proxy configuration for sygnal domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-sygnal.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-sygnal.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_sygnal_enabled|bool + when: matrix_nginx_proxy_proxy_sygnal_enabled | bool + +- name: Ensure Matrix nginx-proxy configuration for ntfy domain exists + ansible.builtin.template: + src: "{{ role_path }}/templates/nginx/conf.d/matrix-ntfy.conf.j2" + dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-ntfy.conf" + mode: 0644 + when: matrix_nginx_proxy_proxy_ntfy_enabled | bool - name: Ensure Matrix nginx-proxy configuration for Matrix domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-domain.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-domain.conf" mode: 0644 - name: Ensure Matrix nginx-proxy data directory for base domain exists - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-domain" state: directory mode: 0750 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_nginx_proxy_base_domain_serving_enabled|bool and matrix_nginx_proxy_base_domain_create_directory|bool + when: matrix_nginx_proxy_base_domain_serving_enabled | bool and matrix_nginx_proxy_base_domain_create_directory | bool - name: Ensure Matrix nginx-proxy homepage for base domain exists - copy: + ansible.builtin.copy: content: "{{ matrix_nginx_proxy_base_domain_homepage_template }}" dest: "{{ matrix_nginx_proxy_data_path }}/matrix-domain/index.html" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_nginx_proxy_base_domain_serving_enabled|bool and matrix_nginx_proxy_base_domain_homepage_enabled|bool and matrix_nginx_proxy_base_domain_create_directory|bool + when: matrix_nginx_proxy_base_domain_serving_enabled | bool and matrix_nginx_proxy_base_domain_homepage_enabled | bool and matrix_nginx_proxy_base_domain_create_directory | bool - name: Ensure Matrix nginx-proxy configuration for base domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-base-domain.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-base-domain.conf" mode: 0644 - when: matrix_nginx_proxy_base_domain_serving_enabled|bool + when: matrix_nginx_proxy_base_domain_serving_enabled | bool # # Tasks related to setting up matrix-nginx-proxy @@ -196,22 +198,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_nginx_proxy_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_nginx_proxy_docker_image_force_pull }}" - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-nginx-proxy.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-nginx-proxy.service.j2" dest: "{{ matrix_systemd_path }}/matrix-nginx-proxy.service" mode: 0644 register: matrix_nginx_proxy_systemd_service_result - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool - name: Ensure systemd reloaded after matrix-nginx-proxy.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_nginx_proxy_enabled and matrix_nginx_proxy_systemd_service_result.changed" @@ -221,111 +223,128 @@ # - name: Check existence of matrix-nginx-proxy service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-nginx-proxy.service" register: matrix_nginx_proxy_service_stat - when: "not matrix_nginx_proxy_enabled|bool" + when: "not matrix_nginx_proxy_enabled | bool" - name: Ensure matrix-nginx-proxy is stopped - service: + ansible.builtin.service: name: matrix-nginx-proxy state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_nginx_proxy_enabled|bool and matrix_nginx_proxy_service_stat.stat.exists" + when: "not matrix_nginx_proxy_enabled | bool and matrix_nginx_proxy_service_stat.stat.exists" - name: Ensure matrix-nginx-proxy.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-nginx-proxy.service" state: absent - when: "not matrix_nginx_proxy_enabled|bool and matrix_nginx_proxy_service_stat.stat.exists" + when: "not matrix_nginx_proxy_enabled | bool and matrix_nginx_proxy_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-nginx-proxy.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_nginx_proxy_enabled|bool and matrix_nginx_proxy_service_stat.stat.exists" + when: "not matrix_nginx_proxy_enabled | bool and matrix_nginx_proxy_service_stat.stat.exists" - name: Ensure Matrix nginx-proxy configuration for matrix domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-domain.conf" state: absent - when: "not matrix_nginx_proxy_proxy_matrix_enabled|bool" + when: "not matrix_nginx_proxy_proxy_matrix_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for riot domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-riot-web.conf" state: absent - when: "not matrix_nginx_proxy_proxy_riot_compat_redirect_enabled|bool" + when: "not matrix_nginx_proxy_proxy_riot_compat_redirect_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for Hydrogen domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-hydrogen.conf" state: absent - when: "not matrix_nginx_proxy_proxy_hydrogen_enabled|bool" + when: "not matrix_nginx_proxy_proxy_hydrogen_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for Cinny domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-cinny.conf" state: absent - when: "not matrix_nginx_proxy_proxy_cinny_enabled|bool" + when: "not matrix_nginx_proxy_proxy_cinny_enabled | bool" + +- name: Ensure Matrix nginx-proxy configuration for buscarron domain deleted + ansible.builtin.file: + path: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-buscarron.conf" + state: absent + when: "not matrix_nginx_proxy_proxy_buscarron_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for dimension domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-dimension.conf" state: absent - when: "not matrix_nginx_proxy_proxy_dimension_enabled|bool" + when: "not matrix_nginx_proxy_proxy_dimension_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for goneb domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-go-neb.conf" state: absent - when: "not matrix_nginx_proxy_proxy_bot_go_neb_enabled|bool" + when: "not matrix_nginx_proxy_proxy_bot_go_neb_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for jitsi domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-jitsi.conf" state: absent - when: "not matrix_nginx_proxy_proxy_jitsi_enabled|bool" + when: "not matrix_nginx_proxy_proxy_jitsi_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for grafana domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-grafana.conf" state: absent - when: "not matrix_nginx_proxy_proxy_grafana_enabled|bool" + when: "not matrix_nginx_proxy_proxy_grafana_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for sygnal domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-sygnal.conf" state: absent - when: "not matrix_nginx_proxy_proxy_sygnal_enabled|bool" + when: "not matrix_nginx_proxy_proxy_sygnal_enabled | bool" + +- name: Ensure Matrix nginx-proxy configuration for ntfy domain deleted + ansible.builtin.file: + path: "{{ matrix_nginx_proxy_confd_path }}/matrix-ntfy.conf" + state: absent + when: "not matrix_nginx_proxy_proxy_ntfy_enabled | bool" - name: Ensure Matrix nginx-proxy homepage for base domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-domain/index.html" state: absent - when: "not matrix_nginx_proxy_base_domain_serving_enabled|bool" + when: "not matrix_nginx_proxy_base_domain_serving_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for base domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-base-domain.conf" state: absent - when: "not matrix_nginx_proxy_base_domain_serving_enabled|bool" + when: "not matrix_nginx_proxy_base_domain_serving_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for main config override deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_base_path }}/nginx.conf" state: absent - when: "not matrix_nginx_proxy_enabled|bool" + when: "not matrix_nginx_proxy_enabled | bool" - name: Ensure Matrix nginx-proxy htpasswd is deleted (protecting /_synapse/metrics URI) - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-synapse-metrics-htpasswd" state: absent - when: "not matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled|bool or not matrix_nginx_proxy_proxy_synapse_metrics|bool" -- name: Ensure sample prometheus.yml for external scraping is deleted - file: +# This file is now generated by the matrix-synapse role and saved in the Synapse directory +- name: (Cleanup) Ensure old sample prometheus.yml for external scraping is deleted + ansible.builtin.file: path: "{{ matrix_base_data_path }}/external_prometheus.yml.example" state: absent - when: "not matrix_nginx_proxy_proxy_synapse_metrics|bool" + +- name: Ensure Matrix nginx-proxy htpasswd is deleted (protecting /metrics/* URIs) + ansible.builtin.file: + path: "{{ matrix_nginx_proxy_data_path }}/matrix-metrics-htpasswd" + state: absent + when: "not matrix_nginx_proxy_proxy_matrix_metrics_enabled | bool or not matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled | bool" diff --git a/roles/matrix-nginx-proxy/tasks/setup_well_known.yml b/roles/matrix-nginx-proxy/tasks/setup_well_known.yml index 1c85552c..11e941bd 100644 --- a/roles/matrix-nginx-proxy/tasks/setup_well_known.yml +++ b/roles/matrix-nginx-proxy/tasks/setup_well_known.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_well_known_file_path: "{{ matrix_static_files_base_path }}/.well-known/matrix/client" # We need others to be able to read these directories too, @@ -7,7 +7,7 @@ # # For running with another webserver, we recommend being part of the `matrix` group. - name: Ensure Matrix static-files path exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0755 @@ -17,7 +17,7 @@ - "{{ matrix_static_files_base_path }}/.well-known/matrix" - name: Ensure Matrix /.well-known/matrix/client configured - template: + ansible.builtin.template: src: "{{ role_path }}/templates/well-known/matrix-client.j2" dest: "{{ matrix_static_files_base_path }}/.well-known/matrix" mode: 0644 diff --git a/roles/matrix-nginx-proxy/tasks/ssl/main.yml b/roles/matrix-nginx-proxy/tasks/ssl/main.yml index 6b843c7b..e9d270cf 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/main.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/main.yml @@ -1,12 +1,12 @@ --- - name: Fail if using unsupported SSL certificate retrieval method - fail: + ansible.builtin.fail: msg: "The `matrix_ssl_retrieval_method` variable contains an unsupported value" when: "matrix_ssl_retrieval_method not in ['lets-encrypt', 'self-signed', 'manually-managed', 'none']" - name: Fail if using unsupported private key type - fail: + ansible.builtin.fail: msg: "The `matrix_ssl_lets_encrypt_key_type` variable contains an unsupported value" when: "matrix_ssl_lets_encrypt_key_type not in ['rsa', 'ecdsa']" @@ -14,7 +14,7 @@ # Common tasks, required by almost any method below. - name: Ensure SSL certificate paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0770 @@ -29,8 +29,8 @@ # Method specific tasks follow -- import_tasks: tasks/ssl/setup_ssl_lets_encrypt.yml +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt.yml" -- import_tasks: tasks/ssl/setup_ssl_self_signed.yml +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_self_signed.yml" -- import_tasks: tasks/ssl/setup_ssl_manually_managed.yml +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_manually_managed.yml" diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml index bfd25894..0e5339a9 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml @@ -3,7 +3,7 @@ # This is a cleanup/migration task, because of to the new way we manage cronjobs (`cron` module) and the new script name. # This migration task can be removed some time in the future. - name: (Migration) Remove deprecated Let's Encrypt SSL certificate management files - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: @@ -25,23 +25,23 @@ force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ssl_lets_encrypt_certbot_docker_image_force_pull }}" - name: Obtain Let's Encrypt certificates - include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml" with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}" loop_control: loop_var: domain_name - name: Ensure Let's Encrypt SSL renewal script installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-lets-encrypt-certificates-renew.j2" dest: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew" mode: 0755 - name: Ensure SSL renewal systemd units installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/{{ item.name }}.j2" dest: "{{ matrix_systemd_path }}/{{ item.name }}" mode: 0644 - when: "item.applicable|bool" + when: "item.applicable | bool" with_items: "{{ matrix_ssl_renewal_systemd_units_list }}" when: "matrix_ssl_retrieval_method == 'lets-encrypt'" @@ -51,14 +51,14 @@ - block: - name: Ensure matrix-ssl-lets-encrypt-renew cronjob removed - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/{{ item.name }}" state: absent - when: "not item.applicable|bool" + when: "not item.applicable | bool" with_items: "{{ matrix_ssl_renewal_systemd_units_list }}" - name: Ensure Let's Encrypt SSL renewal script removed - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew" state: absent when: "matrix_ssl_retrieval_method != 'lets-encrypt'" diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml index 12a21257..18cae090 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml @@ -1,35 +1,35 @@ --- -- debug: +- ansible.builtin.debug: msg: "Dealing with SSL certificate retrieval for domain: {{ domain_name }}" -- set_fact: +- ansible.builtin.set_fact: domain_name_certificate_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/fullchain.pem" - name: Check if a certificate for the domain already exists - stat: + ansible.builtin.stat: path: "{{ domain_name_certificate_path }}" register: domain_name_certificate_path_stat -- set_fact: +- ansible.builtin.set_fact: domain_name_needs_cert: "{{ not domain_name_certificate_path_stat.stat.exists }}" - block: - name: Ensure required service for obtaining is started - service: + ansible.builtin.service: name: "{{ matrix_ssl_pre_obtaining_required_service_name }}" state: started register: matrix_ssl_pre_obtaining_required_service_start_result - name: Wait some time, so that the required service for obtaining can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ matrix_ssl_pre_obtaining_required_service_start_wait_time_seconds }}" - when: "matrix_ssl_pre_obtaining_required_service_start_result.changed|bool" - when: "domain_name_needs_cert|bool and matrix_ssl_pre_obtaining_required_service_name != ''" + when: "matrix_ssl_pre_obtaining_required_service_start_result.changed | bool" + when: "domain_name_needs_cert | bool and matrix_ssl_pre_obtaining_required_service_name != ''" # This will fail if there is something running on port 80 (like matrix-nginx-proxy). # We suppress the error, as we'll try another method below. - name: Attempt initial SSL certificate retrieval with standalone authenticator (directly) - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name=matrix-certbot @@ -51,14 +51,14 @@ --agree-tos --email={{ matrix_ssl_lets_encrypt_support_email }} -d {{ domain_name }} - when: domain_name_needs_cert|bool + when: domain_name_needs_cert | bool register: result_certbot_direct ignore_errors: true # If matrix-nginx-proxy is configured from a previous run of this playbook, # and it's running now, it may be able to proxy requests to `matrix_ssl_lets_encrypt_certbot_standalone_http_port`. - name: Attempt initial SSL certificate retrieval with standalone authenticator (via proxy) - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name=matrix-certbot @@ -86,7 +86,7 @@ ignore_errors: true - name: Fail if all SSL certificate retrieval attempts failed - fail: + ansible.builtin.fail: msg: | Failed to obtain a certificate directly (by listening on port 80) and also failed to obtain by relying on the server at port 80 to proxy the request. diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml index 7bcd3d74..f6fc5a81 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml @@ -1,7 +1,7 @@ --- - name: Verify certificates - include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml" with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}" loop_control: loop_var: domain_name diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml index 2b5bb1f3..ab0ffa2f 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml @@ -1,23 +1,23 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_ssl_certificate_verification_cert_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/fullchain.pem" matrix_ssl_certificate_verification_cert_key_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/privkey.pem" - name: Check if SSL certificate file exists - stat: + ansible.builtin.stat: path: "{{ matrix_ssl_certificate_verification_cert_path }}" register: matrix_ssl_certificate_verification_cert_path_stat_result -- fail: +- ansible.builtin.fail: msg: "Failed finding a certificate file (for domain `{{ domain_name }}`) at `{{ matrix_ssl_certificate_verification_cert_path }}`" when: "not matrix_ssl_certificate_verification_cert_path_stat_result.stat.exists" - name: Check if SSL certificate key file exists - stat: + ansible.builtin.stat: path: "{{ matrix_ssl_certificate_verification_cert_key_path }}" register: matrix_ssl_certificate_verification_cert_key_path_stat_result -- fail: +- ansible.builtin.fail: msg: "Failed finding a certificate key file (for domain `{{ domain_name }}`) at `{{ matrix_ssl_certificate_verification_cert_key_path }}`" when: "not matrix_ssl_certificate_verification_cert_key_path_stat_result.stat.exists" diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml index 47ec40aa..3a7f1958 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml @@ -1,10 +1,10 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" when: "matrix_ssl_retrieval_method == 'self-signed'" - name: Generate self-signed certificates - include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml" with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}" loop_control: loop_var: domain_name diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml index ff7fa2d8..d0b254a2 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml @@ -1,19 +1,19 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_ssl_certificate_csr_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/csr.csr" matrix_ssl_certificate_cert_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/fullchain.pem" matrix_ssl_certificate_cert_key_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/privkey.pem" - name: Check if SSL certificate file exists - stat: + ansible.builtin.stat: path: "{{ matrix_ssl_certificate_cert_path }}" register: matrix_ssl_certificate_cert_path_stat_result # In order to do any sort of generation (below), we need to ensure the directory exists first - name: Ensure SSL certificate directory exists - file: - path: "{{ matrix_ssl_certificate_csr_path|dirname }}" + ansible.builtin.file: + path: "{{ matrix_ssl_certificate_csr_path | dirname }}" state: directory mode: 0750 owner: "{{ matrix_user_username }}" @@ -28,7 +28,7 @@ # # We'll do it in a more manual way. - name: Generate SSL certificate - command: | + ansible.builtin.command: | openssl req -x509 \ -sha256 \ -newkey rsa:4096 \ @@ -40,7 +40,7 @@ when: "not matrix_ssl_certificate_cert_path_stat_result.stat.exists" - name: Adjust SSL certificate file ownership - file: + ansible.builtin.file: path: "{{ item }}" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" diff --git a/roles/matrix-nginx-proxy/tasks/validate_config.yml b/roles/matrix-nginx-proxy/tasks/validate_config.yml index 0de93873..6c87a4bb 100644 --- a/roles/matrix-nginx-proxy/tasks/validate_config.yml +++ b/roles/matrix-nginx-proxy/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). @@ -16,30 +16,39 @@ - {'old': 'matrix_nginx_proxy_reload_cron_time_definition', 'new': ''} - name: Fail on unknown matrix_ssl_retrieval_method - fail: + ansible.builtin.fail: msg: >- `matrix_ssl_retrieval_method` needs to be set to a known value. when: "matrix_ssl_retrieval_method not in ['lets-encrypt', 'self-signed', 'manually-managed', 'none']" - name: Fail on unknown matrix_nginx_proxy_ssl_config - fail: + ansible.builtin.fail: msg: >- `matrix_nginx_proxy_ssl_preset` needs to be set to a known value. when: "matrix_nginx_proxy_ssl_preset not in ['modern', 'intermediate', 'old']" +- name: Fail if Basic Auth enabled for metrics, but no credentials supplied + ansible.builtin.fail: + msg: | + Enabling Basic Auth for metrics (`matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled`) requires: + - either a username/password (provided in `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username` and `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password`) + - or raw htpasswd content (provided in `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content`) + when: "matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled | bool and (matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content == '' and (matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username == '' or matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password == ''))" + - block: - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). with_items: - {'old': 'host_specific_matrix_ssl_support_email', 'new': 'matrix_ssl_lets_encrypt_support_email'} - {'old': 'host_specific_matrix_ssl_lets_encrypt_support_email', 'new': 'matrix_ssl_lets_encrypt_support_email'} + - {'old': 'matrix_nginx_proxy_proxy_synapse_workers_enabled_list', 'new': ''} when: "item.old in vars" - name: Fail if required variables are undefined - fail: + ansible.builtin.fail: msg: "The `{{ item }}` variable must be defined and have a non-null value" with_items: - "matrix_ssl_lets_encrypt_support_email" @@ -49,3 +58,17 @@ - "matrix_nginx_proxy_proxy_synapse_client_api_addr_sans_container" when: "vars[item] == '' or vars[item] is none" when: "matrix_ssl_retrieval_method == 'lets-encrypt'" + +- name: (Deprecation) Catch and report old metrics usage + ansible.builtin.fail: + msg: >- + Your configuration contains a variable (`{{ item }}`), which refers to the old metrics collection system for Synapse, + which exposed metrics on `https://matrix.DOMAIN/_synapse/metrics` and `https://matrix.DOMAIN/_synapse-worker-TYPE-ID/metrics`. + + We now recommend exposing Synapse metrics in another way, from another URL. + Refer to the changelog for more details: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/CHANGELOG.md#2022-06-22 + with_items: + - matrix_nginx_proxy_proxy_synapse_metrics + - matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled + - matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_key + when: "item in vars" diff --git a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-bot-buscarron.conf.j2 b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-bot-buscarron.conf.j2 new file mode 100644 index 00000000..0ce1473b --- /dev/null +++ b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-bot-buscarron.conf.j2 @@ -0,0 +1,104 @@ +#jinja2: lstrip_blocks: "True" + +{% macro render_vhost_directives() %} + gzip on; + gzip_types text/plain application/json application/javascript text/css image/x-icon font/ttf image/gif; + + {% if matrix_nginx_proxy_hsts_preload_enabled %} + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; + {% else %} + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + {% endif %} + add_header X-XSS-Protection "{{ matrix_nginx_proxy_xss_protection }}"; + add_header X-Content-Type-Options nosniff; + add_header X-Frame-Options SAMEORIGIN; + add_header Content-Security-Policy "frame-ancestors 'none'"; + {% if matrix_nginx_proxy_floc_optout_enabled %} + add_header Permissions-Policy interest-cohort=() always; + {% endif %} + + {% for configuration_block in matrix_nginx_proxy_proxy_buscarron_additional_server_configuration_blocks %} + {{- configuration_block }} + {% endfor %} + + location / { + {% if matrix_nginx_proxy_enabled %} + {# Use the embedded DNS resolver in Docker containers to discover the service #} + resolver 127.0.0.11 valid=5s; + set $backend "matrix-bot-buscarron:8080"; + proxy_pass http://$backend; + {% else %} + {# Generic configuration for use outside of our container setup #} + proxy_pass http://127.0.0.1:8080; + {% endif %} + + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }}; + } +{% endmacro %} + +server { + listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }}; + listen [::]:{{ 8080 if matrix_nginx_proxy_enabled else 80 }}; + + + server_name {{ matrix_nginx_proxy_proxy_buscarron_hostname }}; + + server_tokens off; + root /dev/null; + + {% if matrix_nginx_proxy_https_enabled %} + location /.well-known/acme-challenge { + {% if matrix_nginx_proxy_enabled %} + {# Use the embedded DNS resolver in Docker containers to discover the service #} + resolver 127.0.0.11 valid=5s; + set $backend "matrix-certbot:8080"; + proxy_pass http://$backend; + {% else %} + {# Generic configuration for use outside of our container setup #} + proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }}; + {% endif %} + } + + location / { + return 301 https://$http_host$request_uri; + } + {% else %} + {{ render_vhost_directives() }} + {% endif %} +} + +{% if matrix_nginx_proxy_https_enabled %} +server { + listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2; + listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2; + + server_name {{ matrix_nginx_proxy_proxy_buscarron_hostname }}; + + server_tokens off; + root /dev/null; + + ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_buscarron_hostname }}/fullchain.pem; + ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_buscarron_hostname }}/privkey.pem; + + ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }}; + {% if matrix_nginx_proxy_ssl_ciphers != "" %} + ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }}; + {% endif %} + ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }}; + + {% if matrix_nginx_proxy_ocsp_stapling_enabled %} + ssl_stapling on; + ssl_stapling_verify on; + ssl_trusted_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_buscarron_hostname }}/chain.pem; + {% endif %} + + {% if matrix_nginx_proxy_ssl_session_tickets_off %} + ssl_session_tickets off; + {% endif %} + ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }}; + ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }}; + + {{ render_vhost_directives() }} +} +{% endif %} diff --git a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-domain.conf.j2 b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-domain.conf.j2 index 4abcd40a..2895ba14 100644 --- a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-domain.conf.j2 +++ b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-domain.conf.j2 @@ -45,6 +45,19 @@ {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }} {% endif %} + {% if matrix_nginx_proxy_proxy_matrix_metrics_enabled %} + location /metrics { + {% if matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled %} + auth_basic "protected"; + auth_basic_user_file {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_path }}; + {% endif %} + + {% for configuration_block in matrix_nginx_proxy_proxy_matrix_metrics_additional_location_configuration_blocks %} + {{- configuration_block }} + {% endfor %} + } + {% endif %} + {% if matrix_nginx_proxy_proxy_matrix_corporal_api_enabled %} location ^~ /_matrix/corporal { {% if matrix_nginx_proxy_enabled %} diff --git a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-ntfy.conf.j2 b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-ntfy.conf.j2 new file mode 100644 index 00000000..988b3b35 --- /dev/null +++ b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-ntfy.conf.j2 @@ -0,0 +1,102 @@ +#jinja2: lstrip_blocks: "True" + +{% macro render_vhost_directives() %} + gzip on; + gzip_types text/plain application/json application/javascript text/css image/x-icon font/ttf image/gif; + + {% if matrix_nginx_proxy_hsts_preload_enabled %} + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; + {% else %} + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + {% endif %} + add_header X-XSS-Protection "{{ matrix_nginx_proxy_xss_protection }}"; + add_header X-Content-Type-Options nosniff; + add_header X-Frame-Options DENY; + +{% for configuration_block in matrix_nginx_proxy_proxy_ntfy_additional_server_configuration_blocks %} + {{- configuration_block }} +{% endfor %} + + location / { + {% if matrix_nginx_proxy_enabled %} + {# Use the embedded DNS resolver in Docker containers to discover the service #} + resolver 127.0.0.11 valid=5s; + set $backend "matrix-ntfy:80"; + proxy_pass http://$backend; + {% else %} + {# Generic configuration for use outside of our container setup #} + proxy_pass http://127.0.0.1:2586; + {% endif %} + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }}; + proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }}; + } +{% endmacro %} + +server { + listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }}; + listen [::]:{{ 8080 if matrix_nginx_proxy_enabled else 80 }}; + + server_name {{ matrix_nginx_proxy_proxy_ntfy_hostname }}; + + server_tokens off; + root /dev/null; + + {% if matrix_nginx_proxy_https_enabled %} + location /.well-known/acme-challenge { + {% if matrix_nginx_proxy_enabled %} + {# Use the embedded DNS resolver in Docker containers to discover the service #} + resolver 127.0.0.11 valid=5s; + set $backend "matrix-certbot:8080"; + proxy_pass http://$backend; + {% else %} + {# Generic configuration for use outside of our container setup #} + proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }}; + {% endif %} + } + + location / { + return 301 https://$http_host$request_uri; + } + {% else %} + {{ render_vhost_directives() }} + {% endif %} +} + +{% if matrix_nginx_proxy_https_enabled %} +server { + listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2; + listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2; + + server_name {{ matrix_nginx_proxy_proxy_ntfy_hostname }}; + + server_tokens off; + root /dev/null; + + ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_ntfy_hostname }}/fullchain.pem; + ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_ntfy_hostname }}/privkey.pem; + + ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }}; + {% if matrix_nginx_proxy_ssl_ciphers != '' %} + ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }}; + {% endif %} + ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }}; + + {% if matrix_nginx_proxy_ocsp_stapling_enabled %} + ssl_stapling on; + ssl_stapling_verify on; + ssl_trusted_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_ntfy_hostname }}/chain.pem; + {% endif %} + + {% if matrix_nginx_proxy_ssl_session_tickets_off %} + ssl_session_tickets off; + {% endif %} + ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }}; + ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }}; + + {{ render_vhost_directives() }} +} +{% endif %} diff --git a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 index 720b5086..735f4538 100644 --- a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 +++ b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 @@ -1,10 +1,13 @@ #jinja2: lstrip_blocks: "True" -{% set generic_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'generic_worker')|list %} -{% set media_repository_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'media_repository')|list %} -{% set user_dir_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'user_dir')|list %} -{% set frontend_proxy_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'frontend_proxy')|list %} +{% set generic_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'generic_worker') | list %} +{% set media_repository_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'media_repository') | list %} +{% set user_dir_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'user_dir') | list %} +{% set frontend_proxy_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'frontend_proxy') | list %} {% if matrix_nginx_proxy_synapse_workers_enabled %} + {% if matrix_nginx_proxy_synapse_cache_enabled %} + proxy_cache_path {{ matrix_nginx_proxy_synapse_cache_path }} levels=1:2 keys_zone={{ matrix_nginx_proxy_synapse_cache_keys_zone_name }}:{{ matrix_nginx_proxy_synapse_cache_keys_zone_size }} inactive={{ matrix_nginx_proxy_synapse_cache_inactive_time }} max_size={{ matrix_nginx_proxy_synapse_cache_max_size_mb }}m; + {% endif %} # Round Robin "upstream" pools for workers {% if generic_workers %} @@ -95,6 +98,14 @@ server { client_body_buffer_size 25M; client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M; proxy_max_temp_file_size 0; + + {% if matrix_nginx_proxy_synapse_cache_enabled %} + proxy_buffering on; + proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }}; + proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }}; + proxy_force_ranges on; + add_header X-Cache-Status $upstream_cache_status; + {% endif %} } {% endfor %} {% endif %} @@ -134,45 +145,6 @@ server { {{- configuration_block }} {% endfor %} - {% if matrix_nginx_proxy_proxy_synapse_metrics %} - location /_synapse/metrics { - {% if matrix_nginx_proxy_enabled %} - {# Use the embedded DNS resolver in Docker containers to discover the service #} - resolver 127.0.0.11 valid=5s; - set $backend "{{ matrix_nginx_proxy_proxy_synapse_metrics_addr_with_container }}"; - proxy_pass http://$backend; - {% else %} - {# Generic configuration for use outside of our container setup #} - proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_metrics_addr_sans_container }}; - {% endif %} - - proxy_set_header Host $host; - - {% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %} - auth_basic "protected"; - auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd; - {% endif %} - } - {% endif %} - - {% if matrix_nginx_proxy_enabled and matrix_nginx_proxy_proxy_synapse_metrics %} - {% for worker in matrix_nginx_proxy_proxy_synapse_workers_enabled_list %} - {% if worker.metrics_port != 0 %} - location /_synapse-worker-{{ worker.type }}-{{ worker.instanceId }}/metrics { - resolver 127.0.0.11 valid=5s; - set $backend "matrix-synapse-worker-{{ worker.type }}-{{ worker.instanceId }}:{{ worker.metrics_port }}"; - proxy_pass http://$backend/_synapse/metrics; - proxy_set_header Host $host; - - {% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %} - auth_basic "protected"; - auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd; - {% endif %} - } - {% endif %} - {% endfor %} - {% endif %} - {# Everything else just goes to the API server ##} location / { {% if matrix_nginx_proxy_enabled %} @@ -227,6 +199,14 @@ server { client_body_buffer_size 25M; client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M; proxy_max_temp_file_size 0; + + {% if matrix_nginx_proxy_synapse_cache_enabled %} + proxy_buffering on; + proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }}; + proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }}; + proxy_force_ranges on; + add_header X-Cache-Status $upstream_cache_status; + {% endif %} } {% endfor %} {% endif %} diff --git a/roles/matrix-nginx-proxy/templates/nginx/matrix-synapse-metrics-htpasswd.j2 b/roles/matrix-nginx-proxy/templates/nginx/matrix-synapse-metrics-htpasswd.j2 deleted file mode 100644 index 1a7247ac..00000000 --- a/roles/matrix-nginx-proxy/templates/nginx/matrix-synapse-metrics-htpasswd.j2 +++ /dev/null @@ -1,3 +0,0 @@ -#jinja2: lstrip_blocks: "True" -# User and password for protecting /_synapse/metrics URI -prometheus:{{ matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_key }} diff --git a/roles/matrix-nginx-proxy/templates/systemd/matrix-nginx-proxy.service.j2 b/roles/matrix-nginx-proxy/templates/systemd/matrix-nginx-proxy.service.j2 index 172a83bc..74356ea9 100755 --- a/roles/matrix-nginx-proxy/templates/systemd/matrix-nginx-proxy.service.j2 +++ b/roles/matrix-nginx-proxy/templates/systemd/matrix-nginx-proxy.service.j2 @@ -22,6 +22,9 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-nginx-proxy \ --cap-drop=ALL \ --read-only \ --tmpfs=/tmp:rw,noexec,nosuid,size={{ matrix_nginx_proxy_tmp_directory_size_mb }}m \ + {% if matrix_nginx_proxy_synapse_cache_enabled %} + --tmpfs=/tmp/synapse-cache:rw,noexec,nosuid,size={{ matrix_nginx_proxy_tmp_cache_directory_size_mb }}m\ + {% endif %} --network={{ matrix_docker_network }} \ {% if matrix_nginx_proxy_container_http_host_bind_port %} -p {{ matrix_nginx_proxy_container_http_host_bind_port }}:8080 \ diff --git a/roles/matrix-nginx-proxy/vars/main.yml b/roles/matrix-nginx-proxy/vars/main.yml index 5c51fe5b..1a9ed929 100644 --- a/roles/matrix-nginx-proxy/vars/main.yml +++ b/roles/matrix-nginx-proxy/vars/main.yml @@ -11,8 +11,8 @@ matrix_ssl_renewal_systemd_units_list: applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' }}" enableable: true - name: matrix-ssl-nginx-proxy-reload.service - applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled|bool }}" + applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled | bool }}" enableable: false - name: matrix-ssl-nginx-proxy-reload.timer - applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled|bool }}" + applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled | bool }}" enableable: true diff --git a/roles/matrix-ntfy/defaults/main.yml b/roles/matrix-ntfy/defaults/main.yml new file mode 100644 index 00000000..66bc5be4 --- /dev/null +++ b/roles/matrix-ntfy/defaults/main.yml @@ -0,0 +1,48 @@ +--- +# Project source code URL: https://github.com/binwiederhier/ntfy + +matrix_ntfy_enabled: true + +matrix_ntfy_base_path: "{{ matrix_base_data_path }}/ntfy" +matrix_ntfy_config_dir_path: "{{ matrix_ntfy_base_path }}/config" +matrix_ntfy_data_path: "{{ matrix_ntfy_base_path }}/data" + +matrix_ntfy_version: v1.27.2 +matrix_ntfy_docker_image: "{{ matrix_container_global_registry_prefix }}binwiederhier/ntfy:{{ matrix_ntfy_version }}" +matrix_ntfy_docker_image_force_pull: "{{ matrix_ntfy_docker_image.endswith(':latest') }}" + +# Public facing base URL of the ntfy service +matrix_ntfy_base_url: "https://{{ matrix_server_fqn_ntfy }}" + +# Controls whether the container exposes its HTTP port (tcp/80 in the container). +# +# Takes an ":" or "" value (e.g. "127.0.0.1:2586"), or empty string to not expose. +matrix_ntfy_container_http_host_bind_port: '' + +# A list of extra arguments to pass to the container (`docker run` command) +matrix_ntfy_container_extra_arguments: [] + +# Controls whether the self-check feature should validate SSL certificates. +matrix_ntfy_self_check_validate_certificates: true + +# Default ntfy configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_ntfy_configuration_extension_yaml`) +# or completely replace this variable with your own template. +matrix_ntfy_configuration_yaml: "{{ lookup('template', 'templates/ntfy/server.yml.j2') }}" + +matrix_ntfy_configuration_extension_yaml: | + # Your custom YAML configuration for ntfy goes here. + # This configuration extends the default starting configuration (`matrix_ntfy_configuration_yaml`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_ntfy_configuration_yaml`. + +matrix_ntfy_configuration_extension: "{{ matrix_ntfy_configuration_extension_yaml | from_yaml if matrix_ntfy_configuration_extension_yaml | from_yaml is mapping else {} }}" + +# Holds the final ntfy configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_ntfy_configuration_yaml`. +matrix_ntfy_configuration: "{{ matrix_ntfy_configuration_yaml | from_yaml | combine(matrix_ntfy_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-ntfy/tasks/init.yml b/roles/matrix-ntfy/tasks/init.yml new file mode 100644 index 00000000..6222ada0 --- /dev/null +++ b/roles/matrix-ntfy/tasks/init.yml @@ -0,0 +1,5 @@ +--- + +- ansible.builtin.set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ntfy.service'] }}" + when: matrix_ntfy_enabled | bool diff --git a/roles/matrix-ntfy/tasks/main.yml b/roles/matrix-ntfy/tasks/main.yml new file mode 100644 index 00000000..200d38c4 --- /dev/null +++ b/roles/matrix-ntfy/tasks/main.yml @@ -0,0 +1,24 @@ +--- + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_ntfy_enabled | bool" + tags: + - setup-all + - setup-ntfy + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_ntfy_enabled | bool" + tags: + - setup-all + - setup-ntfy + +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" + delegate_to: 127.0.0.1 + become: false + when: "run_self_check | bool and matrix_ntfy_enabled | bool" + tags: + - self-check diff --git a/roles/matrix-ntfy/tasks/self_check.yml b/roles/matrix-ntfy/tasks/self_check.yml new file mode 100644 index 00000000..02529f35 --- /dev/null +++ b/roles/matrix-ntfy/tasks/self_check.yml @@ -0,0 +1,25 @@ +--- + +# Query an arbitrary ntfy topic using ntfy's UnifiedPush topic name syntax. +# Expect an empty response (because we query 'since=1s'). + +- ansible.builtin.set_fact: + matrix_ntfy_url_endpoint_public: "{{ matrix_ntfy_base_url }}/upSELFCHECK123/json?poll=1&since=1s" + +- name: Check ntfy + ansible.builtin.uri: + url: "{{ matrix_ntfy_url_endpoint_public }}" + follow_redirects: none + validate_certs: "{{ matrix_ntfy_self_check_validate_certificates }}" + register: matrix_ntfy_self_check_result + check_mode: false + ignore_errors: true + +- name: Fail if ntfy not working + ansible.builtin.fail: + msg: "Failed checking ntfy is up at `{{ matrix_server_fqn_ntfy }}` (checked endpoint: `{{ matrix_ntfy_url_endpoint_public }}`). Is ntfy running? Is port 443 open in your firewall? Full error: {{ matrix_ntfy_self_check_result }}" + when: "matrix_ntfy_self_check_result.failed" + +- name: Report working ntfy + ansible.builtin.debug: + msg: "ntfy at `{{ matrix_server_fqn_ntfy }}` is working (checked endpoint: `{{ matrix_ntfy_url_endpoint_public }}`)" diff --git a/roles/matrix-ntfy/tasks/setup_install.yml b/roles/matrix-ntfy/tasks/setup_install.yml new file mode 100644 index 00000000..9afabc4c --- /dev/null +++ b/roles/matrix-ntfy/tasks/setup_install.yml @@ -0,0 +1,44 @@ +--- + +- name: Ensure matrix-ntfy image is pulled + docker_image: + name: "{{ matrix_ntfy_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_ntfy_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_ntfy_docker_image_force_pull }}" + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure matrix-ntfy paths exists + ansible.builtin.file: + path: "{{ item }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - "{{ matrix_ntfy_base_path }}" + - "{{ matrix_ntfy_config_dir_path }}" + - "{{ matrix_ntfy_data_path }}" + +- name: Ensure matrix-ntfy config installed + ansible.builtin.copy: + content: "{{ matrix_ntfy_configuration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_ntfy_config_dir_path }}/server.yml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-ntfy.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-ntfy.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-ntfy.service" + mode: 0644 + register: matrix_ntfy_systemd_service_result + +- name: Ensure systemd reloaded after matrix-ntfy.service installation + ansible.builtin.service: + daemon_reload: true + when: "matrix_ntfy_systemd_service_result.changed" diff --git a/roles/matrix-ntfy/tasks/setup_uninstall.yml b/roles/matrix-ntfy/tasks/setup_uninstall.yml new file mode 100644 index 00000000..f6d9cc8a --- /dev/null +++ b/roles/matrix-ntfy/tasks/setup_uninstall.yml @@ -0,0 +1,36 @@ +--- + +- name: Check existence of matrix-ntfy service + ansible.builtin.stat: + path: "{{ matrix_systemd_path }}/matrix-ntfy.service" + register: matrix_ntfy_service_stat + +- name: Ensure matrix-ntfy is stopped + ansible.builtin.service: + name: matrix-ntfy + state: stopped + enabled: false + daemon_reload: true + register: stopping_result + when: "matrix_ntfy_service_stat.stat.exists" + +- name: Ensure matrix-ntfy.service doesn't exist + ansible.builtin.file: + path: "{{ matrix_systemd_path }}/matrix-ntfy.service" + state: absent + when: "matrix_ntfy_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-ntfy.service removal + ansible.builtin.service: + daemon_reload: true + when: "matrix_ntfy_service_stat.stat.exists" + +- name: Ensure matrix-ntfy path doesn't exist + ansible.builtin.file: + path: "{{ matrix_ntfy_base_path }}" + state: absent + +- name: Ensure ntfy Docker image doesn't exist + docker_image: + name: "{{ matrix_ntfy_docker_image }}" + state: absent diff --git a/roles/matrix-ntfy/templates/ntfy/server.yml.j2 b/roles/matrix-ntfy/templates/ntfy/server.yml.j2 new file mode 100644 index 00000000..4cafcd62 --- /dev/null +++ b/roles/matrix-ntfy/templates/ntfy/server.yml.j2 @@ -0,0 +1,3 @@ +base_url: {{ matrix_ntfy_base_url }} +behind_proxy: true +cache_file: /data/cache.db diff --git a/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 b/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 new file mode 100644 index 00000000..da292e5c --- /dev/null +++ b/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 @@ -0,0 +1,38 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=matrix-ntfy +After=docker.service +Requires=docker.service +DefaultDependencies=no + +[Service] +Type=simple +Environment="HOME={{ matrix_systemd_unit_home_path }}" +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-ntfy 2>/dev/null || true' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-ntfy 2>/dev/null || true' + +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-ntfy \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --read-only \ + {% for arg in matrix_ntfy_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + --network={{ matrix_docker_network }} \ + {% if matrix_ntfy_container_http_host_bind_port %} + -p {{ matrix_ntfy_container_http_host_bind_port }}:80 \ + {% endif %} + --mount type=bind,src={{ matrix_ntfy_config_dir_path }},dst=/etc/ntfy,ro \ + --mount type=bind,src={{ matrix_ntfy_data_path }},dst=/data \ + {{ matrix_ntfy_docker_image }} \ + serve + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-ntfy 2>/dev/null || true' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-ntfy 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-ntfy + +[Install] +WantedBy=multi-user.target diff --git a/roles/matrix-postgres-backup/defaults/main.yml b/roles/matrix-postgres-backup/defaults/main.yml index 59ae5076..ed42266f 100644 --- a/roles/matrix-postgres-backup/defaults/main.yml +++ b/roles/matrix-postgres-backup/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/prodrigestivill/docker-postgres-backup-local matrix_postgres_backup_enabled: false diff --git a/roles/matrix-postgres-backup/tasks/init.yml b/roles/matrix-postgres-backup/tasks/init.yml index f74cea06..5ece870a 100644 --- a/roles/matrix-postgres-backup/tasks/init.yml +++ b/roles/matrix-postgres-backup/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-postgres-backup.service'] }}" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool diff --git a/roles/matrix-postgres-backup/tasks/main.yml b/roles/matrix-postgres-backup/tasks/main.yml index 19e3db5b..1403fa5b 100644 --- a/roles/matrix-postgres-backup/tasks/main.yml +++ b/roles/matrix-postgres-backup/tasks/main.yml @@ -1,17 +1,17 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_postgres_backup_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_postgres_backup_enabled | bool" tags: - setup-all - setup-postgres-backup -- import_tasks: "{{ role_path }}/tasks/setup_postgres_backup.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_postgres_backup.yml" + when: run_setup | bool tags: - setup-all - setup-postgres-backup diff --git a/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml b/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml index 73341033..a6246757 100644 --- a/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml +++ b/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml @@ -1,18 +1,20 @@ --- # -# Tasks related to setting up an internal postgres server +# Tasks related to setting up postgres backup # -- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - when: 'matrix_postgres_backup_enabled|bool and matrix_postgres_backup_postgres_data_path != ""' +- ansible.builtin.import_role: + name: matrix-postgres + tasks_from: detect_existing_postgres_version + when: 'matrix_postgres_backup_enabled | bool and matrix_postgres_backup_postgres_data_path != ""' # If we have found an existing version (installed from before), we use its corresponding Docker image. # If not, we install using the latest Postgres. # # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`). -- set_fact: - matrix_postgres_backup_docker_image_to_use: "{{ matrix_postgres_backup_docker_image_latest if matrix_postgres_backup_detected_version_corresponding_docker_image|default('') == '' else matrix_postgres_backup_detected_version_corresponding_docker_image }}" - when: matrix_postgres_backup_enabled|bool +- ansible.builtin.set_fact: + matrix_postgres_backup_docker_image_to_use: "{{ matrix_postgres_backup_docker_image_latest if matrix_postgres_backup_detected_version_corresponding_docker_image | default('') == '' else matrix_postgres_backup_detected_version_corresponding_docker_image }}" + when: matrix_postgres_backup_enabled | bool - name: Ensure postgres backup Docker image is pulled docker_image: @@ -20,14 +22,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_postgres_backup_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_postgres_backup_docker_image_force_pull }}" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Postgres backup paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0700 @@ -35,10 +37,10 @@ group: "{{ matrix_user_groupname }}" with_items: - "{{ matrix_postgres_backup_path }}" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool - name: Ensure Postgres environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/{{ item }}.j2" dest: "{{ matrix_postgres_backup_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -46,65 +48,65 @@ mode: 0640 with_items: - "env-postgres-backup" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool - name: Ensure matrix-postgres-backup.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-postgres-backup.service.j2" dest: "{{ matrix_systemd_path }}/matrix-postgres-backup.service" mode: 0644 register: matrix_postgres_backup_systemd_service_result - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool - name: Ensure systemd reloaded after matrix-postgres-backup.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_postgres_backup_enabled|bool and matrix_postgres_backup_systemd_service_result.changed" + when: "matrix_postgres_backup_enabled | bool and matrix_postgres_backup_systemd_service_result.changed" # -# Tasks related to getting rid of the internal postgres backup server (if it was previously enabled) +# Tasks related to getting rid of postgres backup (if it was previously enabled) # - name: Check existence of matrix-postgres-backup service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service" register: matrix_postgres_backup_service_stat - when: "not matrix_postgres_backup_enabled|bool" + when: "not matrix_postgres_backup_enabled | bool" - name: Ensure matrix-postgres-backup is stopped - service: + ansible.builtin.service: name: matrix-postgres-backup state: stopped enabled: false daemon_reload: true - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_service_stat.stat.exists" - name: Ensure matrix-postgres-backup.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service" state: absent - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-postgres-backup.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_service_stat.stat.exists" - name: Check existence of matrix-postgres-backup backup path - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_backup_path }}" register: matrix_postgres_backup_path_stat - when: "not matrix_postgres_backup_enabled|bool" + when: "not matrix_postgres_backup_enabled | bool" # We just want to notify the user. Deleting data is too destructive. - name: Inject warning if matrix-postgres backup data remains - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: You are not using the local backup service to backup the PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_backup_path }}`. Feel free to delete it." ] }} - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_path_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_path_stat.stat.exists" diff --git a/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml b/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml index 10828cc7..877e5934 100644 --- a/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml +++ b/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml @@ -4,58 +4,58 @@ # If there is, it also tries to detect the Docker image that corresponds to that version. - name: Initialize Postgres version determination variables (default to empty) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION" matrix_postgres_backup_detected_existing: false matrix_postgres_backup_detected_version: "" matrix_postgres_backup_detected_version_corresponding_docker_image: "" - name: Determine existing Postgres version (check PG_VERSION file) - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_backup_detection_pg_version_path }}" register: result_pg_version_stat -- set_fact: +- ansible.builtin.set_fact: matrix_postgres_backup_detected_existing: true when: "result_pg_version_stat.stat.exists" - name: Determine existing Postgres version (read PG_VERSION file) - slurp: + ansible.builtin.slurp: src: "{{ matrix_postgres_backup_detection_pg_version_path }}" register: result_pg_version - when: matrix_postgres_backup_detected_existing|bool + when: matrix_postgres_backup_detected_existing | bool - name: Determine existing Postgres version (make sense of PG_VERSION file) - set_fact: - matrix_postgres_backup_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}" - when: matrix_postgres_backup_detected_existing|bool + ansible.builtin.set_fact: + matrix_postgres_backup_detected_version: "{{ result_pg_version['content'] | b64decode | replace('\n', '') }}" + when: matrix_postgres_backup_detected_existing | bool - name: Determine corresponding Docker image to detected version (assume default of latest) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_latest }}" when: "matrix_postgres_backup_detected_version != ''" - name: Determine corresponding Docker image to detected version (use 9.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v9 }}" when: "matrix_postgres_backup_detected_version.startswith('9.')" - name: Determine corresponding Docker image to detected version (use 10.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v10 }}" when: "matrix_postgres_backup_detected_version == '10' or matrix_postgres_backup_detected_version.startswith('10.')" - name: Determine corresponding Docker image to detected version (use 11.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v11 }}" when: "matrix_postgres_backup_detected_version == '11' or matrix_postgres_backup_detected_version.startswith('11.')" - name: Determine corresponding Docker image to detected version (use 12.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v12 }}" when: "matrix_postgres_backup_detected_version == '12' or matrix_postgres_backup_detected_version.startswith('12.')" - name: Determine corresponding Docker image to detected version (use 13.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v13 }}" when: "matrix_postgres_backup_detected_version == '13' or matrix_postgres_backup_detected_version.startswith('13.')" diff --git a/roles/matrix-postgres-backup/tasks/validate_config.yml b/roles/matrix-postgres-backup/tasks/validate_config.yml index fda9b919..8a2ddb5a 100644 --- a/roles/matrix-postgres-backup/tasks/validate_config.yml +++ b/roles/matrix-postgres-backup/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Postgres settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-postgres/defaults/main.yml b/roles/matrix-postgres/defaults/main.yml index 8593bb83..39481f2e 100644 --- a/roles/matrix-postgres/defaults/main.yml +++ b/roles/matrix-postgres/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/postgres/postgres # Controls if the Postgres server managed by the playbook is enabled. # You can turn it off and use an external Postgres server by setting this to `false`. @@ -22,12 +23,12 @@ matrix_postgres_architecture: amd64 # > LOG: startup process (PID 37) was terminated by signal 11: Segmentation fault matrix_postgres_docker_image_suffix: "{{ '-alpine' if matrix_postgres_architecture in ['amd64', 'arm64'] else '' }}" -matrix_postgres_docker_image_v9: "{{ matrix_container_global_registry_prefix }}postgres:9.6.23{{ matrix_postgres_docker_image_suffix }}" -matrix_postgres_docker_image_v10: "{{ matrix_container_global_registry_prefix }}postgres:10.20{{ matrix_postgres_docker_image_suffix }}" -matrix_postgres_docker_image_v11: "{{ matrix_container_global_registry_prefix }}postgres:11.15{{ matrix_postgres_docker_image_suffix }}" -matrix_postgres_docker_image_v12: "{{ matrix_container_global_registry_prefix }}postgres:12.10{{ matrix_postgres_docker_image_suffix }}" -matrix_postgres_docker_image_v13: "{{ matrix_container_global_registry_prefix }}postgres:13.6{{ matrix_postgres_docker_image_suffix }}" -matrix_postgres_docker_image_v14: "{{ matrix_container_global_registry_prefix }}postgres:14.2{{ matrix_postgres_docker_image_suffix }}" +matrix_postgres_docker_image_v9: "{{ matrix_container_global_registry_prefix }}postgres:9.6.24{{ matrix_postgres_docker_image_suffix }}" +matrix_postgres_docker_image_v10: "{{ matrix_container_global_registry_prefix }}postgres:10.21{{ matrix_postgres_docker_image_suffix }}" +matrix_postgres_docker_image_v11: "{{ matrix_container_global_registry_prefix }}postgres:11.16{{ matrix_postgres_docker_image_suffix }}" +matrix_postgres_docker_image_v12: "{{ matrix_container_global_registry_prefix }}postgres:12.11{{ matrix_postgres_docker_image_suffix }}" +matrix_postgres_docker_image_v13: "{{ matrix_container_global_registry_prefix }}postgres:13.7{{ matrix_postgres_docker_image_suffix }}" +matrix_postgres_docker_image_v14: "{{ matrix_container_global_registry_prefix }}postgres:14.4{{ matrix_postgres_docker_image_suffix }}" matrix_postgres_docker_image_latest: "{{ matrix_postgres_docker_image_v14 }}" # This variable is assigned at runtime. Overriding its value has no effect. @@ -77,7 +78,7 @@ matrix_postgres_import_roles_to_ignore: [matrix_postgres_connection_username] # which is unsupported by default by newer Postgres versions (v14+). # When users are created and passwords are set by the playbook, they end up hashed as `scram-sha-256` on Postgres v14+. # If an md5-hashed password is restored on top, Postgres v14+ will refuse to authenticate users with it by default. -matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_postgres_import_roles_to_ignore|join('|') }})(;| WITH)" +matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_postgres_import_roles_to_ignore | join('|') }})(;| WITH)" # noqa var-spacing # A list of databases to avoid creating when importing (or upgrading) the database. # If a dump file contains the databases and they've also been created beforehand (see `matrix_postgres_additional_databases`), @@ -85,7 +86,7 @@ matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_post # We either need to not create them or to ignore the `CREATE DATABASE` statements in the dump. matrix_postgres_import_databases_to_ignore: [matrix_postgres_db_name] -matrix_postgres_import_databases_ignore_regex: "^CREATE DATABASE ({{ matrix_postgres_import_databases_to_ignore|join('|') }})\\s" +matrix_postgres_import_databases_ignore_regex: "^CREATE DATABASE ({{ matrix_postgres_import_databases_to_ignore | join('|') }})\\s" # noqa var-spacing # The number of seconds to wait after starting `matrix-postgres.service` # and before trying to run queries for creating additional databases/users against it. diff --git a/roles/matrix-postgres/tasks/util/detect_existing_postgres_version.yml b/roles/matrix-postgres/tasks/detect_existing_postgres_version.yml similarity index 74% rename from roles/matrix-postgres/tasks/util/detect_existing_postgres_version.yml rename to roles/matrix-postgres/tasks/detect_existing_postgres_version.yml index a7e94a0c..687d5e3a 100644 --- a/roles/matrix-postgres/tasks/util/detect_existing_postgres_version.yml +++ b/roles/matrix-postgres/tasks/detect_existing_postgres_version.yml @@ -2,60 +2,69 @@ # This utility aims to determine if there is some existing Postgres version in use or not. # If there is, it also tries to detect the Docker image that corresponds to that version. +# +# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible +# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html + + +- name: Fail detection if expectation fails (Postgres not enabled) + ansible.builtin.fail: + msg: "Trying to detect the version of the built-in Postgres server, but Postgres installation is not enabled (`matrix_postgres_enabled: false`)" + when: not matrix_postgres_enabled - name: Initialize Postgres version determination variables (default to empty) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION" matrix_postgres_detected_existing: false matrix_postgres_detected_version: "" matrix_postgres_detected_version_corresponding_docker_image: "" - name: Determine existing Postgres version (check PG_VERSION file) - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_detection_pg_version_path }}" register: result_pg_version_stat -- set_fact: +- ansible.builtin.set_fact: matrix_postgres_detected_existing: true when: "result_pg_version_stat.stat.exists" - name: Determine existing Postgres version (read PG_VERSION file) - slurp: + ansible.builtin.slurp: src: "{{ matrix_postgres_detection_pg_version_path }}" register: result_pg_version - when: matrix_postgres_detected_existing|bool + when: matrix_postgres_detected_existing | bool - name: Determine existing Postgres version (make sense of PG_VERSION file) - set_fact: - matrix_postgres_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}" - when: matrix_postgres_detected_existing|bool + ansible.builtin.set_fact: + matrix_postgres_detected_version: "{{ result_pg_version['content'] | b64decode | replace('\n', '') }}" + when: matrix_postgres_detected_existing | bool - name: Determine corresponding Docker image to detected version (assume default of latest) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_latest }}" when: "matrix_postgres_detected_version != ''" - name: Determine corresponding Docker image to detected version (use 9.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v9 }}" when: "matrix_postgres_detected_version.startswith('9.')" - name: Determine corresponding Docker image to detected version (use 10.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v10 }}" when: "matrix_postgres_detected_version == '10' or matrix_postgres_detected_version.startswith('10.')" - name: Determine corresponding Docker image to detected version (use 11.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v11 }}" when: "matrix_postgres_detected_version == '11' or matrix_postgres_detected_version.startswith('11.')" - name: Determine corresponding Docker image to detected version (use 12.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v12 }}" when: "matrix_postgres_detected_version == '12' or matrix_postgres_detected_version.startswith('12.')" - name: Determine corresponding Docker image to detected version (use 13.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v13 }}" when: "matrix_postgres_detected_version == '13' or matrix_postgres_detected_version.startswith('13.')" diff --git a/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml b/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml index 2a673ee3..671cb33f 100644 --- a/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml +++ b/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml @@ -3,22 +3,22 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `sqlite_database_path` variable needs to be provided to this playbook, via --extra-vars" when: "sqlite_database_path is not defined or sqlite_database_path.startswith('<')" - name: Check if the provided SQLite database file exists - stat: + ansible.builtin.stat: path: "{{ sqlite_database_path }}" register: sqlite_database_path_stat_result - name: Fail if provided SQLite database file doesn't exist - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ sqlite_database_path }}" when: "not sqlite_database_path_stat_result.stat.exists" @@ -27,16 +27,16 @@ - block: - name: Fail if postgres_connection_string_variable_name points to an undefined variable - fail: msg="postgres_connection_string_variable_name is defined, but there is no variable with the name `{{ postgres_connection_string_variable_name }}`" + ansible.builtin.fail: msg="postgres_connection_string_variable_name is defined, but there is no variable with the name `{{ postgres_connection_string_variable_name }}`" when: "postgres_connection_string_variable_name not in vars" - name: Get Postgres connection string from variable - set_fact: + ansible.builtin.set_fact: postgres_db_connection_string: "{{ lookup('vars', postgres_connection_string_variable_name) }}" when: 'postgres_connection_string_variable_name is defined' - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: >- Either a `postgres_db_connection_string` variable or a `postgres_connection_string_variable_name` needs to be provided to this playbook, via `--extra-vars`. Example: `--extra-vars="postgres_db_connection_string=postgresql://username:password@localhost:/database_name"` or `--extra-vars="postgres_connection_string_variable_name=matrix_appservice_discord_database_connString"` @@ -46,29 +46,29 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Import SQLite database from {{ sqlite_database_path }} into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -80,16 +80,20 @@ {{ matrix_postgres_pgloader_docker_image }} -c 'pgloader /in.db {{ postgres_db_connection_string }}' + register: matrix_postgres_import_generic_sqlite_db_import_result + changed_when: matrix_postgres_import_generic_sqlite_db_import_result.rc == 0 - name: Archive SQLite database ({{ sqlite_database_path }} -> {{ sqlite_database_path }}.backup) - command: + ansible.builtin.command: cmd: "mv {{ sqlite_database_path }} {{ sqlite_database_path }}.backup" + register: matrix_postgres_import_generic_sqlite_db_move_result + changed_when: matrix_postgres_import_generic_sqlite_db_move_result.rc == 0 - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your SQLite database file has been imported into Postgres. The original file has been moved from `{{ sqlite_database_path }}` to `{{ sqlite_database_path }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file." diff --git a/roles/matrix-postgres/tasks/import_postgres.yml b/roles/matrix-postgres/tasks/import_postgres.yml index 948c4b3a..53d67436 100644 --- a/roles/matrix-postgres/tasks/import_postgres.yml +++ b/roles/matrix-postgres/tasks/import_postgres.yml @@ -3,22 +3,22 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `server_path_postgres_dump` variable needs to be provided to this playbook, via --extra-vars" when: "server_path_postgres_dump is not defined or server_path_postgres_dump.startswith('<')" - name: Check if the provided Postgres dump file exists - stat: + ansible.builtin.stat: path: "{{ server_path_postgres_dump }}" register: result_server_path_postgres_dump_stat - name: Fail if provided Postgres dump file doesn't exists - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ server_path_postgres_dump }}" when: "not result_server_path_postgres_dump_stat.stat.exists" @@ -26,49 +26,49 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" - name: Set postgres_import_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_import_wait_time: "{{ 7 * 86400 }}" - when: "postgres_import_wait_time|default('') == ''" + when: "postgres_import_wait_time | default('') == ''" # By default, we connect and import into the main (`matrix`) database. # Single-database dumps for Synapse may wish to import into `synapse` instead. - name: Set postgres_default_import_database, if not provided - set_fact: + ansible.builtin.set_fact: postgres_default_import_database: "{{ matrix_postgres_db_name }}" - when: "postgres_default_import_database|default('') == ''" + when: "postgres_default_import_database | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false -- import_tasks: tasks/util/detect_existing_postgres_version.yml +- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml - name: Abort, if no existing Postgres version detected - fail: + ansible.builtin.fail: msg: "Could not find existing Postgres installation" - when: "not matrix_postgres_detected_existing|bool" + when: "not matrix_postgres_detected_existing | bool" # Starting the database container had automatically created the default # role (`matrix_postgres_connection_username`) and database (`matrix_postgres_db_name`). # The dump most likely contains those same entries and would try to re-create them, leading to errors. # We need to skip over those lines. - name: Generate Postgres database import command - set_fact: + ansible.builtin.set_fact: matrix_postgres_import_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-postgres-import --log-driver=none @@ -76,14 +76,16 @@ --cap-drop=ALL --network={{ matrix_docker_network }} --env-file={{ matrix_postgres_base_path }}/env-postgres-psql - --mount type=bind,src={{ server_path_postgres_dump }},dst=/{{ server_path_postgres_dump|basename }},ro + --mount type=bind,src={{ server_path_postgres_dump }},dst=/{{ server_path_postgres_dump | basename }},ro --entrypoint=/bin/sh {{ matrix_postgres_docker_image_latest }} - -c "cat /{{ server_path_postgres_dump|basename }} | + -c "cat /{{ server_path_postgres_dump | basename }} | {{ 'gunzip |' if server_path_postgres_dump.endswith('.gz') else '' }} grep -vE '{{ matrix_postgres_import_roles_ignore_regex }}' | grep -vE '{{ matrix_postgres_import_databases_ignore_regex }}' | psql -v ON_ERROR_STOP=1 -h matrix-postgres --dbname={{ postgres_default_import_database }}" + tags: + - skip_ansible_lint # This is a hack. # See: https://ansibledaily.com/print-to-standard-output-without-escaping/ @@ -91,7 +93,7 @@ # We want to run `debug: msg=".."`, but that dumps it as JSON and escapes double quotes within it, # which ruins the command (`matrix_postgres_import_command`) - name: Note about Postgres importing alternative - set_fact: + ansible.builtin.set_fact: dummy: true with_items: - >- @@ -101,6 +103,9 @@ and manually run the above import command directly on the server. - name: Perform Postgres database import - command: "{{ matrix_postgres_import_command }}" + ansible.builtin.command: + cmd: "{{ matrix_postgres_import_command }}" async: "{{ postgres_import_wait_time }}" poll: 10 + register: matrix_postgres_import_postgres_command_result + changed_when: matrix_postgres_import_postgres_command_result.rc == 0 diff --git a/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml b/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml index 2dafba59..a459b6e1 100644 --- a/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml +++ b/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml @@ -3,22 +3,22 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars" when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')" - name: Check if the provided SQLite homeserver.db file exists - stat: + ansible.builtin.stat: path: "{{ server_path_homeserver_db }}" register: result_server_path_homeserver_db_stat - name: Fail if provided SQLite homeserver.db file doesn't exist - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ server_path_homeserver_db }}" when: "not result_server_path_homeserver_db_stat.stat.exists" @@ -26,26 +26,26 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped daemon_reload: true - name: Ensure postgres data is wiped out - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: absent - name: Ensure postgres data path exists - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: directory mode: 0700 @@ -53,13 +53,13 @@ group: "{{ matrix_user_groupname }}" - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: restarted daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false @@ -70,17 +70,20 @@ # Also, some old `docker_container` versions were buggy and would leave containers behind # on failure, which we had to work around to allow retries (by re-running the playbook). - name: Import SQLite database into Postgres - command: | - docker run - --rm - --name=matrix-synapse-migrate - --log-driver=none - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} - --cap-drop=ALL - --network={{ matrix_docker_network }} - --entrypoint=python - --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data - --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store - --mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db|basename }} - {{ matrix_synapse_docker_image }} - /usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml + ansible.builtin.command: + cmd: | + docker run + --rm + --name=matrix-synapse-migrate + --log-driver=none + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --cap-drop=ALL + --network={{ matrix_docker_network }} + --entrypoint=python + --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data + --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store + --mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db | basename }} + {{ matrix_synapse_docker_image }} + /usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db | basename }} --postgres-config /data/homeserver.yaml + register: matrix_postgres_import_synapse_sqlite_db_result + changed_when: matrix_postgres_import_synapse_sqlite_db_result.rc == 0 diff --git a/roles/matrix-postgres/tasks/init.yml b/roles/matrix-postgres/tasks/init.yml index e5ebd9c5..659380f1 100644 --- a/roles/matrix-postgres/tasks/init.yml +++ b/roles/matrix-postgres/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-postgres.service'] }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool diff --git a/roles/matrix-postgres/tasks/main.yml b/roles/matrix-postgres/tasks/main.yml index 79890417..8e21b3c6 100644 --- a/roles/matrix-postgres/tasks/main.yml +++ b/roles/matrix-postgres/tasks/main.yml @@ -1,45 +1,45 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_postgres_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_postgres_enabled | bool" tags: - setup-all - setup-postgres -- import_tasks: "{{ role_path }}/tasks/setup_postgres.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_postgres.yml" + when: run_setup | bool tags: - setup-all - setup-postgres -- import_tasks: "{{ role_path }}/tasks/import_postgres.yml" - when: run_postgres_import|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_postgres.yml" + when: run_postgres_import | bool tags: - import-postgres # The `run_postgres_import_sqlite_db` variable had better be renamed to be consistent, # but that's a breaking change which may cause trouble for people. -- import_tasks: "{{ role_path }}/tasks/import_synapse_sqlite_db.yml" - when: run_postgres_import_sqlite_db|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_synapse_sqlite_db.yml" + when: run_postgres_import_sqlite_db | bool tags: - import-synapse-sqlite-db # Perhaps we need a new variable here, instead of `run_postgres_import_sqlite_db`. -- import_tasks: "{{ role_path }}/tasks/import_generic_sqlite_db.yml" - when: run_postgres_import_sqlite_db|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_generic_sqlite_db.yml" + when: run_postgres_import_sqlite_db | bool tags: - import-generic-sqlite-db -- import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml" - when: run_postgres_upgrade|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml" + when: run_postgres_upgrade | bool tags: - upgrade-postgres -- import_tasks: "{{ role_path }}/tasks/run_vacuum.yml" - when: run_postgres_vacuum|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/run_vacuum.yml" + when: run_postgres_vacuum | bool tags: - run-postgres-vacuum diff --git a/roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml b/roles/matrix-postgres/tasks/migrate_db_to_postgres.yml similarity index 83% rename from roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml rename to roles/matrix-postgres/tasks/migrate_db_to_postgres.yml index 90f73dba..be967d68 100644 --- a/roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml +++ b/roles/matrix-postgres/tasks/migrate_db_to_postgres.yml @@ -1,17 +1,17 @@ --- - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if util called incorrectly (missing matrix_postgres_db_migration_request) - fail: + ansible.builtin.fail: msg: "The `matrix_postgres_db_migration_request` variable needs to be provided to this util." when: "matrix_postgres_db_migration_request is not defined" - name: Fail if util called incorrectly (invalid matrix_postgres_db_migration_request) - fail: + ansible.builtin.fail: msg: "The `matrix_postgres_db_migration_request` variable needs to contain `{{ item }}`." with_items: - src @@ -22,18 +22,18 @@ when: "item not in matrix_postgres_db_migration_request" - name: Check if the provided source database file exists - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_db_migration_request.src }}" register: matrix_postgres_db_migration_request_src_stat_result - name: Fail if provided source database file doesn't exist - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ matrix_postgres_db_migration_request.src }}" when: "not matrix_postgres_db_migration_request_src_stat_result.stat.exists" - block: - name: Ensure pgloader repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_postgres_pgloader_container_image_self_build_repo }}" dest: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}" version: "{{ matrix_postgres_pgloader_container_image_self_build_repo_branch }}" @@ -49,7 +49,7 @@ # # Although we're not using the dimitri/pgloader image, the one we're using suffers from the same problem. - name: Switch pgloader base image from Debian stable (likely 10.x/Buster) to Bullseye - lineinfile: + ansible.builtin.lineinfile: path: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}/Dockerfile" regexp: "{{ item.match }}" line: "{{ item.replace }}" @@ -69,7 +69,7 @@ dockerfile: Dockerfile path: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}" pull: true - when: "matrix_postgres_pgloader_container_image_self_build|bool" + when: "matrix_postgres_pgloader_container_image_self_build | bool" - name: Ensure pgloader Docker image is pulled docker_image: @@ -82,26 +82,26 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work # matrix-postgres is most likely started already - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" # We only stop services here, leaving it to the caller to start them later. # @@ -112,14 +112,14 @@ # However, we don't do it, because it's simpler having it here, and it also gets to happen only if we'll be doing an import. # If we bailed out (somewhere above), nothing would have gotten stopped. It's nice to leave this running in such cases. - name: Ensure systemd services blocking the database import are stopped - service: + ansible.builtin.service: name: "{{ item }}" state: stopped failed_when: false with_items: "{{ matrix_postgres_db_migration_request.systemd_services_to_stop }}" - name: Import {{ matrix_postgres_db_migration_request.engine_old }} database from {{ matrix_postgres_db_migration_request.src }} into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -130,18 +130,20 @@ --entrypoint=/bin/sh {{ matrix_postgres_pgloader_docker_image }} -c - 'pgloader {{ matrix_postgres_db_migration_request.pgloader_options|default([])|join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}' + 'pgloader {{ matrix_postgres_db_migration_request.pgloader_options | default([]) | join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}' + register: matrix_postgres_migrate_db_to_postgres_import_result + changed_when: matrix_postgres_migrate_db_to_postgres_import_result.rc == 0 - block: - # We can't use `{{ role_path }}` here, neither with `import_tasks`, nor with `include_tasks`, - # because it refers to the role that included this util, and not to the role this file belongs to. - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: detect_existing_postgres_version - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}" - name: Execute additional Postgres SQL migration statements - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -152,18 +154,22 @@ {{ matrix_postgres_docker_image_to_use }} psql --host=matrix-postgres --dbname={{ matrix_postgres_db_migration_request.additional_psql_statements_db_name }} --command='{{ item }}' with_items: "{{ matrix_postgres_db_migration_request.additional_psql_statements_list }}" + register: matrix_postgres_migrate_db_to_postgres_additional_queries_result + changed_when: matrix_postgres_migrate_db_to_postgres_additional_queries_result.rc == 0 - when: "matrix_postgres_db_migration_request.additional_psql_statements_list|default([])|length > 0" + when: "matrix_postgres_db_migration_request.additional_psql_statements_list | default([])|length > 0" - name: Archive {{ matrix_postgres_db_migration_request.engine_old }} database ({{ matrix_postgres_db_migration_request.src }} -> {{ matrix_postgres_db_migration_request.src }}.backup) - command: + ansible.builtin.command: cmd: "mv {{ matrix_postgres_db_migration_request.src }} {{ matrix_postgres_db_migration_request.src }}.backup" + register: matrix_postgres_migrate_db_to_postgres_move_result + changed_when: matrix_postgres_migrate_db_to_postgres_move_result.rc == 0 - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your {{ matrix_postgres_db_migration_request.engine_old }} database file has been imported into Postgres. The original database file has been moved from `{{ matrix_postgres_db_migration_request.src }}` to `{{ matrix_postgres_db_migration_request.src }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file." diff --git a/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml b/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml index f927783f..fde580f5 100644 --- a/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml +++ b/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml @@ -9,14 +9,17 @@ # # For this reason, we store the Postgres data in `/matrix/postgres/data` and need to relocate any installations # which still store it in the parent directory (`/matrix/postgres`). +# +# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible +# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html - name: Check if old Postgres data directory is used - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_base_path }}/PG_VERSION" register: result_pg_old_data_dir_stat - name: Warn if old Postgres data directory detected - debug: + ansible.builtin.debug: msg: > Found that you have Postgres data in `{{ matrix_postgres_base_path }}`. From now on, Postgres data is supposed to be stored in `{{ matrix_postgres_data_path }}` instead. @@ -26,14 +29,14 @@ # We should stop Postgres first, before building a list of files, # as to ignore any `postmaster.pid` files, etc. - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped daemon_reload: true when: "result_pg_old_data_dir_stat.stat.exists" - name: Find files and directories in old Postgres data path - find: + ansible.builtin.find: paths: "{{ matrix_postgres_base_path }}" file_type: any excludes: ["data"] @@ -41,7 +44,7 @@ when: "result_pg_old_data_dir_stat.stat.exists" - name: Ensure new Postgres data path exists - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: directory mode: 0700 @@ -51,8 +54,11 @@ - block: - name: Relocate Postgres data files from old directory to new - command: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path|basename }}" + ansible.builtin.command: + cmd: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path | basename }}" with_items: "{{ result_pg_old_data_dir_find.files }}" + register: matrix_postgres_migrate_postgres_data_directory_move_result + changed_when: matrix_postgres_migrate_postgres_data_directory_move_result.rc == 0 when: "result_pg_old_data_dir_stat.stat.exists" # Intentionally not starting matrix-postgres here. @@ -61,12 +67,12 @@ # and have it initialize a new database. - name: Ensure outdated matrix-postgres.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-postgres.service" state: absent when: "result_pg_old_data_dir_stat.stat.exists" - name: Ensure systemd reloaded after getting rid of outdated matrix-postgres.service - service: + ansible.builtin.service: daemon_reload: true when: "result_pg_old_data_dir_stat.stat.exists" diff --git a/roles/matrix-postgres/tasks/run_vacuum.yml b/roles/matrix-postgres/tasks/run_vacuum.yml index 0b7a60f8..ce2bee6b 100644 --- a/roles/matrix-postgres/tasks/run_vacuum.yml +++ b/roles/matrix-postgres/tasks/run_vacuum.yml @@ -3,47 +3,47 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot run vacuum." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" - name: Set postgres_vacuum_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_vacuum_wait_time: "{{ 7 * 86400 }}" - when: "postgres_vacuum_wait_time|default('') == ''" + when: "postgres_vacuum_wait_time | default('') == ''" # Actual vacuuming work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false -- import_tasks: tasks/util/detect_existing_postgres_version.yml +- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml - name: Abort, if no existing Postgres version detected - fail: + ansible.builtin.fail: msg: "Could not find existing Postgres installation" - when: "not matrix_postgres_detected_existing|bool" + when: "not matrix_postgres_detected_existing | bool" - name: Generate Postgres database vacuum command - set_fact: + ansible.builtin.set_fact: matrix_postgres_vacuum_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-vacuum --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -54,37 +54,38 @@ psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -c 'VACUUM FULL VERBOSE' - name: Note about Postgres vacuum alternative - debug: + ansible.builtin.debug: msg: >- - Running vacuum with the following Postgres command: `{{ matrix_postgres_vacuum_command }}`. + Running vacuum with the following Postgres ansible.builtin.command: `{{ matrix_postgres_vacuum_command }}`. If this crashes, you can stop all processes (`systemctl stop matrix-*`), start Postgres only (`systemctl start matrix-postgres`) and manually run the above command directly on the server. - name: Populate service facts - service_facts: + ansible.builtin.service_facts: -- set_fact: - matrix_postgres_synapse_was_running: "{{ ansible_facts.services['matrix-synapse.service']|default(none) is not none and ansible_facts.services['matrix-synapse.service'].state == 'running' }}" +- ansible.builtin.set_fact: + matrix_postgres_synapse_was_running: "{{ ansible_facts.services['matrix-synapse.service'] | default(none) is not none and ansible_facts.services['matrix-synapse.service'].state == 'running' }}" - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped daemon_reload: true - name: Run Postgres vacuum command - command: "{{ matrix_postgres_vacuum_command }}" + ansible.builtin.command: "{{ matrix_postgres_vacuum_command }}" async: "{{ postgres_vacuum_wait_time }}" poll: 10 register: matrix_postgres_synapse_vacuum_result + changed_when: matrix_postgres_synapse_vacuum_result.rc == 0 # Intentionally show the results -- debug: var="matrix_postgres_synapse_vacuum_result" +- ansible.builtin.debug: var="matrix_postgres_synapse_vacuum_result" - name: Ensure matrix-synapse is started, if it previously was - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true - when: "matrix_postgres_synapse_was_running|bool" + when: "matrix_postgres_synapse_was_running | bool" diff --git a/roles/matrix-postgres/tasks/setup_postgres.yml b/roles/matrix-postgres/tasks/setup_postgres.yml index 04763a32..49eb3249 100644 --- a/roles/matrix-postgres/tasks/setup_postgres.yml +++ b/roles/matrix-postgres/tasks/setup_postgres.yml @@ -4,36 +4,36 @@ # Tasks related to setting up an internal postgres server # -- import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml" - when: matrix_postgres_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml" + when: matrix_postgres_enabled | bool -- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - when: matrix_postgres_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/detect_existing_postgres_version.yml" + when: matrix_postgres_enabled | bool # If we have found an existing version (installed from before), we use its corresponding Docker image. # If not, we install using the latest Postgres. # # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`). -- set_fact: +- ansible.builtin.set_fact: matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Abort if on an unsupported Postgres version - fail: + ansible.builtin.fail: msg: "You're on Postgres {{ matrix_postgres_detected_version }}, which is no longer supported. To upgrade, see docs/maintenance-postgres.md" - when: "matrix_postgres_enabled|bool and matrix_postgres_detected_version.startswith('9.')" + when: "matrix_postgres_enabled | bool and matrix_postgres_detected_version.startswith('9.')" - name: Inject warning if on an old version of Postgres - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your setup is on an old Postgres version ({{ matrix_postgres_docker_image_to_use }}), while {{ matrix_postgres_docker_image_latest }} is supported. You can upgrade using --tags=upgrade-postgres" ] }} - when: "matrix_postgres_enabled|bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest" + when: "matrix_postgres_enabled | bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest" # Even if we don't run the internal server, we still need this for running the CLI - name: Ensure postgres Docker image is pulled @@ -42,14 +42,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_postgres_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_postgres_docker_image_force_pull }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Postgres paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0700 @@ -58,22 +58,22 @@ with_items: - "{{ matrix_postgres_base_path }}" - "{{ matrix_postgres_data_path }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool # We do this as a separate task, because: # - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is) # - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true - name: Ensure Postgres data path ownership is correct - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: directory owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" recurse: true - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure Postgres environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/{{ item }}.j2" dest: "{{ matrix_postgres_base_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -82,79 +82,79 @@ with_items: - "env-postgres-psql" - "env-postgres-server" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres-cli script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2" dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres-cli-non-interactive script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli-non-interactive.j2" dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli-non-interactive" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-change-user-admin-status script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-change-user-admin-status.j2" dest: "{{ matrix_local_bin_path }}/matrix-change-user-admin-status" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: (Migration) Ensure old matrix-make-user-admin script deleted - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/matrix-make-user-admin" state: absent - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres-update-user-password-hash script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2" dest: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2" dest: "{{ matrix_systemd_path }}/matrix-postgres.service" mode: 0644 register: matrix_postgres_systemd_service_result - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure systemd reloaded after matrix-postgres.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed" + when: "matrix_postgres_enabled | bool and matrix_postgres_systemd_service_result.changed" -- include_tasks: +- ansible.builtin.include_tasks: file: "{{ role_path }}/tasks/util/create_additional_databases.yml" apply: tags: - always - when: "matrix_postgres_enabled|bool and matrix_postgres_additional_databases|length > 0" + when: "matrix_postgres_enabled | bool and matrix_postgres_additional_databases|length > 0" - name: Check existence of matrix-postgres backup data path - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup" register: matrix_postgres_data_backup_path_stat - when: "matrix_postgres_enabled|bool" + when: "matrix_postgres_enabled | bool" - name: Inject warning if backup data remains - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: You have some Postgres backup data in `{{ matrix_postgres_data_path }}-auto-upgrade-backup`, which was created during the last major Postgres update you ran. If your setup works well after this upgrade, feel free to delete this whole directory." ] }} - when: "matrix_postgres_enabled|bool and matrix_postgres_data_backup_path_stat.stat.exists" + when: "matrix_postgres_enabled | bool and matrix_postgres_data_backup_path_stat.stat.exists" # @@ -162,54 +162,54 @@ # - name: Check existence of matrix-postgres service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-postgres.service" register: matrix_postgres_service_stat - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped daemon_reload: true - when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists" - name: Ensure matrix-postgres.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-postgres.service" state: absent - when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-postgres.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists" - name: Check existence of matrix-postgres local data path - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_data_path }}" register: matrix_postgres_data_path_stat - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # We just want to notify the user. Deleting data is too destructive. - name: Inject warning if matrix-postgres local data remains - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: You are not using a local PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_data_path }}`. Feel free to delete it." ] }} - when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_data_path_stat.stat.exists" - name: Remove Postgres scripts - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/{{ item }}" state: absent with_items: - matrix-postgres-cli - matrix-change-user-admin-status - matrix-postgres-update-user-password-hash - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" diff --git a/roles/matrix-postgres/tasks/upgrade_postgres.yml b/roles/matrix-postgres/tasks/upgrade_postgres.yml index bf98d938..2f228a4c 100644 --- a/roles/matrix-postgres/tasks/upgrade_postgres.yml +++ b/roles/matrix-postgres/tasks/upgrade_postgres.yml @@ -1,73 +1,73 @@ --- - name: Set default postgres_dump_dir, if not provided - set_fact: + ansible.builtin.set_fact: postgres_dump_dir: "/tmp" - when: "postgres_dump_dir|default('') == ''" + when: "postgres_dump_dir | default('') == ''" - name: Set postgres_dump_name, if not provided - set_fact: + ansible.builtin.set_fact: postgres_dump_name: "matrix-postgres-dump.sql.gz" - when: "postgres_dump_name|default('') == ''" + when: "postgres_dump_name | default('') == ''" - name: Set postgres_auto_upgrade_backup_data_path, if not provided - set_fact: + ansible.builtin.set_fact: postgres_auto_upgrade_backup_data_path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup" - when: "postgres_auto_upgrade_backup_data_path|default('') == ''" + when: "postgres_auto_upgrade_backup_data_path | default('') == ''" - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" - name: Set postgres_force_upgrade, if not provided - set_fact: + ansible.builtin.set_fact: postgres_force_upgrade: false - when: "postgres_force_upgrade|default('') == ''" + when: "postgres_force_upgrade | default('') == ''" - name: Fail, if trying to upgrade external Postgres database - fail: + ansible.builtin.fail: msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Check Postgres auto-upgrade backup data directory - stat: + ansible.builtin.stat: path: "{{ postgres_auto_upgrade_backup_data_path }}" register: result_auto_upgrade_path - name: Abort, if existing Postgres auto-upgrade data path detected - fail: + ansible.builtin.fail: msg: "Detected that a left-over {{ postgres_auto_upgrade_backup_data_path }} exists. You should rename it to {{ matrix_postgres_data_path }} if the previous upgrade went wrong, or delete it if it went well." when: "result_auto_upgrade_path.stat.exists" -- import_tasks: tasks/util/detect_existing_postgres_version.yml +- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml - name: Abort, if no existing Postgres version detected - fail: + ansible.builtin.fail: msg: "Could not find existing Postgres installation" - when: "not matrix_postgres_detected_existing|bool" + when: "not matrix_postgres_detected_existing | bool" - name: Abort, if already at latest Postgres version - fail: + ansible.builtin.fail: msg: "You are already running the latest Postgres version supported ({{ matrix_postgres_docker_image_latest }}). Nothing to do" when: "matrix_postgres_detected_version_corresponding_docker_image == matrix_postgres_docker_image_latest and not postgres_force_upgrade" -- debug: +- ansible.builtin.debug: msg: "Upgrading database from {{ matrix_postgres_detected_version_corresponding_docker_image }} to {{ matrix_postgres_docker_image_latest }}" - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false @@ -78,41 +78,49 @@ # role (`matrix_postgres_connection_username`) and database (`matrix_postgres_db_name`) by itself on startup, # we need to remove these from the dump, or we'll get errors saying these already exist. - name: Perform Postgres database dump - command: >- - {{ matrix_host_command_docker }} run --rm --name matrix-postgres-dump - --log-driver=none - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} - --network={{ matrix_docker_network }} - --env-file={{ matrix_postgres_base_path }}/env-postgres-psql - --entrypoint=/bin/sh - --mount type=bind,src={{ postgres_dump_dir }},dst=/out - {{ matrix_postgres_detected_version_corresponding_docker_image }} - -c "pg_dumpall -h matrix-postgres - {{ '| gzip -c ' if postgres_dump_name.endswith('.gz') else '' }} - > /out/{{ postgres_dump_name }}" + ansible.builtin.command: + cmd: >- + {{ matrix_host_command_docker }} run --rm --name matrix-postgres-dump + --log-driver=none + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --network={{ matrix_docker_network }} + --env-file={{ matrix_postgres_base_path }}/env-postgres-psql + --entrypoint=/bin/sh + --mount type=bind,src={{ postgres_dump_dir }},dst=/out + {{ matrix_postgres_detected_version_corresponding_docker_image }} + -c "pg_dumpall -h matrix-postgres + {{ '| gzip -c ' if postgres_dump_name.endswith('.gz') else '' }} + > /out/{{ postgres_dump_name }}" + register: matrix_postgres_upgrade_postgres_dump_command_result + changed_when: matrix_postgres_upgrade_postgres_dump_command_result.rc == 0 + tags: + - skip_ansible_lint - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped - name: Rename existing Postgres data directory - command: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}" + ansible.builtin.command: + cmd: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}" + register: matrix_postgres_upgrade_postgres_move_command_result + changed_when: matrix_postgres_upgrade_postgres_move_command_result.rc == 0 -- debug: +- ansible.builtin.debug: msg: "NOTE: Your Postgres data directory has been moved from `{{ matrix_postgres_data_path }}` to `{{ postgres_auto_upgrade_backup_data_path }}`. In the event of failure, you can move it back and run the playbook with --tags=setup-postgres to restore operation." -- import_tasks: tasks/setup_postgres.yml +- ansible.builtin.import_tasks: tasks/setup_postgres.yml - name: Ensure matrix-postgres autoruns and is restarted - service: + ansible.builtin.service: name: matrix-postgres enabled: true state: restarted daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false @@ -122,7 +130,7 @@ # The dump most likely contains those same entries and would try to re-create them, leading to errors. # We need to skip over those lines. - name: Generate Postgres database import command - set_fact: + ansible.builtin.set_fact: matrix_postgres_import_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-postgres-import --log-driver=none @@ -138,6 +146,8 @@ grep -vE '{{ matrix_postgres_import_roles_ignore_regex }}' | grep -vE '{{ matrix_postgres_import_databases_ignore_regex }}' | psql -v ON_ERROR_STOP=1 -h matrix-postgres" + tags: + - skip_ansible_lint # This is a hack. # See: https://ansibledaily.com/print-to-standard-output-without-escaping/ @@ -145,7 +155,7 @@ # We want to run `debug: msg=".."`, but that dumps it as JSON and escapes double quotes within it, # which ruins the command (`matrix_postgres_import_command`) - name: Note about Postgres importing - set_fact: + ansible.builtin.set_fact: dummy: true with_items: - >- @@ -155,18 +165,21 @@ and restore the automatically-made backup (`mv {{ postgres_auto_upgrade_backup_data_path }} {{ matrix_postgres_data_path }}`). - name: Perform Postgres database import - command: "{{ matrix_postgres_import_command }}" + ansible.builtin.command: + cmd: "{{ matrix_postgres_import_command }}" + register: matrix_postgres_upgrade_postgres_import_command_result + changed_when: matrix_postgres_upgrade_postgres_import_command_result.rc == 0 - name: Delete Postgres database dump file - file: + ansible.builtin.file: path: "{{ postgres_dump_dir }}/{{ postgres_dump_name }}" state: absent - name: Ensure matrix-synapse is started - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true -- debug: +- ansible.builtin.debug: msg: "NOTE: Your old Postgres data directory is preserved at `{{ postgres_auto_upgrade_backup_data_path }}`. You might want to get rid of it once you've confirmed that all is well." diff --git a/roles/matrix-postgres/tasks/util/create_additional_database.yml b/roles/matrix-postgres/tasks/util/create_additional_database.yml index 22b3c9a2..da95b870 100644 --- a/roles/matrix-postgres/tasks/util/create_additional_database.yml +++ b/roles/matrix-postgres/tasks/util/create_additional_database.yml @@ -3,7 +3,7 @@ # It'd be better if this is belonged to `validate_config.yml`, but it would have to be some loop-within-a-loop there, # and that's ugly. We also don't expect this to catch errors often. It's more of a defensive last-minute check. - name: Fail if additional database data appears invalid - fail: + ansible.builtin.fail: msg: "Additional database definition ({{ additional_db }} lacks a required key: {{ item }}" when: "item not in additional_db" with_items: "{{ ['name', 'username', 'password'] }}" @@ -12,7 +12,7 @@ # This file will be mounted into the container and fed to Postgres. # This way, we avoid passing sensitive data around in CLI commands that other users on the system can see. - name: Create additional database initialization SQL file for {{ additional_db.name }} - template: + ansible.builtin.template: src: "{{ role_path }}/templates/sql/init-additional-db-user-and-role.sql.j2" dest: "/tmp/matrix-postgres-init-additional-db-user-and-role.sql" mode: 0600 @@ -20,7 +20,7 @@ group: "{{ matrix_user_gid }}" - name: Execute Postgres additional database initialization SQL file for {{ additional_db.name }} - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -33,8 +33,9 @@ {{ matrix_postgres_docker_image_to_use }} -c 'psql -h {{ matrix_postgres_connection_hostname }} --file=/matrix-postgres-init-additional-db-user-and-role.sql' + changed_when: true - name: Delete additional database initialization SQL file for {{ additional_db.name }} - file: + ansible.builtin.file: path: /tmp/matrix-postgres-init-additional-db-user-and-role.sql state: absent diff --git a/roles/matrix-postgres/tasks/util/create_additional_databases.yml b/roles/matrix-postgres/tasks/util/create_additional_databases.yml index de87f98c..7fe5713e 100644 --- a/roles/matrix-postgres/tasks/util/create_additional_databases.yml +++ b/roles/matrix-postgres/tasks/util/create_additional_databases.yml @@ -1,21 +1,21 @@ --- - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ matrix_postgres_additional_databases_postgres_start_wait_timeout_seconds }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Create additional Postgres user and database - include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml" with_items: "{{ matrix_postgres_additional_databases }}" loop_control: loop_var: additional_db diff --git a/roles/matrix-postgres/tasks/validate_config.yml b/roles/matrix-postgres/tasks/validate_config.yml index eac4dd5b..f239b116 100644 --- a/roles/matrix-postgres/tasks/validate_config.yml +++ b/roles/matrix-postgres/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Warn about matrix_postgres_use_external usage - fail: + ansible.builtin.fail: msg: > The `matrix_postgres_use_external` variable defined in your configuration is not used by this playbook anymore! You'll need to adapt to the new way of using an external Postgres server. @@ -13,7 +13,7 @@ # This is separate (from the other required variables below), # because we'd like to have a friendlier message for our existing users. - name: Fail if matrix_postgres_connection_password not defined - fail: + ansible.builtin.fail: msg: >- The playbook no longer has a default Postgres password defined in the `matrix_postgres_connection_password` variable, among lots of other Postgres changes. You need to perform multiple manual steps to resolve this. @@ -22,7 +22,7 @@ when: "matrix_postgres_connection_password == ''" - name: Fail if required Postgres settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -34,6 +34,6 @@ - "matrix_postgres_db_name" - name: Fail if Postgres password length exceeded - fail: + ansible.builtin.fail: msg: "The maximum `matrix_postgres_connection_password` length is 99 characters" when: "matrix_postgres_connection_password|length > 99" diff --git a/roles/matrix-postgres/templates/usr-local-bin/matrix-change-user-admin-status.j2 b/roles/matrix-postgres/templates/usr-local-bin/matrix-change-user-admin-status.j2 index 6c3082ef..f378a10f 100644 --- a/roles/matrix-postgres/templates/usr-local-bin/matrix-change-user-admin-status.j2 +++ b/roles/matrix-postgres/templates/usr-local-bin/matrix-change-user-admin-status.j2 @@ -9,7 +9,7 @@ if [ $# -ne 2 ]; then fi docker run \ - -it \ + -i \ --rm \ --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ --cap-drop=ALL \ diff --git a/roles/matrix-prometheus-node-exporter/defaults/main.yml b/roles/matrix-prometheus-node-exporter/defaults/main.yml index 5e50a1d7..c7d6512f 100644 --- a/roles/matrix-prometheus-node-exporter/defaults/main.yml +++ b/roles/matrix-prometheus-node-exporter/defaults/main.yml @@ -1,6 +1,7 @@ --- # matrix-prometheus-node-exporter is an Prometheus exporter for machine metrics # See: https://prometheus.io/docs/guides/node-exporter/ +# Project source code URL: https://github.com/prometheus/node_exporter matrix_prometheus_node_exporter_enabled: false @@ -11,15 +12,35 @@ matrix_prometheus_node_exporter_docker_image_force_pull: "{{ matrix_prometheus_n # A list of extra arguments to pass to the container matrix_prometheus_node_exporter_container_extra_arguments: [] +# A list of extra arguments to pass to the node_exporter process +# +# Example: +# matrix_prometheus_node_exporter_process_extra_arguments: +# - "--collector.systemd" +# - "--collector.logind" +# +# Note: the above is just an example. Various collectors may require various tweaks to be able to run. +# Running the systemd collector requires the following `matrix_prometheus_node_exporter_container_extra_arguments`: +# - the socket to be mounted as well (`--mount type=bind,src=/var/run/dbus/system_bus_socket,dst=/var/run/dbus/system_bus_socket,ro,bind-propagation=rslave`) +# - (on AppArmor-based distros) disabling AppArmor protection (`--security-opt apparmor=unconfined`) +matrix_prometheus_node_exporter_process_extra_arguments: [] + # List of systemd services that matrix-prometheus.service depends on matrix_prometheus_node_exporter_systemd_required_services_list: ['docker.service'] # List of systemd services that matrix-prometheus.service wants matrix_prometheus_node_exporter_systemd_wanted_services_list: [] +# Controls whether node-exporter metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/node-exporter`. +# This will only work take effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. +# See the `matrix-nginx-proxy` role for details about enabling `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. +matrix_prometheus_node_exporter_metrics_proxying_enabled: false + # Controls whether the matrix-prometheus container exposes its HTTP port (tcp/9100 in the container). # -# Takes an ":" value (e.g. "127.0.0.1:9100"), or empty string to not expose. +# Takes an ":" value (e.g. "127.0.0.1:9100"), just a port number or empty string to not expose. +# +# You likely don't need to do this. See `matrix_prometheus_node_exporter_metrics_proxying_enabled`. # # Official recommendations are to run this container with `--net=host`, # but we don't do that, since it: @@ -33,3 +54,9 @@ matrix_prometheus_node_exporter_systemd_wanted_services_list: [] # because node-exporter can't see all interfaces, etc. # For now, we'll live with that, until someone develops a better solution. matrix_prometheus_node_exporter_container_http_host_bind_port: '' + +# If you are supplying your own NGINX proxy but want to use the provided exporters you will have to supply an ":" value for the containers to bind to on your host. +# If matrix_prometheus_node_exporter_container_http_host_bind_port is set to just a port number, this will default to "127.0.0.1:" +# If matrix_prometheus_node_exporter_container_http_host_bind_port is set to an IP that is not 0.0.0.0 and a port, that ":" value will be used +# Otherwise this value will be empty and you will have to manually configure your NGINX config file. (If you are using the config files generated by this playbook, you will have to edit matrix-domain.conf) +matrix_prometheus_node_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host: "{{ '127.0.0.1' + matrix_prometheus_node_exporter_container_http_host_bind_port_number_raw if not ':' in matrix_prometheus_node_exporter_container_http_host_bind_port else (matrix_prometheus_node_exporter_container_http_host_bind_port if matrix_prometheus_node_exporter_container_http_host_bind_port.split(':')[0] != '0.0.0.0' else '') }}" diff --git a/roles/matrix-prometheus-node-exporter/tasks/init.yml b/roles/matrix-prometheus-node-exporter/tasks/init.yml index db44a7ab..42f21667 100644 --- a/roles/matrix-prometheus-node-exporter/tasks/init.yml +++ b/roles/matrix-prometheus-node-exporter/tasks/init.yml @@ -1,5 +1,41 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-prometheus-node-exporter.service'] }}" - when: matrix_prometheus_node_exporter_enabled|bool + when: matrix_prometheus_node_exporter_enabled | bool + +- block: + - name: Fail if matrix-nginx-proxy role already executed + ansible.builtin.fail: + msg: >- + Trying to append node-exporter's 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-prometheus-node-exporter role. + when: matrix_nginx_proxy_role_executed | default(False) | bool + + - name: Generate node-exporter metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/node-exporter) + ansible.builtin.set_fact: + matrix_prometheus_node_exporter_nginx_metrics_configuration_block: | + location /metrics/node-exporter { + {% 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-prometheus-node-exporter:9100"; + proxy_pass http://$backend/metrics; + {% elif matrix_prometheus_node_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host != '' %} + proxy_pass http://{{ matrix_prometheus_node_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host }}/metrics; + {% else %} + return 404 "matrix-nginx-proxy is disabled and no host port was bound to the container, so metrics are unavailable"; + {% endif %} + } + + - name: Register node-exporter metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/node-exporter) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | + {{ + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + + + [matrix_prometheus_node_exporter_nginx_metrics_configuration_block] + }} + when: matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_metrics_proxying_enabled | bool diff --git a/roles/matrix-prometheus-node-exporter/tasks/main.yml b/roles/matrix-prometheus-node-exporter/tasks/main.yml index 71bbb8d7..81b0c702 100644 --- a/roles/matrix-prometheus-node-exporter/tasks/main.yml +++ b/roles/matrix-prometheus-node-exporter/tasks/main.yml @@ -1,10 +1,10 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-prometheus-node-exporter diff --git a/roles/matrix-prometheus-node-exporter/tasks/setup.yml b/roles/matrix-prometheus-node-exporter/tasks/setup.yml index 21d0b55d..0c6e77fc 100644 --- a/roles/matrix-prometheus-node-exporter/tasks/setup.yml +++ b/roles/matrix-prometheus-node-exporter/tasks/setup.yml @@ -10,50 +10,50 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_prometheus_node_exporter_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_prometheus_node_exporter_docker_image_force_pull }}" - when: "matrix_prometheus_node_exporter_enabled|bool" + when: "matrix_prometheus_node_exporter_enabled | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-prometheus-node-exporter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-prometheus-node-exporter.service.j2" dest: "{{ matrix_systemd_path }}/matrix-prometheus-node-exporter.service" mode: 0644 register: matrix_prometheus_node_exporter_systemd_service_result - when: matrix_prometheus_node_exporter_enabled|bool + when: matrix_prometheus_node_exporter_enabled | bool - name: Ensure systemd reloaded after matrix-prometheus.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_systemd_service_result.changed" + when: "matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_systemd_service_result.changed" # # Tasks related to getting rid of matrix-prometheus-node-exporter (if it was previously enabled) # - name: Check existence of matrix-prometheus-node-exporter service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-prometheus-node-exporter.service" register: matrix_prometheus_node_exporter_service_stat - name: Ensure matrix-prometheus-node-exporter is stopped - service: + ansible.builtin.service: name: matrix-prometheus-node-exporter state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_service_stat.stat.exists" - name: Ensure matrix-prometheus-node-exporter.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-prometheus-node-exporter.service" state: absent - when: "not matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-prometheus-node-exporter.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_service_stat.stat.exists" diff --git a/roles/matrix-prometheus-node-exporter/templates/systemd/matrix-prometheus-node-exporter.service.j2 b/roles/matrix-prometheus-node-exporter/templates/systemd/matrix-prometheus-node-exporter.service.j2 index e38b42e3..d0bfa4cc 100644 --- a/roles/matrix-prometheus-node-exporter/templates/systemd/matrix-prometheus-node-exporter.service.j2 +++ b/roles/matrix-prometheus-node-exporter/templates/systemd/matrix-prometheus-node-exporter.service.j2 @@ -32,7 +32,7 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-prometheus-nod --pid=host \ --mount type=bind,src=/,dst=/host,ro,bind-propagation=rslave \ {{ matrix_prometheus_node_exporter_docker_image }} \ - --path.rootfs=/host + --path.rootfs=/host {{ matrix_prometheus_node_exporter_process_extra_arguments|join(' ') }} ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-prometheus-node-exporter 2>/dev/null || true' ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-prometheus-node-exporter 2>/dev/null || true' diff --git a/roles/matrix-prometheus-node-exporter/vars/main.yml b/roles/matrix-prometheus-node-exporter/vars/main.yml new file mode 100644 index 00000000..952dc205 --- /dev/null +++ b/roles/matrix-prometheus-node-exporter/vars/main.yml @@ -0,0 +1,5 @@ +--- + +# `matrix_prometheus_node_exporter_container_http_host_bind_port_number_raw` contains the raw port number extracted from `matrix_prometheus_node_exporter_container_http_host_bind_port`, +# which can contain values like this: ('1234', '127.0.0.1:1234', '0.0.0.0:1234') +matrix_prometheus_node_exporter_container_http_host_bind_port_number_raw: "{{ '' if matrix_prometheus_node_exporter_container_http_host_bind_port == '' else (matrix_prometheus_node_exporter_container_http_host_bind_port.split(':')[1] if ':' in matrix_prometheus_node_exporter_container_http_host_bind_port else matrix_prometheus_node_exporter_container_http_host_bind_port) }}" diff --git a/roles/matrix-prometheus-postgres-exporter/defaults/main.yml b/roles/matrix-prometheus-postgres-exporter/defaults/main.yml index c96a6ea8..fbe16ca8 100644 --- a/roles/matrix-prometheus-postgres-exporter/defaults/main.yml +++ b/roles/matrix-prometheus-postgres-exporter/defaults/main.yml @@ -1,10 +1,10 @@ --- # matrix-prometheus-postgres-exporter is an Prometheus exporter for postgres metrics -# See: https://github.com/prometheus-community/postgres_exporter +# Project source code URL: https://github.com/prometheus-community/postgres_exporter matrix_prometheus_postgres_exporter_enabled: false -matrix_prometheus_postgres_exporter_version: v0.10.1 +matrix_prometheus_postgres_exporter_version: v0.11.0 matrix_prometheus_postgres_exporter_port: 9187 matrix_prometheus_postgres_exporter_docker_image: "quay.io/prometheuscommunity/postgres-exporter:{{ matrix_prometheus_postgres_exporter_version }}" @@ -12,8 +12,8 @@ matrix_prometheus_postgres_exporter_docker_image_force_pull: "{{ matrix_promethe # A list of extra arguments to pass to the container matrix_prometheus_postgres_exporter_container_extra_arguments: ["-e PG_EXPORTER_AUTO_DISCOVER_DATABASES=true", - "-e PG_EXPORTER_WEB_LISTEN_ADDRESS=\":{{matrix_prometheus_postgres_exporter_port}}\"", - "-e DATA_SOURCE_NAME=\"postgresql://{{matrix_prometheus_postgres_exporter_database_username}}:{{matrix_prometheus_postgres_exporter_database_password}}@{{matrix_prometheus_postgres_exporter_database_hostname}}:5432/{{matrix_prometheus_postgres_exporter_database_name}}?sslmode=disable\""] + "-e PG_EXPORTER_WEB_LISTEN_ADDRESS=\":{{ matrix_prometheus_postgres_exporter_port }}\"", + "-e DATA_SOURCE_NAME=\"postgresql://{{ matrix_prometheus_postgres_exporter_database_username }}:{{ matrix_prometheus_postgres_exporter_database_password }}@{{ matrix_prometheus_postgres_exporter_database_hostname }}:5432/{{ matrix_prometheus_postgres_exporter_database_name }}?sslmode=disable\""] # List of systemd services that matrix-prometheus-postgres-exporter.service depends on matrix_prometheus_postgres_exporter_systemd_required_services_list: ['docker.service'] @@ -28,15 +28,21 @@ matrix_prometheus_postgres_exporter_database_hostname: 'matrix-postgres' matrix_prometheus_postgres_exporter_database_port: 5432 matrix_prometheus_postgres_exporter_database_name: 'matrix_prometheus_postgres_exporter' +# Controls whether postgres-exporter metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/postgres-exporter`. +# This will only work take effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. +# See the `matrix-nginx-proxy` role for details about enabling `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. +matrix_prometheus_postgres_exporter_metrics_proxying_enabled: false -# Controls whether the matrix-prometheus container exposes its HTTP port (tcp/9100 in the container). +# Controls whether the matrix-prometheus container exposes its HTTP port (tcp/9187 in the container). # -# Takes an ":" value (e.g. "127.0.0.1:9100"), or empty string to not expose. +# Takes an ":" value (e.g. "127.0.0.1:9187"), just a port number or an empty string to not expose. +# +# You likely don't need to do this. See `matrix_prometheus_postgres_exporter_metrics_proxying_enabled`. # # Official recommendations are to run this container with `--net=host`, # but we don't do that, since it: # - likely exposes the metrics web server way too publicly (before applying https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/1008) -# - or listens on a loopback interface only (--net=host and 127.0.0.1:9100), which is not reachable from another container (like `matrix-prometheus`) +# - or listens on a loopback interface only (--net=host and 127.0.0.1:9187), which is not reachable from another container (like `matrix-prometheus`) # # Using `--net=host` and binding to Docker's `matrix` bridge network may be a solution to both, # but that's trickier to accomplish and won't necessarily work (hasn't been tested). @@ -46,5 +52,11 @@ matrix_prometheus_postgres_exporter_database_name: 'matrix_prometheus_postgres_e # For now, we'll live with that, until someone develops a better solution. matrix_prometheus_postgres_exporter_container_http_host_bind_port: '' +# If you are supplying your own NGINX proxy but want to use the provided exporters you will have to supply an ":" value for the containers to bind to on your host. +# If matrix_prometheus_postgres_exporter_container_http_host_bind_port is set to just a port number, this will default to "127.0.0.1:" +# If matrix_prometheus_postgres_exporter_container_http_host_bind_port is set to an IP that is not 0.0.0.0 and a port, that ":" value will be used +# Otherwise this value will be empty and you will have to manually configure your NGINX config file. (If you are using the config files generated by this playbook, you will have to edit matrix-domain.conf) +matrix_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host: "{{ '127.0.0.1' + matrix_prometheus_postgres_exporter_container_http_host_bind_port_number_raw if not ':' in matrix_prometheus_postgres_exporter_container_http_host_bind_port else (matrix_prometheus_postgres_exporter_container_http_host_bind_port if matrix_prometheus_postgres_exporter_container_http_host_bind_port.split(':')[0] != '0.0.0.0' else '') }}" + matrix_prometheus_postgres_exporter_dashboard_urls: - "https://grafana.com/api/dashboards/9628/revisions/7/download" diff --git a/roles/matrix-prometheus-postgres-exporter/tasks/init.yml b/roles/matrix-prometheus-postgres-exporter/tasks/init.yml index ddea23ab..03fe965c 100644 --- a/roles/matrix-prometheus-postgres-exporter/tasks/init.yml +++ b/roles/matrix-prometheus-postgres-exporter/tasks/init.yml @@ -1,5 +1,41 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-prometheus-postgres-exporter.service'] }}" - when: matrix_prometheus_postgres_exporter_enabled|bool + when: matrix_prometheus_postgres_exporter_enabled | bool + +- block: + - name: Fail if matrix-nginx-proxy role already executed + ansible.builtin.fail: + msg: >- + Trying to append postgres-exporter's 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-prometheus-postgres-exporter role. + when: matrix_nginx_proxy_role_executed | default(False) | bool + + - name: Generate postgres-exporter metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/postgres-exporter) + ansible.builtin.set_fact: + matrix_prometheus_postgres_exporter_nginx_metrics_configuration_block: | + location /metrics/postgres-exporter { + {% 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-prometheus-postgres-exporter:9187"; + proxy_pass http://$backend/metrics; + {% elif matrix_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host != '' %} + proxy_pass http://{{ matrix_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host }}/metrics; + {% else %} + return 404 "matrix-nginx-proxy is disabled and no host port was bound to the container, so metrics are unavailable"; + {% endif %} + } + + - name: Register postgres-exporter metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/postgres-exporter) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | + {{ + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + + + [matrix_prometheus_postgres_exporter_nginx_metrics_configuration_block] + }} + when: matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_metrics_proxying_enabled | bool diff --git a/roles/matrix-prometheus-postgres-exporter/tasks/main.yml b/roles/matrix-prometheus-postgres-exporter/tasks/main.yml index e9497099..43473587 100644 --- a/roles/matrix-prometheus-postgres-exporter/tasks/main.yml +++ b/roles/matrix-prometheus-postgres-exporter/tasks/main.yml @@ -1,10 +1,10 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-prometheus-postgres-exporter diff --git a/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml b/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml index 08ffe708..00a61df6 100644 --- a/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml +++ b/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml @@ -10,50 +10,50 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_prometheus_postgres_exporter_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_prometheus_postgres_exporter_docker_image_force_pull }}" - when: "matrix_prometheus_postgres_exporter_enabled|bool" + when: "matrix_prometheus_postgres_exporter_enabled | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-prometheus-postgres-exporter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-prometheus-postgres-exporter.service.j2" dest: "{{ matrix_systemd_path }}/matrix-prometheus-postgres-exporter.service" mode: 0644 register: matrix_prometheus_postgres_exporter_systemd_service_result - when: matrix_prometheus_postgres_exporter_enabled|bool + when: matrix_prometheus_postgres_exporter_enabled | bool - name: Ensure systemd reloaded after matrix-prometheus.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_systemd_service_result.changed" + when: "matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_systemd_service_result.changed" # # Tasks related to getting rid of matrix-prometheus-postgres-exporter (if it was previously enabled) # - name: Check existence of matrix-prometheus-postgres-exporter service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-prometheus-postgres-exporter.service" register: matrix_prometheus_postgres_exporter_service_stat - name: Ensure matrix-prometheus-postgres-exporter is stopped - service: + ansible.builtin.service: name: matrix-prometheus-postgres-exporter state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" - name: Ensure matrix-prometheus-postgres-exporter.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-prometheus-postgres-exporter.service" state: absent - when: "not matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-prometheus-postgres-exporter.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" diff --git a/roles/matrix-prometheus-postgres-exporter/vars/main.yml b/roles/matrix-prometheus-postgres-exporter/vars/main.yml new file mode 100644 index 00000000..aed3b216 --- /dev/null +++ b/roles/matrix-prometheus-postgres-exporter/vars/main.yml @@ -0,0 +1,5 @@ +--- + +# `matrix_prometheus_postgres_exporter_container_http_host_bind_port_number_raw` contains the raw port number extracted from `matrix_prometheus_postgres_exporter_container_http_host_bind_port`, +# which can contain values like this: ('1234', '127.0.0.1:1234', '0.0.0.0:1234') +matrix_prometheus_postgres_exporter_container_http_host_bind_port_number_raw: "{{ '' if matrix_prometheus_postgres_exporter_container_http_host_bind_port == '' else (matrix_prometheus_postgres_exporter_container_http_host_bind_port.split(':')[1] if ':' in matrix_prometheus_postgres_exporter_container_http_host_bind_port else matrix_prometheus_postgres_exporter_container_http_host_bind_port) }}" diff --git a/roles/matrix-prometheus/defaults/main.yml b/roles/matrix-prometheus/defaults/main.yml index 843a90e8..8f5c2148 100644 --- a/roles/matrix-prometheus/defaults/main.yml +++ b/roles/matrix-prometheus/defaults/main.yml @@ -1,10 +1,11 @@ --- # matrix-prometheus is an open-source systems monitoring and alerting toolkit # See: https://github.com/matrix-org/synapse/blob/master/docs/metrics-howto.md +# Project source code URL: https://github.com/prometheus/prometheus matrix_prometheus_enabled: false -matrix_prometheus_version: v2.33.3 +matrix_prometheus_version: v2.37.0 matrix_prometheus_docker_image: "{{ matrix_container_global_registry_prefix }}prom/prometheus:{{ matrix_prometheus_version }}" matrix_prometheus_docker_image_force_pull: "{{ matrix_prometheus_docker_image.endswith(':latest') }}" @@ -26,6 +27,19 @@ matrix_prometheus_systemd_wanted_services_list: [] # Takes an ":" or "" value (e.g. "127.0.0.1:9090"), or empty string to not expose. matrix_prometheus_container_http_host_bind_port: '' +# A list of default arguments to pass to the prometheus process +matrix_prometheus_process_default_arguments: + - "--config.file=/etc/prometheus/prometheus.yml" + - "--storage.tsdb.path=/prometheus" + - "--web.console.libraries=/usr/share/prometheus/console_libraries" + - "--web.console.templates=/usr/share/prometheus/consoles" + +# A list of extra arguments to pass to the prometheus process +matrix_prometheus_process_extra_arguments: [] + +# holds the final list of process arguments +matrix_prometheus_process_arguments: "{{ matrix_prometheus_process_default_arguments + matrix_prometheus_process_extra_arguments }}" + # Tells whether the "synapse" scraper configuration is enabled. matrix_prometheus_scraper_synapse_enabled: false @@ -61,8 +75,8 @@ matrix_prometheus_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_prometheus_configuration_yaml`. -matrix_prometheus_configuration_extension: "{{ matrix_prometheus_configuration_extension_yaml|from_yaml if matrix_prometheus_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_prometheus_configuration_extension: "{{ matrix_prometheus_configuration_extension_yaml | from_yaml if matrix_prometheus_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_prometheus_configuration_yaml`. -matrix_prometheus_configuration: "{{ matrix_prometheus_configuration_yaml|from_yaml|combine(matrix_prometheus_configuration_extension, recursive=True) }}" +matrix_prometheus_configuration: "{{ matrix_prometheus_configuration_yaml | from_yaml | combine(matrix_prometheus_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-prometheus/tasks/init.yml b/roles/matrix-prometheus/tasks/init.yml index 6587ddd9..29853673 100644 --- a/roles/matrix-prometheus/tasks/init.yml +++ b/roles/matrix-prometheus/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-prometheus.service'] }}" - when: matrix_prometheus_enabled|bool + when: matrix_prometheus_enabled | bool diff --git a/roles/matrix-prometheus/tasks/main.yml b/roles/matrix-prometheus/tasks/main.yml index c74918fa..1a5a3708 100644 --- a/roles/matrix-prometheus/tasks/main.yml +++ b/roles/matrix-prometheus/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_prometheus_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_prometheus_enabled | bool" tags: - setup-all - setup-prometheus -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_prometheus_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_prometheus_enabled | bool" tags: - setup-all - setup-prometheus -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_prometheus_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_prometheus_enabled | bool" tags: - setup-all - setup-prometheus diff --git a/roles/matrix-prometheus/tasks/setup_install.yml b/roles/matrix-prometheus/tasks/setup_install.yml index e0fe8cf6..c3aeaa7a 100644 --- a/roles/matrix-prometheus/tasks/setup_install.yml +++ b/roles/matrix-prometheus/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure Prometheus paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -24,31 +24,35 @@ - "{{ matrix_prometheus_data_path }}" - name: Download synapse-v2.rules - get_url: + ansible.builtin.get_url: url: "{{ matrix_prometheus_scraper_synapse_rules_download_url }}" dest: "{{ matrix_prometheus_config_path }}/synapse-v2.rules" force: true mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: "matrix_prometheus_scraper_synapse_rules_enabled|bool" + when: "matrix_prometheus_scraper_synapse_rules_enabled | bool" + register: result + retries: "{{ matrix_geturl_retries_count }}" + delay: "{{ matrix_geturl_retries_delay }}" + until: result is not failed - name: Ensure prometheus.yml installed - copy: - content: "{{ matrix_prometheus_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_prometheus_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_prometheus_config_path }}/prometheus.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-prometheus.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-prometheus.service.j2" dest: "{{ matrix_systemd_path }}/matrix-prometheus.service" mode: 0644 register: matrix_prometheus_systemd_service_result - name: Ensure systemd reloaded after matrix-prometheus.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_systemd_service_result.changed|bool" + when: "matrix_prometheus_systemd_service_result.changed | bool" diff --git a/roles/matrix-prometheus/tasks/setup_uninstall.yml b/roles/matrix-prometheus/tasks/setup_uninstall.yml index c9f07f52..7dd94459 100644 --- a/roles/matrix-prometheus/tasks/setup_uninstall.yml +++ b/roles/matrix-prometheus/tasks/setup_uninstall.yml @@ -1,26 +1,26 @@ --- - name: Check existence of matrix-prometheus service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-prometheus.service" register: matrix_prometheus_service_stat - name: Ensure matrix-prometheus is stopped - service: + ansible.builtin.service: name: matrix-prometheus state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_prometheus_service_stat.stat.exists|bool" + when: "matrix_prometheus_service_stat.stat.exists | bool" - name: Ensure matrix-prometheus.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-prometheus.service" state: absent - when: "matrix_prometheus_service_stat.stat.exists|bool" + when: "matrix_prometheus_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-prometheus.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_service_stat.stat.exists|bool" + when: "matrix_prometheus_service_stat.stat.exists | bool" diff --git a/roles/matrix-prometheus/tasks/validate_config.yml b/roles/matrix-prometheus/tasks/validate_config.yml index 9fcfe12b..3e386304 100644 --- a/roles/matrix-prometheus/tasks/validate_config.yml +++ b/roles/matrix-prometheus/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if Synapse metrics or Prometheus Node Exporter not enabled - fail: + ansible.builtin.fail: msg: > You need to enable `matrix_prometheus_scraper_synapse_enabled` and/or `matrix_prometheus_scraper_node_enabled` for Prometheus grab metrics. when: "not matrix_prometheus_scraper_synapse_enabled and not matrix_prometheus_scraper_node_enabled" diff --git a/roles/matrix-prometheus/templates/systemd/matrix-prometheus.service.j2 b/roles/matrix-prometheus/templates/systemd/matrix-prometheus.service.j2 index 8de57201..56e13c13 100644 --- a/roles/matrix-prometheus/templates/systemd/matrix-prometheus.service.j2 +++ b/roles/matrix-prometheus/templates/systemd/matrix-prometheus.service.j2 @@ -31,7 +31,7 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-prometheus \ {% for arg in matrix_prometheus_container_extra_arguments %} {{ arg }} \ {% endfor %} - {{ matrix_prometheus_docker_image }} + {{ matrix_prometheus_docker_image }} {{ matrix_prometheus_process_arguments|join(' ') }} ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-prometheus 2>/dev/null || true' ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-prometheus 2>/dev/null || true' diff --git a/roles/matrix-redis/defaults/main.yml b/roles/matrix-redis/defaults/main.yml index 88d3d739..4eefbce4 100644 --- a/roles/matrix-redis/defaults/main.yml +++ b/roles/matrix-redis/defaults/main.yml @@ -1,4 +1,5 @@ --- +# Project source code URL: https://github.com/redis/redis matrix_redis_enabled: true @@ -7,7 +8,7 @@ matrix_redis_connection_password: "" matrix_redis_base_path: "{{ matrix_base_data_path }}/redis" matrix_redis_data_path: "{{ matrix_redis_base_path }}/data" -matrix_redis_version: 6.2.6-alpine +matrix_redis_version: 7.0.4-alpine matrix_redis_docker_image_v6: "{{ matrix_container_global_registry_prefix }}redis:{{ matrix_redis_version }}" matrix_redis_docker_image_latest: "{{ matrix_redis_docker_image_v6 }}" matrix_redis_docker_image_to_use: '{{ matrix_redis_docker_image_latest }}' diff --git a/roles/matrix-redis/tasks/init.yml b/roles/matrix-redis/tasks/init.yml index 99c52026..00154b33 100644 --- a/roles/matrix-redis/tasks/init.yml +++ b/roles/matrix-redis/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-redis'] }}" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool diff --git a/roles/matrix-redis/tasks/main.yml b/roles/matrix-redis/tasks/main.yml index 430b6a64..1bcac7d6 100644 --- a/roles/matrix-redis/tasks/main.yml +++ b/roles/matrix-redis/tasks/main.yml @@ -1,11 +1,11 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_redis.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_redis.yml" + when: run_setup | bool tags: - setup-all - setup-redis diff --git a/roles/matrix-redis/tasks/setup_redis.yml b/roles/matrix-redis/tasks/setup_redis.yml index df1d1736..7dd7ea9f 100644 --- a/roles/matrix-redis/tasks/setup_redis.yml +++ b/roles/matrix-redis/tasks/setup_redis.yml @@ -10,14 +10,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_redis_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_redis_docker_image_force_pull }}" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure redis paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0700 @@ -26,79 +26,79 @@ with_items: - "{{ matrix_redis_base_path }}" - "{{ matrix_redis_data_path }}" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool # We do this as a separate task, because: # - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is) # - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true - name: Ensure redis data path ownership is correct - file: + ansible.builtin.file: path: "{{ matrix_redis_data_path }}" state: directory owner: "{{ matrix_user_username }}" group: "{{ matrix_user_username }}" recurse: true - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool - name: Ensure redis environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/{{ item }}.j2" dest: "{{ matrix_redis_base_path }}/{{ item }}" mode: 0644 with_items: - "redis.conf" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool - name: Ensure matrix-redis.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-redis.service.j2" dest: "{{ matrix_systemd_path }}/matrix-redis.service" mode: 0644 register: matrix_redis_systemd_service_result - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool - name: Ensure systemd reloaded after matrix-redis.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_redis_enabled|bool and matrix_redis_systemd_service_result.changed" + when: "matrix_redis_enabled | bool and matrix_redis_systemd_service_result.changed" # # Tasks related to getting rid of the internal redis server (if it was previously enabled) # - name: Check existence of matrix-redis service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-redis.service" register: matrix_redis_service_stat - when: "not matrix_redis_enabled|bool" + when: "not matrix_redis_enabled | bool" - name: Ensure matrix-redis is stopped - service: + ansible.builtin.service: name: matrix-redis state: stopped enabled: false daemon_reload: true - when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists" - name: Ensure matrix-redis.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-redis.service" state: absent - when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-redis.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists" - name: Check existence of matrix-redis local data path - stat: + ansible.builtin.stat: path: "{{ matrix_redis_data_path }}" register: matrix_redis_data_path_stat - when: "not matrix_redis_enabled|bool" + when: "not matrix_redis_enabled | bool" # We just want to notify the user. Deleting data is too destructive. - name: Notify if matrix-redis local data remains - debug: + ansible.builtin.debug: msg: "Note: You are not using a local redis instance, but some old data remains from before in `{{ matrix_redis_data_path }}`. Feel free to delete it." - when: "not matrix_redis_enabled|bool and matrix_redis_data_path_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_data_path_stat.stat.exists" diff --git a/roles/matrix-registration/defaults/main.yml b/roles/matrix-registration/defaults/main.yml index d924551a..1e53ae98 100644 --- a/roles/matrix-registration/defaults/main.yml +++ b/roles/matrix-registration/defaults/main.yml @@ -1,12 +1,17 @@ --- # matrix-registration is a simple python application to have a token based matrix registration # See: https://zeratax.github.io/matrix-registration/ +# Project source code URL: https://github.com/ZerataX/matrix-registration matrix_registration_enabled: true matrix_registration_container_image_self_build: false matrix_registration_container_image_self_build_repo: "https://github.com/ZerataX/matrix-registration" matrix_registration_container_image_self_build_branch: "{{ 'master' if matrix_registration_version == 'latest' else matrix_registration_version }}" +# Controls whether we'll be patching the dependencies in `setup.py` when self-building. +# Without patching, building will likely fail, because of the poor unbounded way dependencies are defined (e.g. `flask-limiter>=1.1.0`). +# This is an attempt to get matrix-registration in its current (outdated) version to build. +matrix_registration_container_image_self_build_python_dependencies_patch_enabled: true matrix_registration_base_path: "{{ matrix_base_data_path }}/matrix-registration" matrix_registration_config_path: "{{ matrix_registration_base_path }}/config" @@ -110,8 +115,8 @@ matrix_registration_configuration_extension_yaml: | # password: # min_length: 12 -matrix_registration_configuration_extension: "{{ matrix_registration_configuration_extension_yaml|from_yaml if matrix_registration_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_registration_configuration_extension: "{{ matrix_registration_configuration_extension_yaml | from_yaml if matrix_registration_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final matrix-registration configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_registration_configuration_yaml`. -matrix_registration_configuration: "{{ matrix_registration_configuration_yaml|from_yaml|combine(matrix_registration_configuration_extension, recursive=True) }}" +matrix_registration_configuration: "{{ matrix_registration_configuration_yaml | from_yaml | combine(matrix_registration_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-registration/tasks/generate_token.yml b/roles/matrix-registration/tasks/generate_token.yml index 4e337b01..c910bf63 100644 --- a/roles/matrix-registration/tasks/generate_token.yml +++ b/roles/matrix-registration/tasks/generate_token.yml @@ -1,17 +1,17 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `one_time` variable needs to be provided to this playbook, via --extra-vars" when: "one_time is not defined or one_time not in ['yes', 'no']" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `ex_date` variable (expiration date) needs to be provided to this playbook, via --extra-vars" when: "ex_date is not defined or ex_date == ''" - name: Call matrix-registration token creation API - uri: + ansible.builtin.uri: url: "{{ matrix_registration_api_token_endpoint }}" follow_redirects: none validate_certs: "{{ matrix_registration_api_validate_certs }}" @@ -23,12 +23,12 @@ body: | { "one_time": {{ 'true' if one_time == 'yes' else 'false' }}, - "ex_date": {{ ex_date|to_json }} + "ex_date": {{ ex_date | to_json }} } check_mode: false register: matrix_registration_api_result -- set_fact: +- ansible.builtin.set_fact: matrix_registration_api_result_message: >- matrix-registration result: @@ -42,10 +42,10 @@ check_mode: false - name: Inject result message into matrix_playbook_runtime_results - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [matrix_registration_api_result_message] }} diff --git a/roles/matrix-registration/tasks/init.yml b/roles/matrix-registration/tasks/init.yml index 44a887d1..922db0f7 100644 --- a/roles/matrix-registration/tasks/init.yml +++ b/roles/matrix-registration/tasks/init.yml @@ -2,32 +2,32 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Matrix Registration image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_registration_container_image_self_build and matrix_registration_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-registration.service'] }}" - when: matrix_registration_enabled|bool + when: matrix_registration_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append matrix-registration's 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-registration role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate matrix-registration proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_registration_matrix_nginx_proxy_configuration: | rewrite ^{{ matrix_registration_public_endpoint }}$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_registration_public_endpoint }}/ permanent; rewrite ^{{ matrix_registration_public_endpoint }}/$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_registration_public_endpoint }}/register redirect; location ~ ^{{ matrix_registration_public_endpoint }}/(.*) { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-registration:5000"; @@ -47,23 +47,23 @@ } - name: Register matrix-registration proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_registration_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_registration_enabled|bool + when: matrix_registration_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the matrix-registration tool but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_registration_public_endpoint }}` URL endpoint to the matrix-registration container. You can expose the container's port using the `matrix_registration_container_http_host_bind_port` variable. - when: "matrix_registration_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_registration_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-registration/tasks/list_tokens.yml b/roles/matrix-registration/tasks/list_tokens.yml index 9ef40d27..4bcd1460 100644 --- a/roles/matrix-registration/tasks/list_tokens.yml +++ b/roles/matrix-registration/tasks/list_tokens.yml @@ -1,7 +1,7 @@ --- - name: Call matrix-registration list all tokens API - uri: + ansible.builtin.uri: url: "{{ matrix_registration_api_token_endpoint }}" follow_redirects: none validate_certs: "{{ matrix_registration_api_validate_certs }}" @@ -13,7 +13,7 @@ check_mode: false register: matrix_registration_api_result -- set_fact: +- ansible.builtin.set_fact: matrix_registration_api_result_message: >- matrix-registration result: @@ -21,10 +21,10 @@ check_mode: false - name: Inject result message into matrix_playbook_runtime_results - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [matrix_registration_api_result_message] }} diff --git a/roles/matrix-registration/tasks/main.yml b/roles/matrix-registration/tasks/main.yml index ca574384..99b89e3d 100644 --- a/roles/matrix-registration/tasks/main.yml +++ b/roles/matrix-registration/tasks/main.yml @@ -1,33 +1,33 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - setup-all - setup-matrix-registration -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - setup-all - setup-matrix-registration -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_registration_enabled | bool" tags: - setup-all - setup-matrix-registration -- import_tasks: "{{ role_path }}/tasks/generate_token.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/generate_token.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - generate-matrix-registration-token -- import_tasks: "{{ role_path }}/tasks/list_tokens.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/list_tokens.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - list-matrix-registration-tokens diff --git a/roles/matrix-registration/tasks/setup_install.yml b/roles/matrix-registration/tasks/setup_install.yml index 6ff2de30..d3048337 100644 --- a/roles/matrix-registration/tasks/setup_install.yml +++ b/roles/matrix-registration/tasks/setup_install.yml @@ -1,20 +1,20 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_registration_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_registration_sqlite_database_path_local }}" register: matrix_registration_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_registration_sqlite_database_path_local }}" dst: "{{ matrix_registration_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_registration_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-registration.service'] @@ -24,15 +24,17 @@ - ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE; additional_psql_statements_db_name: "{{ matrix_registration_database_name }}" - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_registration_requires_restart: true - when: "matrix_registration_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_registration_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_registration_database_engine == 'postgres'" - name: Ensure matrix-registration paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -43,7 +45,7 @@ - {path: "{{ matrix_registration_config_path }}", when: true} - {path: "{{ matrix_registration_data_path }}", when: true} - {path: "{{ matrix_registration_docker_src_files_path }}", when: "{{ matrix_registration_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure matrix-registration image is pulled docker_image: @@ -51,14 +53,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_registration_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_registration_docker_image_force_pull }}" - when: "not matrix_registration_container_image_self_build|bool" + when: "not matrix_registration_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-registration repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_registration_container_image_self_build_repo }}" dest: "{{ matrix_registration_docker_src_files_path }}" version: "{{ matrix_registration_container_image_self_build_branch }}" @@ -66,7 +68,15 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_registration_git_pull_results - when: "matrix_registration_container_image_self_build|bool" + when: "matrix_registration_container_image_self_build | bool" + +# See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1864 +- name: Patch setup.py to allow self-built version to work + ansible.builtin.lineinfile: + path: "{{ matrix_registration_docker_src_files_path }}/setup.py" + regexp: 'flask-limiter' + line: '"flask-limiter~=1.1.0", "Markupsafe<2.1",' + when: "matrix_registration_container_image_self_build | bool and matrix_registration_container_image_self_build_python_dependencies_patch_enabled | bool" - name: Ensure matrix-registration Docker image is built docker_image: @@ -78,30 +88,30 @@ dockerfile: Dockerfile path: "{{ matrix_registration_docker_src_files_path }}" pull: true - when: "matrix_registration_container_image_self_build|bool" + when: "matrix_registration_container_image_self_build | bool" - name: Ensure matrix-registration config installed - copy: - content: "{{ matrix_registration_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_registration_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_registration_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-registration.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2" dest: "{{ matrix_systemd_path }}/matrix-registration.service" mode: 0644 register: matrix_registration_systemd_service_result - name: Ensure systemd reloaded after matrix-registration.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_registration_systemd_service_result.changed|bool" + when: "matrix_registration_systemd_service_result.changed | bool" - name: Ensure matrix-registration.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-registration.service" state: restarted - when: "matrix_registration_requires_restart|bool" + when: "matrix_registration_requires_restart | bool" diff --git a/roles/matrix-registration/tasks/setup_uninstall.yml b/roles/matrix-registration/tasks/setup_uninstall.yml index 4b7c195f..e3d713dc 100644 --- a/roles/matrix-registration/tasks/setup_uninstall.yml +++ b/roles/matrix-registration/tasks/setup_uninstall.yml @@ -1,29 +1,29 @@ --- - name: Check existence of matrix-registration service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-registration.service" register: matrix_registration_service_stat - name: Ensure matrix-registration is stopped - service: + ansible.builtin.service: name: matrix-registration state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_registration_service_stat.stat.exists|bool" + when: "matrix_registration_service_stat.stat.exists | bool" - name: Ensure matrix-registration.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-registration.service" state: absent - when: "matrix_registration_service_stat.stat.exists|bool" + when: "matrix_registration_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-registration.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_registration_service_stat.stat.exists|bool" + when: "matrix_registration_service_stat.stat.exists | bool" - name: Ensure matrix-registration Docker image doesn't exist docker_image: diff --git a/roles/matrix-registration/tasks/validate_config.yml b/roles/matrix-registration/tasks/validate_config.yml index 90466b46..eb140d31 100644 --- a/roles/matrix-registration/tasks/validate_config.yml +++ b/roles/matrix-registration/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required matrix-registration settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) for using matrix-registration. when: "vars[item] == ''" @@ -11,7 +11,7 @@ - "matrix_registration_server_location" - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). diff --git a/roles/matrix-sygnal/defaults/main.yml b/roles/matrix-sygnal/defaults/main.yml index 15bce68c..1268d602 100644 --- a/roles/matrix-sygnal/defaults/main.yml +++ b/roles/matrix-sygnal/defaults/main.yml @@ -1,14 +1,14 @@ --- # Sygnal is a reference Push Gateway for Matrix. # To make use of it for delivering push notificatins, you'll need to develop/build your own Matrix app. -# Learn more here: https://github.com/matrix-org/sygnal +# Project source code URL: https://github.com/matrix-org/sygnal matrix_sygnal_enabled: false matrix_sygnal_base_path: "{{ matrix_base_data_path }}/sygnal" matrix_sygnal_config_path: "{{ matrix_sygnal_base_path }}/config" matrix_sygnal_data_path: "{{ matrix_sygnal_base_path }}/data" -matrix_sygnal_version: v0.11.0 +matrix_sygnal_version: v0.12.0 matrix_sygnal_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/sygnal:{{ matrix_sygnal_version }}" matrix_sygnal_docker_image_force_pull: "{{ matrix_sygnal_docker_image.endswith(':latest') }}" @@ -69,8 +69,8 @@ matrix_sygnal_configuration_extension_yaml: | # opentracing: # enabled: true -matrix_sygnal_configuration_extension: "{{ matrix_sygnal_configuration_extension_yaml|from_yaml if matrix_sygnal_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_sygnal_configuration_extension: "{{ matrix_sygnal_configuration_extension_yaml | from_yaml if matrix_sygnal_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final sygnal configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_sygnal_configuration_yaml`. -matrix_sygnal_configuration: "{{ matrix_sygnal_configuration_yaml|from_yaml|combine(matrix_sygnal_configuration_extension, recursive=True) }}" +matrix_sygnal_configuration: "{{ matrix_sygnal_configuration_yaml | from_yaml | combine(matrix_sygnal_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-sygnal/tasks/init.yml b/roles/matrix-sygnal/tasks/init.yml index efa17a4d..dae7a299 100644 --- a/roles/matrix-sygnal/tasks/init.yml +++ b/roles/matrix-sygnal/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-sygnal.service'] }}" - when: matrix_sygnal_enabled|bool + when: matrix_sygnal_enabled | bool diff --git a/roles/matrix-sygnal/tasks/main.yml b/roles/matrix-sygnal/tasks/main.yml index 38579822..b001bb82 100644 --- a/roles/matrix-sygnal/tasks/main.yml +++ b/roles/matrix-sygnal/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-sygnal -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: run_setup|bool and matrix_sygnal_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: run_setup | bool and matrix_sygnal_enabled | bool tags: - setup-all - setup-sygnal -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: run_setup|bool and not matrix_sygnal_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: run_setup | bool and not matrix_sygnal_enabled | bool tags: - setup-all - setup-sygnal diff --git a/roles/matrix-sygnal/tasks/setup_install.yml b/roles/matrix-sygnal/tasks/setup_install.yml index 1a6ce186..8f5f6937 100644 --- a/roles/matrix-sygnal/tasks/setup_install.yml +++ b/roles/matrix-sygnal/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure Sygnal paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -24,21 +24,21 @@ - "{{ matrix_sygnal_data_path }}" - name: Ensure Sygnal config installed - copy: - content: "{{ matrix_sygnal_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_sygnal_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_sygnal_config_path }}/sygnal.yaml" mode: 0640 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-sygnal.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-sygnal.service.j2" dest: "{{ matrix_systemd_path }}/matrix-sygnal.service" mode: 0644 register: matrix_sygnal_systemd_service_result - name: Ensure systemd reloaded after matrix-sygnal.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_sygnal_systemd_service_result.changed|bool" + when: "matrix_sygnal_systemd_service_result.changed | bool" diff --git a/roles/matrix-sygnal/tasks/setup_uninstall.yml b/roles/matrix-sygnal/tasks/setup_uninstall.yml index 5a81a1b2..eff4a74b 100644 --- a/roles/matrix-sygnal/tasks/setup_uninstall.yml +++ b/roles/matrix-sygnal/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-sygnal service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-sygnal.service" register: matrix_sygnal_service_stat - name: Ensure matrix-sygnal is stopped - service: + ansible.builtin.service: name: matrix-sygnal state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_sygnal_service_stat.stat.exists|bool" + when: "matrix_sygnal_service_stat.stat.exists | bool" - name: Ensure matrix-sygnal.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-sygnal.service" state: absent - when: "matrix_sygnal_service_stat.stat.exists|bool" + when: "matrix_sygnal_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-sygnal.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_sygnal_service_stat.stat.exists|bool" + when: "matrix_sygnal_service_stat.stat.exists | bool" - name: Ensure Sygnal base directory doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_sygnal_base_path }}" state: absent diff --git a/roles/matrix-sygnal/tasks/validate_config.yml b/roles/matrix-sygnal/tasks/validate_config.yml index 2121edf4..b2c38010 100644 --- a/roles/matrix-sygnal/tasks/validate_config.yml +++ b/roles/matrix-sygnal/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if no Sygnal apps defined - fail: + ansible.builtin.fail: msg: >- Enabling Sygnal requires that you specify at least one app in `matrix_sygnal_apps` when: "matrix_sygnal_enabled and matrix_sygnal_apps|length == 0" diff --git a/roles/matrix-synapse-admin/defaults/main.yml b/roles/matrix-synapse-admin/defaults/main.yml index 0aa19e86..9f4510b6 100644 --- a/roles/matrix-synapse-admin/defaults/main.yml +++ b/roles/matrix-synapse-admin/defaults/main.yml @@ -1,6 +1,6 @@ --- # matrix-synapse-admin is a web UI for mananging the Synapse Matrix server -# See: https://github.com/Awesome-Technologies/synapse-admin +# Project source code URL: https://github.com/Awesome-Technologies/synapse-admin matrix_synapse_admin_enabled: true diff --git a/roles/matrix-synapse-admin/tasks/init.yml b/roles/matrix-synapse-admin/tasks/init.yml index de8c0046..f934eced 100644 --- a/roles/matrix-synapse-admin/tasks/init.yml +++ b/roles/matrix-synapse-admin/tasks/init.yml @@ -2,31 +2,31 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: - msg: "To self-build the Element image, you should use Ansible 2.8 or higher. See docs/ansible.md" + ansible.builtin.fail: + msg: "To self-build the Synapse Admin image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_synapse_admin_container_image_self_build and matrix_synapse_admin_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-synapse-admin.service'] }}" - when: matrix_synapse_admin_enabled|bool + when: matrix_synapse_admin_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Synapse Admin's 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-synapse-admin role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Synapse Admin proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_synapse_admin_matrix_nginx_proxy_configuration: | rewrite ^{{ matrix_synapse_admin_public_endpoint }}$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_synapse_admin_public_endpoint }}/ permanent; location ~ ^{{ matrix_synapse_admin_public_endpoint }}/(.*) { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-synapse-admin:80"; @@ -38,23 +38,23 @@ } - name: Register Synapse Admin proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_synapse_admin_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_synapse_admin_enabled|bool + when: matrix_synapse_admin_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Synapse Admin tool but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_synapse_admin_public_endpoint }}` URL endpoint to the matrix-synapse-admin container. You can expose the container's port using the `matrix_synapse_admin_container_http_host_bind_port` variable. - when: "matrix_synapse_admin_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_synapse_admin_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-synapse-admin/tasks/main.yml b/roles/matrix-synapse-admin/tasks/main.yml index 0095f753..0c6bd942 100644 --- a/roles/matrix-synapse-admin/tasks/main.yml +++ b/roles/matrix-synapse-admin/tasks/main.yml @@ -1,16 +1,16 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-synapse-admin -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-synapse-admin diff --git a/roles/matrix-synapse-admin/tasks/setup.yml b/roles/matrix-synapse-admin/tasks/setup.yml index f83ccdc3..66021272 100644 --- a/roles/matrix-synapse-admin/tasks/setup.yml +++ b/roles/matrix-synapse-admin/tasks/setup.yml @@ -10,14 +10,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_synapse_admin_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_synapse_admin_docker_image_force_pull }}" - when: "matrix_synapse_admin_enabled|bool and not matrix_synapse_admin_container_image_self_build|bool" + when: "matrix_synapse_admin_enabled | bool and not matrix_synapse_admin_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-synapse-admin repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_synapse_admin_container_image_self_build_repo }}" dest: "{{ matrix_synapse_admin_docker_src_files_path }}" version: "{{ matrix_synapse_admin_docker_image.split(':')[1] }}" @@ -25,7 +25,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_synapse_admin_git_pull_results - when: "matrix_synapse_admin_enabled|bool and matrix_synapse_admin_container_image_self_build|bool" + when: "matrix_synapse_admin_enabled | bool and matrix_synapse_admin_container_image_self_build | bool" - name: Ensure matrix-synapse-admin Docker image is built docker_image: @@ -37,52 +37,52 @@ dockerfile: Dockerfile path: "{{ matrix_synapse_admin_docker_src_files_path }}" pull: true - when: "matrix_synapse_admin_enabled|bool and matrix_synapse_admin_container_image_self_build|bool" + when: "matrix_synapse_admin_enabled | bool and matrix_synapse_admin_container_image_self_build | bool" - name: Ensure matrix-synapse-admin.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-synapse-admin.service.j2" dest: "{{ matrix_systemd_path }}/matrix-synapse-admin.service" mode: 0644 register: matrix_synapse_admin_systemd_service_result - when: matrix_synapse_admin_enabled|bool + when: matrix_synapse_admin_enabled | bool - name: Ensure systemd reloaded after matrix-synapse-admin.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_synapse_admin_enabled|bool and matrix_synapse_admin_systemd_service_result.changed" + when: "matrix_synapse_admin_enabled | bool and matrix_synapse_admin_systemd_service_result.changed" # # Tasks related to getting rid of matrix-synapse-admin (if it was previously enabled) # - name: Check existence of matrix-synapse-admin service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-synapse-admin.service" register: matrix_synapse_admin_service_stat - name: Ensure matrix-synapse-admin is stopped - service: + ansible.builtin.service: name: matrix-synapse-admin state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_synapse_admin_enabled|bool and matrix_synapse_admin_service_stat.stat.exists" + when: "not matrix_synapse_admin_enabled | bool and matrix_synapse_admin_service_stat.stat.exists" - name: Ensure matrix-synapse-admin.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-synapse-admin.service" state: absent - when: "not matrix_synapse_admin_enabled|bool and matrix_synapse_admin_service_stat.stat.exists" + when: "not matrix_synapse_admin_enabled | bool and matrix_synapse_admin_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-synapse-admin.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_synapse_admin_enabled|bool and matrix_synapse_admin_service_stat.stat.exists" + when: "not matrix_synapse_admin_enabled | bool and matrix_synapse_admin_service_stat.stat.exists" - name: Ensure matrix-synapse-admin Docker image doesn't exist docker_image: name: "{{ matrix_synapse_admin_docker_image }}" state: absent - when: "not matrix_synapse_admin_enabled|bool" + when: "not matrix_synapse_admin_enabled | bool" diff --git a/roles/matrix-synapse-admin/tasks/validate_config.yml b/roles/matrix-synapse-admin/tasks/validate_config.yml index 20a5c170..bf5fe69e 100644 --- a/roles/matrix-synapse-admin/tasks/validate_config.yml +++ b/roles/matrix-synapse-admin/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). diff --git a/roles/matrix-synapse/defaults/main.yml b/roles/matrix-synapse/defaults/main.yml index 9e332669..99ce80c0 100644 --- a/roles/matrix-synapse/defaults/main.yml +++ b/roles/matrix-synapse/defaults/main.yml @@ -1,6 +1,6 @@ --- # Synapse is a Matrix homeserver -# See: https://github.com/matrix-org/synapse +# Project source code URL: https://github.com/matrix-org/synapse matrix_synapse_enabled: true @@ -9,7 +9,7 @@ matrix_synapse_container_image_self_build_repo: "https://github.com/matrix-org/s matrix_synapse_docker_image: "{{ matrix_synapse_docker_image_name_prefix }}matrixdotorg/synapse:{{ matrix_synapse_docker_image_tag }}" matrix_synapse_docker_image_name_prefix: "{{ 'localhost/' if matrix_synapse_container_image_self_build else matrix_container_global_registry_prefix }}" -matrix_synapse_version: v1.56.0 +matrix_synapse_version: v1.64.0 matrix_synapse_docker_image_tag: "{{ matrix_synapse_version }}" matrix_synapse_docker_image_force_pull: "{{ matrix_synapse_docker_image.endswith(':latest') }}" @@ -74,7 +74,7 @@ matrix_synapse_in_container_python_packages_path: "/usr/local/lib/python3.9/site # Specifies which template files to use when configuring Synapse. # If you'd like to have your own different configuration, feel free to copy and paste # the original files into your inventory (e.g. in `inventory/host_vars//`) -# and then change the specific host's `vars.yaml` file like this: +# and then change the specific host's `vars.yml` file like this: # matrix_synapse_template_synapse_homeserver: "{{ playbook_dir }}/inventory/host_vars//homeserver.yaml.j2" matrix_synapse_template_synapse_homeserver: "{{ role_path }}/templates/synapse/homeserver.yaml.j2" matrix_synapse_template_synapse_log: "{{ role_path }}/templates/synapse/synapse.log.config.j2" @@ -86,6 +86,14 @@ matrix_synapse_form_secret: "{{ matrix_synapse_macaroon_secret_key }}" matrix_synapse_max_upload_size_mb: 50 +# Controls whether local media should be removed under certain conditions, typically for the purpose of saving space. +# should be empty to disable +matrix_synapse_media_retention_local_media_lifetime: +# Controls whether remote media cache (media that is downloaded from other homeservers) +# should be removed under certain conditions, typically for the purpose of saving space. +# should be empty to disable +matrix_synapse_media_retention_remote_media_lifetime: + # The tmpfs at /tmp needs to be large enough to handle multiple concurrent file uploads. matrix_synapse_tmp_directory_size_mb: "{{ matrix_synapse_max_upload_size_mb * 50 }}" @@ -215,9 +223,6 @@ matrix_synapse_recaptcha_private_key: '' # Disabling this option will not delete any tokens previously generated. matrix_synapse_registration_requires_token: false -# Allows non-server-admin users to create groups on this server -matrix_synapse_enable_group_creation: false - # A list of 3PID types which users must supply when registering (possible values: email, msisdn). matrix_synapse_registrations_require_3pid: [] @@ -329,6 +334,14 @@ matrix_url_preview_accept_language: ['en-US', 'en'] matrix_synapse_metrics_enabled: false matrix_synapse_metrics_port: 9100 +# Controls whether Synapse metrics should be proxied (exposed) on: +# - `matrix.DOMAIN/metrics/synapse/main-process` for the main process +# - `matrix.DOMAIN/metrics/synapse/worker/{type}-{id}` for each worker process +# +# This will only work take effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. +# See the `matrix-nginx-proxy` role for details about enabling `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. +matrix_synapse_metrics_proxying_enabled: false + # Enable the Synapse manhole # See https://github.com/matrix-org/synapse/blob/master/docs/manhole.md matrix_synapse_manhole_enabled: false @@ -358,10 +371,13 @@ matrix_synapse_workers_presets: one-of-each: generic_workers_count: 1 pusher_workers_count: 1 - appservice_workers_count: 1 + # appservice workers are deprecated since Synapse v1.59. This will be removed. + appservice_workers_count: 0 federation_sender_workers_count: 1 media_repository_workers_count: 1 # Disabled until https://github.com/matrix-org/synapse/issues/8787 is resolved. + # user_dir workers are deprecated since Synapse v1.59. This will be removed. + # See: https://github.com/matrix-org/synapse/blob/v1.59.0/docs/upgrade.md#deprecation-of-the-synapseappappservice-and-synapseappuser_dir-worker-application-types user_dir_workers_count: 0 frontend_proxy_workers_count: 1 @@ -383,7 +399,9 @@ matrix_synapse_workers_pusher_workers_count: "{{ matrix_synapse_workers_presets[ matrix_synapse_workers_pusher_workers_metrics_range_start: 19200 # matrix_synapse_workers_appservice_workers_count can only be 0 or 1. More instances are not supported. -matrix_synapse_workers_appservice_workers_count: "{{ matrix_synapse_workers_presets[matrix_synapse_workers_preset]['appservice_workers_count'] }}" +# appservice workers are deprecated since Synapse v1.59. This will be removed. +# See: https://github.com/matrix-org/synapse/blob/v1.59.0/docs/upgrade.md#deprecation-of-the-synapseappappservice-and-synapseappuser_dir-worker-application-types +matrix_synapse_workers_appservice_workers_count: 0 matrix_synapse_workers_appservice_workers_metrics_range_start: 19300 # matrix_synapse_workers_federation_sender_workers_count can only be 0 or 1 for now. @@ -397,7 +415,9 @@ matrix_synapse_workers_media_repository_workers_port_range_start: 18551 matrix_synapse_workers_media_repository_workers_metrics_range_start: 19551 # Disabled until https://github.com/matrix-org/synapse/issues/8787 is resolved. -matrix_synapse_workers_user_dir_workers_count: "{{ matrix_synapse_workers_presets[matrix_synapse_workers_preset]['user_dir_workers_count'] }}" +# user_dir workers are deprecated since Synapse v1.59. This will be removed. +# See: https://github.com/matrix-org/synapse/blob/v1.59.0/docs/upgrade.md#deprecation-of-the-synapseappappservice-and-synapseappuser_dir-worker-application-types +matrix_synapse_workers_user_dir_workers_count: 0 matrix_synapse_workers_user_dir_workers_port_range_start: 18661 matrix_synapse_workers_user_dir_workers_metrics_range_start: 19661 @@ -501,11 +521,11 @@ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret: "" matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled: true # We'd like to enable this, but it causes trouble for Element: https://github.com/vector-im/element-web/issues/19605 matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled: false -matrix_synapse_ext_password_provider_shared_secret_config: "{{ matrix_synapse_ext_password_provider_shared_secret_config_yaml|from_yaml }}" +matrix_synapse_ext_password_provider_shared_secret_config: "{{ matrix_synapse_ext_password_provider_shared_secret_config_yaml | from_yaml }}" matrix_synapse_ext_password_provider_shared_secret_config_yaml: | - shared_secret: {{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret|string|to_json }} - m_login_password_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled|to_json }} - com_devture_shared_secret_auth_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled|to_json }} + shared_secret: {{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret | string | to_json }} + m_login_password_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled | to_json }} + com_devture_shared_secret_auth_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled | to_json }} # Enable this to activate LDAP password provider matrix_synapse_ext_password_provider_ldap_enabled: false @@ -552,7 +572,7 @@ matrix_synapse_ext_spam_checker_mjolnir_antispam_config_ban_lists: [] # Enable this to activate the E2EE disabling Synapse module. # See: https://github.com/digitalentity/matrix_encryption_disabler matrix_synapse_ext_encryption_disabler_enabled: false -matrix_synapse_ext_encryption_disabler_download_url: "https://raw.githubusercontent.com/digitalentity/matrix_encryption_disabler/1182388f7019e8ec1e28f035070c7919d0e4cc24/matrix_e2ee_filter.py" +matrix_synapse_ext_encryption_disabler_download_url: "https://raw.githubusercontent.com/digitalentity/matrix_encryption_disabler/cdc37a07441acb7c2a3288bcb29b376658d5e766/matrix_e2ee_filter.py" # A list of server domain names for which to deny encryption if the event sender's domain matches the domain in the list. # By default, with the configuration below, we prevent all homeserver users from initiating encryption in ANY room. matrix_synapse_ext_encryption_disabler_deny_encryption_for_users_of: ["{{ matrix_domain }}"] @@ -566,11 +586,11 @@ matrix_synapse_ext_encryption_disabler_deny_encryption_for_rooms_of: ["{{ matrix # Enabling this may have incompatiblity consequences with servers / clients. # Familiarize yourself with the caveats upstream: https://github.com/digitalentity/matrix_encryption_disabler matrix_synapse_ext_encryption_disabler_patch_power_levels: false -matrix_synapse_ext_encryption_config: "{{ matrix_synapse_ext_encryption_config_yaml|from_yaml }}" +matrix_synapse_ext_encryption_config: "{{ matrix_synapse_ext_encryption_config_yaml | from_yaml }}" matrix_synapse_ext_encryption_config_yaml: | - deny_encryption_for_users_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_users_of|to_json }} - deny_encryption_for_rooms_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_rooms_of|to_json }} - patch_power_levels: {{ matrix_synapse_ext_encryption_disabler_patch_power_levels|to_json }} + deny_encryption_for_users_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_users_of | to_json }} + deny_encryption_for_rooms_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_rooms_of | to_json }} + patch_power_levels: {{ matrix_synapse_ext_encryption_disabler_patch_power_levels | to_json }} matrix_s3_media_store_enabled: false @@ -658,8 +678,8 @@ matrix_synapse_configuration_extension_yaml: | # system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ" # room_name: "Server Notices" -matrix_synapse_configuration_extension: "{{ matrix_synapse_configuration_extension_yaml|from_yaml if matrix_synapse_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_synapse_configuration_extension: "{{ matrix_synapse_configuration_extension_yaml | from_yaml if matrix_synapse_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final Synapse configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_synapse_configuration_yaml`. -matrix_synapse_configuration: "{{ matrix_synapse_configuration_yaml|from_yaml|combine(matrix_synapse_configuration_extension, recursive=True) }}" +matrix_synapse_configuration: "{{ matrix_synapse_configuration_yaml | from_yaml | combine(matrix_synapse_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-synapse/files/workers-doc-to-yaml.awk b/roles/matrix-synapse/files/workers-doc-to-yaml.awk index ca58b486..5b99d396 100755 --- a/roles/matrix-synapse/files/workers-doc-to-yaml.awk +++ b/roles/matrix-synapse/files/workers-doc-to-yaml.awk @@ -120,7 +120,7 @@ enable_parsing { worker_stanza_append(" # " line linefeed) # and take note of words hinting at additional conditions to be met - if (line ~ /(^| )[Ii]f |(^| )[Ff]or /) { + if (line ~ /(^[Ii]f|care must be taken|can be handled for)/) { endpoints_seem_conditional = 1 } } diff --git a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml index 8fda082d..e0e61df8 100644 --- a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml +++ b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_install.yml" - when: matrix_synapse_ext_encryption_disabler_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_install.yml" + when: matrix_synapse_ext_encryption_disabler_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_uninstall.yml" - when: "not matrix_synapse_ext_encryption_disabler_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_uninstall.yml" + when: "not matrix_synapse_ext_encryption_disabler_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml index dfc15a20..00cc1650 100644 --- a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml @@ -1,18 +1,22 @@ --- - name: Download matrix_encryption_disabler - get_url: + ansible.builtin.get_url: url: "{{ matrix_synapse_ext_encryption_disabler_download_url }}" dest: "{{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py" force: true mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" + register: result + retries: "{{ matrix_geturl_retries_count }}" + delay: "{{ matrix_geturl_retries_delay }}" + until: result is not failed -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_modules: | {{ - matrix_synapse_modules|default([]) + matrix_synapse_modules | default([]) + [ { @@ -23,11 +27,15 @@ }} matrix_synapse_container_extra_arguments: > - {{ matrix_synapse_container_extra_arguments|default([]) }} - + - ["--mount type=bind,src={{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py,dst={{ matrix_synapse_in_container_python_packages_path }}/matrix_e2ee_filter.py,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py,dst={{ matrix_synapse_in_container_python_packages_path }}/matrix_e2ee_filter.py,ro"] + }} matrix_synapse_additional_loggers: > - {{ matrix_synapse_additional_loggers }} - + - {{ [{'name': 'matrix_e2ee_filter', 'level': 'INFO'}] }} + {{ + matrix_synapse_additional_loggers + + + [{'name': 'matrix_e2ee_filter', 'level': 'INFO'}] + }} diff --git a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml index a532464d..c223f6e8 100644 --- a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure matrix_encryption_disabler doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py" state: absent diff --git a/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml b/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml index 374c9e55..5d648c84 100644 --- a/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml +++ b/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml @@ -1,10 +1,12 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_password_providers_enabled: true matrix_synapse_additional_loggers: > - {{ matrix_synapse_additional_loggers }} - + - {{ [{'name': 'ldap_auth_provider', 'level': 'INFO'}] }} - when: matrix_synapse_ext_password_provider_ldap_enabled|bool + {{ + matrix_synapse_additional_loggers + + + [{'name': 'ldap_auth_provider', 'level': 'INFO'}] + }} + when: matrix_synapse_ext_password_provider_ldap_enabled | bool diff --git a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml index 6c45f469..1a3e097d 100644 --- a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml +++ b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_install.yml" - when: matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_install.yml" + when: matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_uninstall.yml" - when: "not matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_uninstall.yml" + when: "not matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml index ec298ccd..3869f1aa 100644 --- a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure git installed (RedHat) - yum: + ansible.builtin.yum: name: - git state: present @@ -9,7 +9,7 @@ when: "ansible_os_family == 'RedHat'" - name: Ensure git installed (Debian) - apt: + ansible.builtin.apt: name: - git state: present @@ -25,28 +25,32 @@ when: "ansible_distribution == 'Archlinux'" - name: Clone mjolnir-antispam git repository - git: + ansible.builtin.git: repo: "{{ matrix_synapse_ext_spam_checker_mjolnir_antispam_git_repository_url }}" version: "{{ matrix_synapse_ext_spam_checker_mjolnir_antispam_git_version }}" dest: "{{ matrix_synapse_ext_path }}/mjolnir" become: true become_user: "{{ matrix_user_username }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_spam_checker: > - {{ matrix_synapse_spam_checker }} - + - [{ - "module": "mjolnir.AntiSpam", - "config": { - "block_invites": {{ matrix_synapse_ext_spam_checker_mjolnir_antispam_config_block_invites }}, - "block_messages": {{ matrix_synapse_ext_spam_checker_mjolnir_antispam_config_block_messages }}, - "block_usernames": {{ matrix_synapse_ext_spam_checker_mjolnir_antispam_config_block_usernames }}, - "ban_lists": {{ matrix_synapse_ext_spam_checker_mjolnir_antispam_config_ban_lists }} - } - }] + {{ + matrix_synapse_spam_checker + + + [{ + "module": "mjolnir.AntiSpam", + "config": { + "block_invites": matrix_synapse_ext_spam_checker_mjolnir_antispam_config_block_invites, + "block_messages": matrix_synapse_ext_spam_checker_mjolnir_antispam_config_block_messages, + "block_usernames": matrix_synapse_ext_spam_checker_mjolnir_antispam_config_block_usernames, + "ban_lists": matrix_synapse_ext_spam_checker_mjolnir_antispam_config_ban_lists, + } + }] + }} matrix_synapse_container_extra_arguments: > - {{ matrix_synapse_container_extra_arguments|default([]) }} - + - ["--mount type=bind,src={{ matrix_synapse_ext_path }}/mjolnir/synapse_antispam/mjolnir,dst={{ matrix_synapse_in_container_python_packages_path }}/mjolnir,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/mjolnir/synapse_antispam/mjolnir,dst={{ matrix_synapse_in_container_python_packages_path }}/mjolnir,ro"] + }} diff --git a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml index f8439a87..8211d51a 100644 --- a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure mjolnir-antispam doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/mjolnir" state: absent diff --git a/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml b/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml index 0270784a..6df360ce 100644 --- a/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml +++ b/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_install.yml" - when: matrix_synapse_ext_password_provider_rest_auth_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_install.yml" + when: matrix_synapse_ext_password_provider_rest_auth_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_uninstall.yml" - when: "not matrix_synapse_ext_password_provider_rest_auth_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_uninstall.yml" + when: "not matrix_synapse_ext_password_provider_rest_auth_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml b/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml index 634b1ca5..489f1140 100644 --- a/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml @@ -1,28 +1,36 @@ --- - name: Fail if REST Auth endpoint not configured - fail: + ansible.builtin.fail: msg: "You have enabled the REST Auth password provider, but have not configured its endpoint in the `matrix_synapse_ext_password_provider_rest_auth_endpoint` variable. Consult the documentation." when: "matrix_synapse_ext_password_provider_rest_auth_endpoint == ''" - name: Download matrix-synapse-rest-auth - get_url: + ansible.builtin.get_url: url: "{{ matrix_synapse_ext_password_provider_rest_auth_download_url }}" dest: "{{ matrix_synapse_ext_path }}/rest_auth_provider.py" force: true mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" + register: result + retries: "{{ matrix_geturl_retries_count }}" + delay: "{{ matrix_geturl_retries_delay }}" + until: result is not failed -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_password_providers_enabled: true matrix_synapse_container_extra_arguments: > - {{ matrix_synapse_container_extra_arguments|default([]) }} - + - ["--mount type=bind,src={{ matrix_synapse_ext_path }}/rest_auth_provider.py,dst={{ matrix_synapse_in_container_python_packages_path }}/rest_auth_provider.py,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/rest_auth_provider.py,dst={{ matrix_synapse_in_container_python_packages_path }}/rest_auth_provider.py,ro"] + }} matrix_synapse_additional_loggers: > - {{ matrix_synapse_additional_loggers }} - + - {{ [{'name': 'rest_auth_provider', 'level': 'INFO'}] }} + {{ + matrix_synapse_additional_loggers + + + [{'name': 'rest_auth_provider', 'level': 'INFO'}] + }} diff --git a/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml index be8ad600..d95dd1c7 100644 --- a/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure matrix-synapse-rest-auth doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/rest_auth_provider.py" state: absent diff --git a/roles/matrix-synapse/tasks/ext/setup.yml b/roles/matrix-synapse/tasks/ext/setup.yml index 25c8809d..d944f257 100644 --- a/roles/matrix-synapse/tasks/ext/setup.yml +++ b/roles/matrix-synapse/tasks/ext/setup.yml @@ -1,13 +1,13 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/ldap-auth/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/ldap-auth/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup.yml" diff --git a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml index ed8d0197..6dc385d3 100644 --- a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml +++ b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_install.yml" - when: matrix_synapse_ext_password_provider_shared_secret_auth_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_install.yml" + when: matrix_synapse_ext_password_provider_shared_secret_auth_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_uninstall.yml" - when: "not matrix_synapse_ext_password_provider_shared_secret_auth_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_uninstall.yml" + when: "not matrix_synapse_ext_password_provider_shared_secret_auth_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml index f408e2f9..055d671a 100644 --- a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml @@ -1,28 +1,32 @@ --- - name: Fail if Shared Secret Auth secret not set - fail: + ansible.builtin.fail: msg: "Shared Secret Auth is enabled, but no secret has been set in matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret" when: "matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret == ''" - name: Fail if no Shared Secret Auth login types enabled - fail: + ansible.builtin.fail: msg: "Shared Secret Auth is enabled, but none of the login types are" when: "not (matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled or matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled)" - name: Download matrix-synapse-shared-secret-auth - get_url: + ansible.builtin.get_url: url: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_download_url }}" dest: "{{ matrix_synapse_ext_path }}/shared_secret_authenticator.py" force: true mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" + register: result + retries: "{{ matrix_geturl_retries_count }}" + delay: "{{ matrix_geturl_retries_delay }}" + until: result is not failed -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_modules: | {{ - matrix_synapse_modules|default([]) + matrix_synapse_modules | default([]) + [ { @@ -33,11 +37,15 @@ }} matrix_synapse_container_extra_arguments: > - {{ matrix_synapse_container_extra_arguments|default([]) }} - + - ["--mount type=bind,src={{ matrix_synapse_ext_path }}/shared_secret_authenticator.py,dst={{ matrix_synapse_in_container_python_packages_path }}/shared_secret_authenticator.py,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/shared_secret_authenticator.py,dst={{ matrix_synapse_in_container_python_packages_path }}/shared_secret_authenticator.py,ro"] + }} matrix_synapse_additional_loggers: > - {{ matrix_synapse_additional_loggers }} - + - {{ [{'name': 'shared_secret_authenticator', 'level': 'INFO'}] }} + {{ + matrix_synapse_additional_loggers + + + [{'name': 'shared_secret_authenticator', 'level': 'INFO'}] + }} diff --git a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml index e564909e..b2f90944 100644 --- a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure matrix-synapse-shared-secret-auth doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/shared_secret_authenticator.py" state: absent diff --git a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml index efd4a027..038eea74 100644 --- a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml +++ b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_install.yml" - when: matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_install.yml" + when: matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_uninstall.yml" - when: "not matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_uninstall.yml" + when: "not matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml index 740d9474..23a382f2 100644 --- a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml @@ -1,12 +1,12 @@ --- - name: Fail if Synapse Simple Antispam blocked homeservers is not set - fail: + ansible.builtin.fail: msg: "Synapse Simple Antispam is enabled, but no blocked homeservers have been set in matrix_synapse_ext_spam_checker_synapse_simple_antispam_config_blocked_homeservers" when: "matrix_synapse_ext_spam_checker_synapse_simple_antispam_config_blocked_homeservers|length == 0" - name: Ensure git installed (RedHat) - yum: + ansible.builtin.yum: name: - git state: present @@ -14,7 +14,7 @@ when: "ansible_os_family == 'RedHat'" - name: Ensure git installed (Debian) - apt: + ansible.builtin.apt: name: - git state: present @@ -30,25 +30,29 @@ when: "ansible_distribution == 'Archlinux'" - name: Clone synapse-simple-antispam git repository - git: + ansible.builtin.git: repo: "{{ matrix_synapse_ext_spam_checker_synapse_simple_antispam_git_repository_url }}" version: "{{ matrix_synapse_ext_spam_checker_synapse_simple_antispam_git_version }}" dest: "{{ matrix_synapse_ext_path }}/synapse-simple-antispam" become: true become_user: "{{ matrix_user_username }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_modules: > - {{ matrix_synapse_modules }} - + - [{ - "module": "synapse_simple_antispam.AntiSpamInvites", - "config": { - "blocked_homeservers": {{ matrix_synapse_ext_spam_checker_synapse_simple_antispam_config_blocked_homeservers }} - } - }] + {{ + matrix_synapse_modules + + + [{ + "module": "synapse_simple_antispam.AntiSpamInvites", + "config": { + "blocked_homeservers": matrix_synapse_ext_spam_checker_synapse_simple_antispam_config_blocked_homeservers + } + }] + }} matrix_synapse_container_extra_arguments: > - {{ matrix_synapse_container_extra_arguments|default([]) }} - + - ["--mount type=bind,src={{ matrix_synapse_ext_path }}/synapse-simple-antispam/synapse_simple_antispam,dst={{ matrix_synapse_in_container_python_packages_path }}/synapse_simple_antispam,ro"] + {{ + matrix_synapse_container_extra_arguments | default([]) + + + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/synapse-simple-antispam/synapse_simple_antispam,dst={{ matrix_synapse_in_container_python_packages_path }}/synapse_simple_antispam,ro"] + }} diff --git a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml index 14cefc72..b1d558aa 100644 --- a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure synapse-simple-antispam doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/synapse-simple-antispam" state: absent diff --git a/roles/matrix-synapse/tasks/goofys/setup.yml b/roles/matrix-synapse/tasks/goofys/setup.yml index 6370408d..2f9eaa87 100644 --- a/roles/matrix-synapse/tasks/goofys/setup.yml +++ b/roles/matrix-synapse/tasks/goofys/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/goofys/setup_install.yml" - when: matrix_s3_media_store_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/goofys/setup_install.yml" + when: matrix_s3_media_store_enabled | bool -- import_tasks: "{{ role_path }}/tasks/goofys/setup_uninstall.yml" - when: "not matrix_s3_media_store_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/goofys/setup_uninstall.yml" + when: "not matrix_s3_media_store_enabled | bool" diff --git a/roles/matrix-synapse/tasks/goofys/setup_install.yml b/roles/matrix-synapse/tasks/goofys/setup_install.yml index d3781520..e3c34150 100644 --- a/roles/matrix-synapse/tasks/goofys/setup_install.yml +++ b/roles/matrix-synapse/tasks/goofys/setup_install.yml @@ -1,6 +1,6 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_fuse_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_fuse_installed.yml" - name: Ensure Goofys Docker image is pulled docker_image: @@ -15,13 +15,13 @@ # This will throw a Permission Denied error if already mounted - name: Check Matrix Goofys external storage mountpoint path - stat: + ansible.builtin.stat: path: "{{ matrix_s3_media_store_path }}" register: local_path_matrix_s3_media_store_path_stat ignore_errors: true - name: Ensure Matrix Goofys external storage mountpoint exists - file: + ansible.builtin.file: path: "{{ matrix_s3_media_store_path }}" state: directory mode: 0750 @@ -30,20 +30,20 @@ when: "not local_path_matrix_s3_media_store_path_stat.failed and not local_path_matrix_s3_media_store_path_stat.stat.exists" - name: Ensure goofys environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/goofys/env-goofys.j2" dest: "{{ matrix_synapse_config_dir_path }}/env-goofys" owner: root mode: 0600 - name: Ensure matrix-goofys.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/goofys/systemd/matrix-goofys.service.j2" dest: "{{ matrix_systemd_path }}/matrix-goofys.service" mode: 0644 register: matrix_goofys_systemd_service_result - name: Ensure systemd reloaded after matrix-goofys.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_goofys_systemd_service_result.changed" diff --git a/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml b/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml index c00206ef..da78003f 100644 --- a/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-goofys service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-goofys.service" register: matrix_goofys_service_stat - name: Ensure matrix-goofys is stopped - service: + ansible.builtin.service: name: matrix-goofys state: stopped enabled: false @@ -15,18 +15,18 @@ when: "matrix_goofys_service_stat.stat.exists" - name: Ensure matrix-goofys.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-goofys.service" state: absent when: "matrix_goofys_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-goofys.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_goofys_service_stat.stat.exists" - name: Ensure goofys environment variables file doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_config_dir_path }}/env-goofys" state: absent diff --git a/roles/matrix-synapse/tasks/import_media_store.yml b/roles/matrix-synapse/tasks/import_media_store.yml index 8e962680..133debe3 100644 --- a/roles/matrix-synapse/tasks/import_media_store.yml +++ b/roles/matrix-synapse/tasks/import_media_store.yml @@ -3,37 +3,37 @@ # Pre-checks - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `server_path_media_store` variable needs to be provided to this playbook, via --extra-vars" when: "server_path_media_store is not defined or server_path_media_store.startswith('<')" - name: Fail if media store is on Amazon S3 - fail: + ansible.builtin.fail: msg: "Your media store is on Amazon S3. Due to technical limitations, restoring is not supported." - when: matrix_s3_media_store_enabled|bool + when: matrix_s3_media_store_enabled | bool - name: Check if the provided media store directory exists - stat: + ansible.builtin.stat: path: "{{ server_path_media_store }}" register: server_path_media_store_stat - name: Fail if provided media store directory doesn't exist on the server - fail: + ansible.builtin.fail: msg: "{{ server_path_media_store }} cannot be found on the server" when: "not server_path_media_store_stat.stat.exists or not server_path_media_store_stat.stat.isdir" - name: Check if media store contains local_content - stat: + ansible.builtin.stat: path: "{{ server_path_media_store }}/local_content" register: server_path_media_store_local_content_stat - name: Check if media store contains remote_content - stat: + ansible.builtin.stat: path: "{{ server_path_media_store }}/remote_content" register: server_path_media_store_remote_content_stat - name: Fail if media store directory doesn't look okay (lacking remote and local content) - fail: + ansible.builtin.fail: msg: "{{ server_path_media_store }} contains neither local_content nor remote_content directories. It's most likely a mistake and is not a media store directory." when: "not server_path_media_store_local_content_stat.stat.exists and not server_path_media_store_remote_content_stat.stat.exists" @@ -41,7 +41,7 @@ # Actual import work - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped enabled: false @@ -57,25 +57,25 @@ delete: true # It's wasteful to preserve owner/group now. We chown below anyway. owner: false - group: false + ansible.builtin.group: false times: true delegate_to: "{{ inventory_hostname }}" # This is for the generic case and fails in other cases (remote file systems), # because in such cases the base path (matrix_synapse_media_store_path) is a mount point. - name: Ensure media store permissions are correct (generic case) - file: + ansible.builtin.file: path: "{{ matrix_synapse_media_store_path }}" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" recurse: true - when: "not matrix_s3_media_store_enabled|bool" + when: "not matrix_s3_media_store_enabled | bool" # We don't chown for Goofys, because due to the way it's mounted, # all files become owned by whoever needs to own them. - name: Ensure Synapse is started (if it previously was) - service: + ansible.builtin.service: name: "{{ item }}" state: started daemon_reload: true diff --git a/roles/matrix-synapse/tasks/init.yml b/roles/matrix-synapse/tasks/init.yml index 88065049..77696bce 100644 --- a/roles/matrix-synapse/tasks/init.yml +++ b/roles/matrix-synapse/tasks/init.yml @@ -2,26 +2,86 @@ # See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070 # and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407 - name: Fail if trying to self-build on Ansible < 2.8 - fail: + ansible.builtin.fail: msg: "To self-build the Synapse image, you should use Ansible 2.8 or higher. See docs/ansible.md" when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_synapse_container_image_self_build and matrix_synapse_enabled" # Unless `matrix_synapse_workers_enabled_list` is explicitly defined, # we'll generate it dynamically. -- import_tasks: "{{ role_path }}/tasks/synapse/workers/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/workers/init.yml" when: "matrix_synapse_enabled and matrix_synapse_workers_enabled and matrix_synapse_workers_enabled_list|length == 0" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-synapse.service'] }}" - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool - name: Ensure systemd services for workers are injected - include_tasks: "{{ role_path }}/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml" with_items: "{{ matrix_synapse_workers_enabled_list }}" loop_control: loop_var: matrix_synapse_worker_details - when: matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool + when: matrix_synapse_enabled | bool and matrix_synapse_workers_enabled | bool -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-goofys.service'] }}" - when: matrix_s3_media_store_enabled|bool + when: matrix_s3_media_store_enabled | bool + +- block: + - name: Fail if matrix-nginx-proxy role already executed + ansible.builtin.fail: + msg: >- + Trying to append Synapse's 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-synapse role. + when: matrix_nginx_proxy_role_executed | default(False) | bool + + - name: Generate synapse metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/main-process) + ansible.builtin.set_fact: + matrix_synapse_nginx_metrics_configuration_block: | + location /metrics/synapse/main-process { + {% 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-synapse:{{ matrix_synapse_metrics_port }}"; + proxy_pass http://$backend/_synapse/metrics; + {% else %} + {# Generic configuration for use outside of our container setup #} + proxy_pass http://127.0.0.1:{{ matrix_synapse_metrics_port }}/_synapse/metrics; + {% endif %} + } + + - name: Register synapse metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/main-process) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | + {{ + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + + + [matrix_synapse_nginx_metrics_configuration_block] + }} + + - name: Generate synapse worker metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/worker) + ansible.builtin.set_fact: + matrix_synapse_worker_nginx_metrics_configuration_block: | + {% for worker in matrix_synapse_workers_enabled_list %} + {% if worker.metrics_port != 0 %} + location /metrics/synapse/worker/{{ worker.type }}-{{ worker.instanceId }} { + resolver 127.0.0.11 valid=5s; + set $backend "matrix-synapse-worker-{{ worker.type }}-{{ worker.instanceId }}:{{ worker.metrics_port }}"; + proxy_pass http://$backend/_synapse/metrics; + proxy_set_header Host $host; + } + {% endif %} + {% endfor %} + when: matrix_synapse_workers_enabled_list|length > 0 + + - name: Register synapse worker metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/worker) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | + {{ + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + + + [matrix_synapse_worker_nginx_metrics_configuration_block] + }} + when: matrix_synapse_workers_enabled_list|length > 0 + when: matrix_synapse_enabled | bool and matrix_synapse_metrics_proxying_enabled | bool diff --git a/roles/matrix-synapse/tasks/main.yml b/roles/matrix-synapse/tasks/main.yml index 55235843..7068dcef 100644 --- a/roles/matrix-synapse/tasks/main.yml +++ b/roles/matrix-synapse/tasks/main.yml @@ -1,57 +1,57 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool and matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool and matrix_synapse_enabled | bool tags: - setup-all - setup-synapse -- import_tasks: "{{ role_path }}/tasks/setup_synapse.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_synapse.yml" + when: run_setup | bool tags: - setup-all - setup-synapse -- import_tasks: "{{ role_path }}/tasks/import_media_store.yml" - when: run_synapse_import_media_store|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_media_store.yml" + when: run_synapse_import_media_store | bool tags: - import-synapse-media-store -- import_tasks: "{{ role_path }}/tasks/register_user.yml" - when: run_synapse_register_user|bool and matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/register_user.yml" + when: run_synapse_register_user | bool and matrix_synapse_enabled | bool tags: - register-user -- import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool + when: run_self_check | bool tags: - self-check -- import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool + when: run_self_check | bool tags: - self-check -- import_tasks: "{{ role_path }}/tasks/update_user_password.yml" - when: run_synapse_update_user_password|bool and matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/update_user_password.yml" + when: run_synapse_update_user_password | bool and matrix_synapse_enabled | bool tags: - update-user-password -- import_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/main.yml" - when: run_synapse_rust_synapse_compress_state|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/main.yml" + when: run_synapse_rust_synapse_compress_state | bool tags: - rust-synapse-compress-state - name: Mark matrix-synapse role as executed - set_fact: + ansible.builtin.set_fact: matrix_synapse_role_executed: true tags: - always diff --git a/roles/matrix-synapse/tasks/register_user.yml b/roles/matrix-synapse/tasks/register_user.yml index 2a1c5708..8c344b2d 100644 --- a/roles/matrix-synapse/tasks/register_user.yml +++ b/roles/matrix-synapse/tasks/register_user.yml @@ -1,31 +1,33 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `username` variable needs to be provided to this playbook, via --extra-vars" when: "username is not defined or username == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `password` variable needs to be provided to this playbook, via --extra-vars" when: "password is not defined or password == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `admin` variable needs to be provided to this playbook, via --extra-vars" when: "admin is not defined or admin not in ['yes', 'no']" - name: Ensure matrix-synapse is started - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true register: start_result - name: Wait a while, so that Synapse can manage to start - pause: + ansible.builtin.pause: seconds: 7 when: "start_result.changed" - name: Register user - command: "{{ matrix_local_bin_path }}/matrix-synapse-register-user {{ username|quote }} {{ password|quote }} {{ '1' if admin == 'yes' else '0' }}" + ansible.builtin.command: "{{ matrix_local_bin_path }}/matrix-synapse-register-user {{ username|quote }} {{ password|quote }} {{ '1' if admin == 'yes' else '0' }}" + register: matrix_synapse_register_user_result + changed_when: matrix_synapse_register_user_result.rc == 0 diff --git a/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml b/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml index e1386c75..221a7570 100644 --- a/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml +++ b/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml @@ -1,10 +1,10 @@ --- -- debug: +- ansible.builtin.debug: msg: "Compressing room `{{ room_details.room_id }}` having {{ room_details.count }} state group rows" - name: Generate rust-synapse-compress-state room compression command - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_compress_room_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-compress-room --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -17,15 +17,16 @@ -r '{{ room_details.room_id }}' - name: Run rust-synapse-compress-state room compression command (SQL generation) - command: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_command }}" + ansible.builtin.command: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_command }}" async: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_time }}" poll: 10 register: matrix_synapse_rust_synapse_compress_state_compress_room_command_result + changed_when: matrix_synapse_rust_synapse_compress_state_compress_room_command_result.rc == 0 -- debug: var="matrix_synapse_rust_synapse_compress_state_compress_room_command_result" +- ansible.builtin.debug: var="matrix_synapse_rust_synapse_compress_state_compress_room_command_result" - name: Generate Postgres compression SQL import command - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_psql_import_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-psql-import --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -39,12 +40,13 @@ psql -v ON_ERROR_STOP=1 -h matrix-postgres -d {{ matrix_synapse_database_database }}" - name: Import compression SQL into Postgres - command: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_command }}" + ansible.builtin.command: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_command }}" async: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_time }}" poll: 10 register: matrix_synapse_rust_synapse_compress_state_psql_import_command_result + changed_when: matrix_synapse_rust_synapse_compress_state_psql_import_command_result.rc == 0 - name: Clean up - file: + ansible.builtin.file: path: "{{ matrix_synapse_rust_synapse_compress_state_base_path }}/state-compressor.sql" state: absent diff --git a/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml b/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml index 219f1c98..fcea8606 100644 --- a/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml +++ b/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml @@ -2,40 +2,40 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot use rust-synapse-compress-state." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time: 1800 - when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time | default('') == ''" - name: Set matrix_synapse_rust_synapse_compress_state_compress_room_time, if not provided - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_compress_room_time: 3600 - when: "matrix_synapse_rust_synapse_compress_state_compress_room_time|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_compress_room_time | default('') == ''" - name: Set matrix_synapse_rust_synapse_compress_state_psql_import_time, if not provided - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_psql_import_time: 3600 - when: "matrix_synapse_rust_synapse_compress_state_psql_import_time|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_psql_import_time | default('') == ''" - name: Set matrix_synapse_rust_synapse_compress_state_min_state_groups_required, if not provided - set_fact: + ansible.builtin.set_fact: # The minimum number of state groups we're looking for before we consider a room eligible for compression. # Rooms with a smaller state groups count will not be compressed. matrix_synapse_rust_synapse_compress_state_min_state_groups_required: 100000 - when: "matrix_synapse_rust_synapse_compress_state_min_state_groups_required|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_min_state_groups_required | default('') == ''" # Actual compression work - name: Ensure rust-synapse-compress-state paths exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_rust_synapse_compress_state_base_path }}" state: directory mode: 0750 @@ -54,7 +54,7 @@ until: result is not failed - name: Generate rust-synapse-compress-state room find command - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_find_rooms_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-find-rooms --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -66,10 +66,11 @@ 'SELECT array_to_json(array_agg(row_to_json (r))) FROM (SELECT room_id, count(*) AS count FROM state_groups_state GROUP BY room_id HAVING count(*) > {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} ORDER BY count DESC) r;' - name: Find rooms eligible for compression with rust-synapse-compress-state - command: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command }}" + ansible.builtin.command: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command }}" async: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time }}" poll: 10 register: matrix_synapse_rust_synapse_compress_state_find_rooms_command_result + changed_when: false # We expect the output to be like this: # @@ -85,10 +86,10 @@ # Row 3 contains a space when there's no result. - block: - - debug: var="matrix_synapse_rust_synapse_compress_state_find_rooms_command_result" + - ansible.builtin.debug: var="matrix_synapse_rust_synapse_compress_state_find_rooms_command_result" - name: Fail if room find result is not what we expect - fail: + ansible.builtin.fail: msg: >- Expecting 4 lines in the "find rooms" result. when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.failed or matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines|length != 4" @@ -96,11 +97,11 @@ - block: # matrix_synapse_rust_synapse_compress_state_eligible_rooms is a list # of dictionaries like this: {'room_id': '!some-id', 'count': 2461329} - - set_fact: + - ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_eligible_rooms: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] | from_json }}" - name: Display rooms that will be compressed - debug: + ansible.builtin.debug: msg: >- The following rooms contain more than {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} state group rows (configurable via `matrix_synapse_rust_synapse_compress_state_min_state_groups_required`) @@ -108,14 +109,14 @@ {{ matrix_synapse_rust_synapse_compress_state_eligible_rooms }} - name: Compress room state - include_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/compress_room.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/compress_room.yml" with_items: "{{ matrix_synapse_rust_synapse_compress_state_eligible_rooms }}" loop_control: loop_var: room_details when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] != ' '" - name: Show notice about lack of rooms to compress - debug: + ansible.builtin.debug: msg: >- No rooms were found to contain more than {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} state group rows (configurable via `matrix_synapse_rust_synapse_compress_state_min_state_groups_required`), diff --git a/roles/matrix-synapse/tasks/self_check_client_api.yml b/roles/matrix-synapse/tasks/self_check_client_api.yml index 407a79ff..1c03ba5b 100644 --- a/roles/matrix-synapse/tasks/self_check_client_api.yml +++ b/roles/matrix-synapse/tasks/self_check_client_api.yml @@ -1,21 +1,21 @@ --- - name: Check Matrix Client API - uri: + ansible.builtin.uri: url: "{{ matrix_synapse_client_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_synapse_self_check_validate_certificates }}" register: result_matrix_synapse_client_api ignore_errors: true check_mode: false - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool - name: Fail if Matrix Client API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Client API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_client_api_url_endpoint_public }}`). Is Synapse running? Is port 443 open in your firewall? Full error: {{ result_matrix_synapse_client_api }}" - when: "matrix_synapse_enabled|bool and (result_matrix_synapse_client_api.failed or 'json' not in result_matrix_synapse_client_api)" + when: "matrix_synapse_enabled | bool and (result_matrix_synapse_client_api.failed or 'json' not in result_matrix_synapse_client_api)" - name: Report working Matrix Client API - debug: + ansible.builtin.debug: msg: "The Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_client_api_url_endpoint_public }}`) is working" - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool diff --git a/roles/matrix-synapse/tasks/self_check_federation_api.yml b/roles/matrix-synapse/tasks/self_check_federation_api.yml index 32249372..80ec4fc2 100644 --- a/roles/matrix-synapse/tasks/self_check_federation_api.yml +++ b/roles/matrix-synapse/tasks/self_check_federation_api.yml @@ -1,26 +1,26 @@ --- - name: Check Matrix Federation API - uri: + ansible.builtin.uri: url: "{{ matrix_synapse_federation_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_synapse_self_check_validate_certificates }}" register: result_matrix_synapse_federation_api ignore_errors: true check_mode: false - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool - name: Fail if Matrix Federation API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_federation_api_url_endpoint_public }}`). Is Synapse running? Is port {{ matrix_federation_public_port }} open in your firewall? Full error: {{ result_matrix_synapse_federation_api }}" - when: "matrix_synapse_enabled|bool and matrix_synapse_federation_enabled|bool and (result_matrix_synapse_federation_api.failed or 'json' not in result_matrix_synapse_federation_api)" + when: "matrix_synapse_enabled | bool and matrix_synapse_federation_enabled | bool and (result_matrix_synapse_federation_api.failed or 'json' not in result_matrix_synapse_federation_api)" - name: Fail if Matrix Federation API unexpectedly enabled - fail: + ansible.builtin.fail: msg: "Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_federation_api_url_endpoint_public }}`) despite being disabled." - when: "matrix_synapse_enabled|bool and not matrix_synapse_federation_enabled|bool and not result_matrix_synapse_federation_api.failed" + when: "matrix_synapse_enabled | bool and not matrix_synapse_federation_enabled | bool and not result_matrix_synapse_federation_api.failed" - name: Report working Matrix Federation API - debug: + ansible.builtin.debug: msg: "The Matrix Federation API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_federation_api_url_endpoint_public }}`) is working" - when: "matrix_synapse_enabled|bool and matrix_synapse_federation_enabled|bool" + when: "matrix_synapse_enabled | bool and matrix_synapse_federation_enabled | bool" diff --git a/roles/matrix-synapse/tasks/setup_synapse.yml b/roles/matrix-synapse/tasks/setup_synapse.yml index 47e404f4..d4e6ae95 100644 --- a/roles/matrix-synapse/tasks/setup_synapse.yml +++ b/roles/matrix-synapse/tasks/setup_synapse.yml @@ -1,7 +1,7 @@ --- - name: Ensure Synapse paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,12 +14,12 @@ # We handle matrix_synapse_media_store_path elsewhere (in ./synapse/setup_install.yml), # because if it's using Goofys and it's already mounted (from before), # trying to chown/chmod it here will cause trouble. - when: "(matrix_synapse_enabled|bool or matrix_s3_media_store_enabled|bool) and item.when" + when: "(matrix_synapse_enabled | bool or matrix_s3_media_store_enabled | bool) and item.when" -- import_tasks: "{{ role_path }}/tasks/ext/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/setup.yml" -- import_tasks: "{{ role_path }}/tasks/synapse/workers/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/workers/setup.yml" -- import_tasks: "{{ role_path }}/tasks/synapse/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/setup.yml" -- import_tasks: "{{ role_path }}/tasks/goofys/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/goofys/setup.yml" diff --git a/roles/matrix-synapse/tasks/synapse/setup.yml b/roles/matrix-synapse/tasks/synapse/setup.yml index b5d27c36..80f761e5 100644 --- a/roles/matrix-synapse/tasks/synapse/setup.yml +++ b/roles/matrix-synapse/tasks/synapse/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/synapse/setup_install.yml" - when: matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/setup_install.yml" + when: matrix_synapse_enabled | bool -- import_tasks: "{{ role_path }}/tasks/synapse/setup_uninstall.yml" - when: "not matrix_synapse_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/setup_uninstall.yml" + when: "not matrix_synapse_enabled | bool" diff --git a/roles/matrix-synapse/tasks/synapse/setup_install.yml b/roles/matrix-synapse/tasks/synapse/setup_install.yml index 2302a6f2..e4ec0f67 100644 --- a/roles/matrix-synapse/tasks/synapse/setup_install.yml +++ b/roles/matrix-synapse/tasks/synapse/setup_install.yml @@ -2,7 +2,7 @@ # This will throw a Permission Denied error if already mounted using fuse - name: Check Synapse media store path - stat: + ansible.builtin.stat: path: "{{ matrix_synapse_media_store_path }}" register: local_path_media_store_stat ignore_errors: true @@ -10,7 +10,7 @@ # This is separate and conditional, to ensure we don't execute it # if the path already exists or we failed to check, because it's mounted using fuse. - name: Ensure Synapse media store path exists - file: + ansible.builtin.file: path: "{{ matrix_synapse_media_store_path }}" state: directory mode: 0750 @@ -20,7 +20,7 @@ - block: - name: Ensure Synapse repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_synapse_container_image_self_build_repo }}" dest: "{{ matrix_synapse_docker_src_files_path }}" version: "{{ matrix_synapse_docker_image.split(':')[1] }}" @@ -30,14 +30,15 @@ register: matrix_synapse_git_pull_results - name: Check if Synapse Docker image exists - command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'" + ansible.builtin.command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'" register: matrix_synapse_docker_image_check_result + changed_when: false # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module, # because the latter does not support BuildKit. # See: https://github.com/ansible-collections/community.general/issues/514 - name: Ensure Synapse Docker image is built - shell: + ansible.builtin.shell: chdir: "{{ matrix_synapse_docker_src_files_path }}" cmd: | {{ matrix_host_command_docker }} build \ @@ -46,8 +47,8 @@ . environment: DOCKER_BUILDKIT: 1 - when: "matrix_synapse_git_pull_results.changed|bool or matrix_synapse_docker_image_check_result.stdout == ''" - when: "matrix_synapse_container_image_self_build|bool" + when: "matrix_synapse_git_pull_results.changed | bool or matrix_synapse_docker_image_check_result.stdout == ''" + when: "matrix_synapse_container_image_self_build | bool" - name: Ensure Synapse Docker image is pulled docker_image: @@ -62,7 +63,7 @@ until: result is not failed - name: Check if a Synapse signing key exists - stat: + ansible.builtin.stat: path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key" register: matrix_synapse_signing_key_stat @@ -74,7 +75,7 @@ # We don't use the `docker_container` module, because using it with `cap_drop` requires # a very recent docker-py version, which is not available for a lot of people yet. - name: Generate initial Synapse config and signing key - command: | + ansible.builtin.command: | docker run --rm --name=matrix-config @@ -89,33 +90,42 @@ when: "not matrix_synapse_signing_key_stat.stat.exists" - name: Ensure Synapse homeserver config installed - copy: - content: "{{ matrix_synapse_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_synapse_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Synapse log config installed - template: + ansible.builtin.template: src: "{{ matrix_synapse_template_synapse_log }}" dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config" mode: 0644 - name: Ensure matrix-synapse.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2" dest: "{{ matrix_systemd_path }}/matrix-synapse.service" mode: 0644 register: matrix_synapse_systemd_service_result - name: Ensure systemd reloaded after matrix-synapse.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_synapse_systemd_service_result.changed" - name: Ensure matrix-synapse-register-user script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2" dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user" mode: 0755 + +- name: Generate sample prometheus.yml for external scraping + ansible.builtin.template: + src: "{{ role_path }}/templates/synapse/prometheus/external_prometheus.yml.example.j2" + dest: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: 0644 + when: matrix_synapse_metrics_proxying_enabled | bool diff --git a/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml b/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml index 911d1285..17b1b8c4 100644 --- a/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-synapse service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-synapse.service" register: matrix_synapse_service_stat - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped enabled: false @@ -15,13 +15,13 @@ when: "matrix_synapse_service_stat.stat.exists" - name: Ensure matrix-synapse.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-synapse.service" state: absent when: "matrix_synapse_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-synapse.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_synapse_service_stat.stat.exists" @@ -29,3 +29,9 @@ docker_image: name: "{{ matrix_synapse_docker_image }}" state: absent + +- name: Ensure sample prometheus.yml for external scraping is deleted + ansible.builtin.file: + path: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example" + state: absent + when: "not matrix_synapse_metrics_proxying_enabled | bool" diff --git a/roles/matrix-synapse/tasks/synapse/workers/init.yml b/roles/matrix-synapse/tasks/synapse/workers/init.yml index f59313bd..4b007bc3 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/init.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/init.yml @@ -5,69 +5,69 @@ # so we're forced to do something much uglier. - name: Build generic workers - set_fact: + ansible.builtin.set_fact: worker: type: 'generic_worker' instanceId: "{{ matrix_synapse_workers_generic_workers_port_range_start + item }}" port: "{{ matrix_synapse_workers_generic_workers_port_range_start + item }}" metrics_port: "{{ matrix_synapse_workers_generic_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_generic_workers" - loop: "{{ range(0, matrix_synapse_workers_generic_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_generic_workers_count | int) | list }}" - name: Build federation sender workers - set_fact: + ansible.builtin.set_fact: worker: type: 'federation_sender' instanceId: "{{ item }}" port: 0 metrics_port: "{{ matrix_synapse_workers_federation_sender_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_federation_sender_workers" - loop: "{{ range(0, matrix_synapse_workers_federation_sender_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_federation_sender_workers_count | int) | list }}" # This type of worker can only have a count of 1, at most - name: Build pusher workers - set_fact: + ansible.builtin.set_fact: worker: type: 'pusher' instanceId: "{{ item }}" port: 0 metrics_port: "{{ matrix_synapse_workers_pusher_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_pusher_workers" - loop: "{{ range(0, matrix_synapse_workers_pusher_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_pusher_workers_count | int) | list }}" # This type of worker can only have a count of 1, at most - name: Build appservice workers - set_fact: + ansible.builtin.set_fact: worker: type: 'appservice' instanceId: "{{ item }}" port: 0 metrics_port: "{{ matrix_synapse_workers_appservice_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_appservice_workers" - loop: "{{ range(0, matrix_synapse_workers_appservice_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_appservice_workers_count | int) | list }}" - name: Build media_repository workers - set_fact: + ansible.builtin.set_fact: worker: type: 'media_repository' instanceId: "{{ matrix_synapse_workers_media_repository_workers_port_range_start + item }}" port: "{{ matrix_synapse_workers_media_repository_workers_port_range_start + item }}" metrics_port: "{{ matrix_synapse_workers_media_repository_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_media_repository_workers" - loop: "{{ range(0, matrix_synapse_workers_media_repository_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_media_repository_workers_count | int) | list }}" - name: Build frontend_proxy workers - set_fact: + ansible.builtin.set_fact: worker: type: 'frontend_proxy' instanceId: "{{ matrix_synapse_workers_frontend_proxy_workers_port_range_start + item }}" port: "{{ matrix_synapse_workers_frontend_proxy_workers_port_range_start + item }}" metrics_port: "{{ matrix_synapse_workers_frontend_proxy_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_frontend_proxy_workers" - loop: "{{ range(0, matrix_synapse_workers_frontend_proxy_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_frontend_proxy_workers_count | int) | list }}" -- set_fact: - matrix_synapse_dynamic_workers_list: "{{ matrix_synapse_dynamic_workers_list|default([]) + [item.ansible_facts.worker] }}" +- ansible.builtin.set_fact: + matrix_synapse_dynamic_workers_list: "{{ matrix_synapse_dynamic_workers_list | default([]) + [item.ansible_facts.worker] }}" with_items: | {{ matrix_synapse_workers_list_results_generic_workers.results @@ -83,5 +83,5 @@ matrix_synapse_workers_list_results_frontend_proxy_workers.results }} -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_workers_enabled_list: "{{ matrix_synapse_dynamic_workers_list }}" diff --git a/roles/matrix-synapse/tasks/synapse/workers/setup.yml b/roles/matrix-synapse/tasks/synapse/workers/setup.yml index ce66a2e4..836d5a66 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/setup.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/setup.yml @@ -3,19 +3,19 @@ # A previous version of the worker setup used this. # This is a temporary cleanup for people who ran that version. - name: Ensure old matrix-synapse.service.wants directory is gone - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-synapse.service.wants" state: absent # Same. This was part of a previous version of the worker setup. # No longer necessary. - name: Ensure matrix-synapse-worker-write-pid script is removed - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/matrix-synapse-worker-write-pid" state: absent -- include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_install.yml" - when: "matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool" +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_install.yml" + when: "matrix_synapse_enabled | bool and matrix_synapse_workers_enabled | bool" -- include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_uninstall.yml" - when: "not matrix_synapse_workers_enabled|bool" +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_uninstall.yml" + when: "not matrix_synapse_workers_enabled | bool" diff --git a/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml b/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml index 983f1876..c264805a 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Determine current worker configs - find: + ansible.builtin.find: path: "{{ matrix_synapse_config_dir_path }}" patterns: "worker.*.yaml" use_regex: true @@ -9,34 +9,34 @@ # This also deletes some things which we need. They will be recreated below. - name: Ensure previous worker configs are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_config_files.files }}" - name: Determine current worker systemd services - find: + ansible.builtin.find: path: "{{ matrix_systemd_path }}" patterns: "matrix-synapse-worker.*.service" use_regex: true register: matrix_synapse_workers_current_systemd_services - name: Ensure unnecessary worker systemd services are stopped and disabled - service: - name: "{{ item.path|basename }}" + ansible.builtin.service: + name: "{{ item.path | basename }}" state: stopped enabled: false with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" - when: "not ansible_check_mode and item.path|basename not in matrix_systemd_services_list" + when: "not ansible_check_mode and item.path | basename not in matrix_systemd_services_list" - name: Ensure unnecessary worker systemd services are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" - name: Ensure creation of worker systemd service files and configuration files - include_tasks: "{{ role_path }}/tasks/synapse/workers/util/setup_files_for_worker.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/util/setup_files_for_worker.yml" with_items: "{{ matrix_synapse_workers_enabled_list }}" loop_control: loop_var: matrix_synapse_worker_details diff --git a/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml b/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml index f0357611..98c81a2e 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml @@ -1,37 +1,37 @@ --- - name: Populate service facts - service_facts: + ansible.builtin.service_facts: - name: Ensure any worker services are stopped - service: + ansible.builtin.service: name: "{{ item.key }}" state: stopped - with_dict: "{{ ansible_facts.services|default({})|dict2items|selectattr('key', 'match', 'matrix-synapse-worker-.+\\.service')|list|items2dict }}" + with_dict: "{{ ansible_facts.services | default({}) | dict2items | selectattr('key', 'match', 'matrix-synapse-worker-.+\\.service') | list | items2dict }}" when: "item.value['status'] != 'not-found'" # see https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1461 - name: Find worker configs to be cleaned - find: + ansible.builtin.find: path: "{{ matrix_synapse_config_dir_path }}" patterns: "worker.*.yaml" use_regex: true register: matrix_synapse_workers_current_config_files - name: Ensure previous worker configs are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_config_files.files }}" - name: Find worker systemd services to be cleaned - find: + ansible.builtin.find: path: "{{ matrix_systemd_path }}" patterns: "matrix-synapse-worker.*.service" use_regex: true register: matrix_synapse_workers_current_systemd_services - name: Ensure previous worker systemd services are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" diff --git a/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml b/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml index 2669e149..2ecb3f2b 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml @@ -8,12 +8,12 @@ # In the future, it should be possible to remove this check. # Our own code which dynamically builds `matrix_synapse_workers_enabled_list` does things right. - name: Fail if instanceId not defined for worker - fail: - msg: "Synapse workers (like {{ matrix_synapse_worker_details|to_json }}) need to define an instanceId property (type + instanceId must be unique)" + ansible.builtin.fail: + msg: "Synapse workers (like {{ matrix_synapse_worker_details | to_json }}) need to define an instanceId property (type + instanceId must be unique)" when: "'instanceId' not in matrix_synapse_worker_details" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_systemd_service_name: "matrix-synapse-worker-{{ matrix_synapse_worker_details.type }}-{{ matrix_synapse_worker_details.instanceId }}.service" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + [matrix_synapse_worker_systemd_service_name] }}" diff --git a/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml b/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml index 2247cd89..d6d4924f 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml @@ -1,21 +1,24 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_systemd_service_name: "matrix-synapse-worker-{{ matrix_synapse_worker_details.type }}-{{ matrix_synapse_worker_details.instanceId }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_container_name: "{{ matrix_synapse_worker_systemd_service_name }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_config_file_name: "worker.{{ matrix_synapse_worker_details.type }}_{{ matrix_synapse_worker_details.instanceId }}.yaml" - name: Ensure configuration exists for {{ matrix_synapse_worker_systemd_service_name }} - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/worker.yaml.j2" dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_synapse_worker_config_file_name }}" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" - name: Ensure systemd service exists for {{ matrix_synapse_worker_systemd_service_name }} - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse-worker.service.j2" dest: "{{ matrix_systemd_path }}/{{ matrix_synapse_worker_systemd_service_name }}.service" mode: 0644 diff --git a/roles/matrix-synapse/tasks/update_user_password.yml b/roles/matrix-synapse/tasks/update_user_password.yml index fd348d9d..586bf51b 100644 --- a/roles/matrix-synapse/tasks/update_user_password.yml +++ b/roles/matrix-synapse/tasks/update_user_password.yml @@ -1,29 +1,29 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `username` variable needs to be provided to this playbook, via --extra-vars" when: "username is not defined or username == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `password` variable needs to be provided to this playbook, via --extra-vars" when: "password is not defined or password == ''" - name: Fail if not using matrix-postgres container - fail: + ansible.builtin.fail: msg: "This command is working only when matrix-postgres container is being used" - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Ensure matrix-synapse is started - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true register: start_result - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true @@ -31,13 +31,16 @@ - name: Wait a while, so that Matrix Synapse can manage to start - pause: + ansible.builtin.pause: seconds: 7 when: "start_result.changed or postgres_start_result.changed" - name: Generate password hash - shell: "{{ matrix_host_command_docker }} exec matrix-synapse /usr/local/bin/hash_password -c /data/homeserver.yaml -p {{ password|quote }}" + ansible.builtin.shell: "{{ matrix_host_command_docker }} exec matrix-synapse /usr/local/bin/hash_password -c /data/homeserver.yaml -p {{ password|quote }}" register: password_hash + changed_when: false - name: Update user password hash - command: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash {{ username|quote }} {{ password_hash.stdout|quote }}" + ansible.builtin.command: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash {{ username|quote }} {{ password_hash.stdout|quote }}" + register: matrix_synapse_update_user_password_result + changed_when: matrix_synapse_update_user_password_result.rc == 0 diff --git a/roles/matrix-synapse/tasks/validate_config.yml b/roles/matrix-synapse/tasks/validate_config.yml index 89107c0a..ba60abf8 100644 --- a/roles/matrix-synapse/tasks/validate_config.yml +++ b/roles/matrix-synapse/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Synapse settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Synapse. when: "vars[item] == ''" @@ -12,18 +12,29 @@ - "matrix_synapse_database_password" - "matrix_synapse_database_database" +- name: Fail if asking to configure deprecaed workers (appservice, userdir) + ansible.builtin.fail: + msg: >- + `{{ item }}` cannot be more than 0. + This type of worker has been deprecated since Synapse v1.59. + Please remove your `{{ item }}` configuration to solve this problem. + See: https://github.com/matrix-org/synapse/blob/v1.59.0/docs/upgrade.md#deprecation-of-the-synapseappappservice-and-synapseappuser_dir-worker-application-types + when: "vars[item]|int != 0" + with_items: + - "matrix_synapse_workers_appservice_workers_count" + - "matrix_synapse_workers_user_dir_workers_count" + - name: Fail if asking for more than 1 instance of single-instance workers - fail: + ansible.builtin.fail: msg: >- `{{ item }}` cannot be more than 1. This is a single-instance worker. when: "vars[item]|int > 1" with_items: - - "matrix_synapse_workers_appservice_workers_count" - "matrix_synapse_workers_pusher_workers_count" - "matrix_synapse_workers_federation_sender_workers_count" - name: (Deprecation) Catch and report renamed settings - fail: + 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 }}`). @@ -49,9 +60,10 @@ - {'old': 'matrix_synapse_trusted_third_party_id_servers', 'new': ''} - {'old': 'matrix_synapse_use_presence', 'new': 'matrix_synapse_presence_enabled'} - {'old': 'matrix_synapse_version_arm64', 'new': ''} + - {'old': 'matrix_synapse_enable_group_creation', 'new': ''} - name: (Deprecation) Catch and report renamed settings in matrix_synapse_configuration_extension_yaml - fail: + ansible.builtin.fail: msg: >- Your matrix_synapse_configuration_extension_yaml configuration contains a variable, which now has a different name. Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`). diff --git a/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 b/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 index 37cad10f..5797f185 100644 --- a/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 +++ b/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 @@ -352,21 +352,15 @@ worker_app: synapse.app.homeserver # thx https://oznetnerd.com/2017/04/18/jinja2-selectattr-filter/ # reduce the main worker's offerings to core homeserver business -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'appservice')|list %} -notify_appservices: false -{% endif %} -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'federation_sender')|list %} +{% if matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'federation_sender') | list %} send_federation: false {% endif %} -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'media_repository')|list %} +{% if matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'media_repository') | list %} enable_media_repo: false {% endif %} -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'pusher')|list %} +{% if matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'pusher') | list %} start_pushers: false {% endif %} -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'user_dir')|list %} -update_user_directory: false -{% endif %} daemonize: false {% endif %} @@ -432,6 +426,11 @@ manhole_settings: # sign up in a short space of time never to return after their initial # session. # +# The option `mau_appservice_trial_days` is similar to `mau_trial_days`, but +# applies a different trial number if the user was registered by an appservice. +# A value of 0 means no trial days are applied. Appservices not listed in this +# dictionary use the value of `mau_trial_days` instead. +# # 'mau_limit_alerting' is a means of limiting client side alerting # should the mau limit be reached. This is useful for small instances # where the admin has 5 mau seats (say) for 5 specific people and no @@ -442,6 +441,8 @@ manhole_settings: #max_mau_value: 50 #mau_trial_days: 2 #mau_limit_alerting: false +#mau_appservice_trial_days: +# "appservice-id": 1 # If enabled, the metrics for the number of monthly active users will # be populated, however no one will be limited. If limit_usage_by_mau @@ -742,11 +743,11 @@ federation_domain_whitelist: {{ matrix_synapse_federation_domain_whitelist|to_js # #allow_profile_lookup_over_federation: false -# Uncomment to disable device display name lookup over federation. By default, the -# Federation API allows other homeservers to obtain device display names of any user -# on this homeserver. Defaults to 'true'. +# Uncomment to allow device display name lookup over federation. By default, the +# Federation API prevents other homeservers from obtaining the display names of +# user devices on this homeserver. Defaults to 'false'. # -#allow_device_name_lookup_over_federation: false +#allow_device_name_lookup_over_federation: true ## Caching ## @@ -869,8 +870,8 @@ database: name: "psycopg2" txn_limit: {{ matrix_synapse_database_txn_limit }} args: - user: {{ matrix_synapse_database_user|string|to_json }} - password: {{ matrix_synapse_database_password|string|to_json }} + user: {{ matrix_synapse_database_user | string|to_json }} + password: {{ matrix_synapse_database_password | string|to_json }} database: "{{ matrix_synapse_database_database }}" host: "{{ matrix_synapse_database_host }}" port: {{ matrix_synapse_database_port }} @@ -1047,6 +1048,14 @@ media_store_path: "/matrix-media-store-parent/{{ matrix_synapse_media_store_dire # max_upload_size: "{{ matrix_synapse_max_upload_size_mb }}M" +media_retention: +{% if matrix_synapse_media_retention_local_media_lifetime %} + local_media_lifetime: {{ matrix_synapse_media_retention_local_media_lifetime|to_json }} +{% endif %} +{% if matrix_synapse_media_retention_remote_media_lifetime %} + remote_media_lifetime: {{ matrix_synapse_media_retention_remote_media_lifetime|to_json }} +{% endif %} + # Maximum number of pixels that will be thumbnailed # #max_image_pixels: 32M @@ -1247,7 +1256,7 @@ turn_uris: {{ matrix_synapse_turn_uris|to_json }} # The shared secret used to compute passwords for the TURN server # -turn_shared_secret: {{ matrix_synapse_turn_shared_secret|string|to_json }} +turn_shared_secret: {{ matrix_synapse_turn_shared_secret | string|to_json }} # The Username and password if the TURN server needs them and # does not use a token @@ -1375,12 +1384,16 @@ allowed_local_3pids: {{ matrix_synapse_allowed_local_3pids|to_json }} # registration_requires_token: {{ matrix_synapse_registration_requires_token|to_json }} - +# Allow users to submit a token during registration to bypass any required 3pid +# steps configured in `registrations_require_3pid`. +# Defaults to false, requiring that registration tokens (if enabled) complete a 3pid flow. +# +#enable_registration_token_3pid_bypass: false # If set, allows registration of standard or admin accounts by anyone who # has the shared secret, even if registration is otherwise disabled. # -registration_shared_secret: {{ matrix_synapse_registration_shared_secret|string|to_json }} +registration_shared_secret: {{ matrix_synapse_registration_shared_secret | string|to_json }} # Set the number of bcrypt rounds used to generate password hash. # Larger numbers increase the work factor needed to generate the hash. @@ -1574,11 +1587,11 @@ metrics_flags: # #known_servers: true -# Whether or not to report anonymized homeserver usage statistics. +# Whether or not to report homeserver usage statistics. # report_stats: {{ matrix_synapse_report_stats|to_json }} -# The endpoint to report the anonymized homeserver usage statistics to. +# The endpoint to report homeserver usage statistics to. # Defaults to https://matrix.org/report-usage-stats/push # #report_stats_endpoint: https://example.com/report-usage-stats/push @@ -1644,13 +1657,13 @@ app_service_config_files: {{ matrix_synapse_app_service_config_files|to_json }} # the registration_shared_secret is used, if one is given; otherwise, # a secret key is derived from the signing key. # -macaroon_secret_key: {{ matrix_synapse_macaroon_secret_key|string|to_json }} +macaroon_secret_key: {{ matrix_synapse_macaroon_secret_key | string|to_json }} # a secret which is used to calculate HMACs for form values, to stop # falsification of values. Must be specified for the User Consent # forms to work. # -form_secret: {{ matrix_synapse_form_secret|string|to_json }} +form_secret: {{ matrix_synapse_form_secret | string|to_json }} ## Signing Keys ## @@ -2250,7 +2263,7 @@ password_config: # Uncomment and change to a secret random string for extra security. # DO NOT CHANGE THIS AFTER INITIAL SETUP! # - pepper: {{ matrix_synapse_password_config_pepper|string|to_json }} + pepper: {{ matrix_synapse_password_config_pepper | string|to_json }} # Define and enforce a password policy. Each parameter is optional. # This is an implementation of MSC2000. @@ -2317,7 +2330,7 @@ email: # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'. # #smtp_host: mail.server - smtp_host: {{ matrix_synapse_email_smtp_host|string|to_json }} + smtp_host: {{ matrix_synapse_email_smtp_host | string|to_json }} # The port on the mail server for outgoing SMTP. Defaults to 25. # @@ -2327,8 +2340,8 @@ email: # Username/password for authentication to the SMTP server. By default, no # authentication is attempted. {% if matrix_synapse_email_smtp_user %} - smtp_user: {{ matrix_synapse_email_smtp_user|string|to_json }} - smtp_pass: {{ matrix_synapse_email_smtp_pass|string|to_json }} + smtp_user: {{ matrix_synapse_email_smtp_user | string|to_json }} + smtp_pass: {{ matrix_synapse_email_smtp_pass | string|to_json }} {% endif %} # Uncomment the following to require TLS transport security for SMTP. @@ -2358,7 +2371,7 @@ email: # trailing 's'. # #notif_from: "Your Friendly %(app)s homeserver " - notif_from: {{ matrix_synapse_email_notif_from|string|to_json }} + notif_from: {{ matrix_synapse_email_notif_from | string|to_json }} # app_name defines the default value for '%(app)s' in notif_from and email # subjects. It defaults to 'Matrix'. @@ -2385,7 +2398,7 @@ email: # supported for backwards-compatibility but is now deprecated.) # #client_base_url: "http://localhost/riot" - client_base_url: {{ matrix_synapse_email_client_base_url|string|to_json }} + client_base_url: {{ matrix_synapse_email_client_base_url | string|to_json }} # Configure the time that a validation email will expire after sending. # Defaults to 1h. @@ -2396,7 +2409,7 @@ email: # to the identity server as the org.matrix.web_client_location key. Defaults # to unset, giving no guidance to the identity server. # - invite_client_location: {{ matrix_synapse_email_invite_client_location|string|to_json }} + invite_client_location: {{ matrix_synapse_email_invite_client_location | string|to_json }} # Subjects to use when sending emails from Synapse. # @@ -2497,7 +2510,7 @@ password_providers: {% if matrix_synapse_ext_password_provider_rest_auth_enabled %} - module: "rest_auth_provider.RestAuthProvider" config: - endpoint: {{ matrix_synapse_ext_password_provider_rest_auth_endpoint|string|to_json }} + endpoint: {{ matrix_synapse_ext_password_provider_rest_auth_endpoint | string|to_json }} policy: registration: username: @@ -2512,18 +2525,20 @@ password_providers: - module: "ldap_auth_provider.LdapAuthProvider" config: enabled: true - uri: {{ matrix_synapse_ext_password_provider_ldap_uri|string|to_json }} + uri: {{ matrix_synapse_ext_password_provider_ldap_uri | string|to_json }} start_tls: {{ matrix_synapse_ext_password_provider_ldap_start_tls|to_json }} - base: {{ matrix_synapse_ext_password_provider_ldap_base|string|to_json }} + base: {{ matrix_synapse_ext_password_provider_ldap_base | string|to_json }} active_directory: {{ matrix_synapse_ext_password_provider_ldap_active_directory|to_json }} - default_domain: {{ matrix_synapse_ext_password_provider_ldap_default_domain|string|to_json }} + default_domain: {{ matrix_synapse_ext_password_provider_ldap_default_domain | string|to_json }} attributes: - uid: {{ matrix_synapse_ext_password_provider_ldap_attributes_uid|string|to_json }} - mail: {{ matrix_synapse_ext_password_provider_ldap_attributes_mail|string|to_json }} - name: {{ matrix_synapse_ext_password_provider_ldap_attributes_name|string|to_json }} - bind_dn: {{ matrix_synapse_ext_password_provider_ldap_bind_dn|string|to_json }} - bind_password: {{ matrix_synapse_ext_password_provider_ldap_bind_password|string|to_json }} - filter: {{ matrix_synapse_ext_password_provider_ldap_filter|string|to_json }} + uid: {{ matrix_synapse_ext_password_provider_ldap_attributes_uid | string|to_json }} + mail: {{ matrix_synapse_ext_password_provider_ldap_attributes_mail | string|to_json }} + name: {{ matrix_synapse_ext_password_provider_ldap_attributes_name | string|to_json }} +{% if matrix_synapse_ext_password_provider_ldap_bind_dn %} + bind_dn: {{ matrix_synapse_ext_password_provider_ldap_bind_dn | string|to_json }} + bind_password: {{ matrix_synapse_ext_password_provider_ldap_bind_password | string|to_json }} +{% endif %} + filter: {{ matrix_synapse_ext_password_provider_ldap_filter | string|to_json }} {% endif %} {% endif %} @@ -2593,16 +2608,6 @@ spam_checker: {{ matrix_synapse_spam_checker|to_json }} encryption_enabled_by_default_for_room_type: {{ matrix_synapse_encryption_enabled_by_default_for_room_type|to_json }} -# Uncomment to allow non-server-admin users to create groups on this server -# -enable_group_creation: {{ matrix_synapse_enable_group_creation|to_json }} - -# If enabled, non server admins can only create groups with local parts -# starting with this prefix -# -#group_creation_prefix: "unofficial_" - - # User Directory configuration # diff --git a/roles/matrix-nginx-proxy/templates/prometheus/external_prometheus.yml.example.j2 b/roles/matrix-synapse/templates/synapse/prometheus/external_prometheus.yml.example.j2 similarity index 51% rename from roles/matrix-nginx-proxy/templates/prometheus/external_prometheus.yml.example.j2 rename to roles/matrix-synapse/templates/synapse/prometheus/external_prometheus.yml.example.j2 index cbb2e6f3..b194c3c2 100644 --- a/roles/matrix-nginx-proxy/templates/prometheus/external_prometheus.yml.example.j2 +++ b/roles/matrix-synapse/templates/synapse/prometheus/external_prometheus.yml.example.j2 @@ -11,29 +11,29 @@ rule_files: scrape_configs: - job_name: 'synapse' - metrics_path: /_synapse/metrics - scheme: {{ 'https' if matrix_nginx_proxy_https_enabled else 'http' }} -{% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %} + metrics_path: /metrics/synapse/main-process + scheme: {{ 'https' if matrix_nginx_proxy_https_enabled|default(true) else 'http' }} +{% if matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled|default(true) %} basic_auth: username: prometheus password_file: /path/to/your/passwordfile.pwd {% endif %} static_configs: - - targets: ['{{ matrix_server_fqn_matrix }}:{{ matrix_nginx_proxy_container_https_host_bind_port if matrix_nginx_proxy_https_enabled else matrix_nginx_proxy_container_http_host_bind_port }}'] + - targets: ['{{ matrix_server_fqn_matrix }}:{{ matrix_nginx_proxy_container_https_host_bind_port|default(443) if matrix_nginx_proxy_https_enabled|default(true) else matrix_nginx_proxy_container_http_host_bind_port|default(80) }}'] labels: job: "master" index: "0" -{% for worker in matrix_nginx_proxy_proxy_synapse_workers_enabled_list %} +{% for worker in matrix_synapse_workers_enabled_list %} - job_name: 'synapse-{{ worker.type }}-{{ worker.instanceId }}' - metrics_path: /_synapse-worker-{{ worker.type }}-{{ worker.instanceId }}/metrics - scheme: {{ 'https' if matrix_nginx_proxy_https_enabled else 'http' }} -{% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %} + metrics_path: /metrics/synapse/worker/{{ worker.type }}-{{ worker.instanceId }} + scheme: {{ 'https' if matrix_nginx_proxy_https_enabled|default(true) else 'http' }} +{% if matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled|default(true) %} basic_auth: username: prometheus password_file: /path/to/your/passwordfile.pwd {% endif %} static_configs: - - targets: ['{{ matrix_server_fqn_matrix }}:{{ matrix_nginx_proxy_container_https_host_bind_port if matrix_nginx_proxy_https_enabled else matrix_nginx_proxy_container_http_host_bind_port }}'] + - targets: ['{{ matrix_server_fqn_matrix }}:{{ matrix_nginx_proxy_container_https_host_bind_port|default(443) if matrix_nginx_proxy_https_enabled|default(true) else matrix_nginx_proxy_container_http_host_bind_port|default(80) }}'] labels: job: "{{ worker.type }}" index: "{{ worker.instanceId }}" diff --git a/roles/matrix-synapse/templates/synapse/worker.yaml.j2 b/roles/matrix-synapse/templates/synapse/worker.yaml.j2 index 40714f44..239de1f2 100644 --- a/roles/matrix-synapse/templates/synapse/worker.yaml.j2 +++ b/roles/matrix-synapse/templates/synapse/worker.yaml.j2 @@ -26,6 +26,7 @@ worker_listeners: {% if http_resources|length > 0 %} - type: http bind_addresses: ['::'] + x_forwarded: true port: {{ matrix_synapse_worker_details.port }} resources: - names: {{ http_resources|to_json }} diff --git a/roles/matrix-synapse/vars/main.yml b/roles/matrix-synapse/vars/main.yml index 5839aa81..2d9b62cf 100644 --- a/roles/matrix-synapse/vars/main.yml +++ b/roles/matrix-synapse/vars/main.yml @@ -6,7 +6,7 @@ matrix_synapse_federation_api_url_endpoint_public: "https://{{ matrix_server_fqn # Tells whether this role had executed or not. Toggled to `true` during runtime. matrix_synapse_role_executed: false -matrix_synapse_media_store_directory_name: "{{ matrix_synapse_media_store_path|basename }}" +matrix_synapse_media_store_directory_name: "{{ matrix_synapse_media_store_path | basename }}" # A Synapse generic worker can handle both federation and client-server API endpoints. # We wish to split these, as we normally serve federation separately and don't want them mixed up. @@ -24,11 +24,15 @@ matrix_synapse_media_store_directory_name: "{{ matrix_synapse_media_store_path|b # so it's not that important whether we forward them or not. # # Basically, we aim to cover most things. Skipping `/_synapse/client` or a few other minor things doesn't matter too much. -matrix_synapse_workers_generic_worker_client_server_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints|default([]) | map('regex_search', '.*/_matrix/client.*')| list | difference([none]) }}" +matrix_synapse_workers_generic_worker_client_server_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', '.*/_matrix/client.*') | list | difference([none]) }}" # A Synapse generic worker can handle both federation and client-server API endpoints. # We wish to split these, as we normally serve federation separately and don't want them mixed up. # # This is some ugly Ansible/Jinja2 hack (seen here: https://stackoverflow.com/a/47831492), # which takes a list of various strings and removes the ones NOT containing `/_matrix/federation` or `/_matrix/key` anywhere in them. -matrix_synapse_workers_generic_worker_federation_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints|default([]) | map('regex_search', '.*(/_matrix/federation|/_matrix/key).*')| list | difference([none]) }}" +matrix_synapse_workers_generic_worker_federation_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', matrix_synapse_workers_generic_worker_federation_endpoints_regex) | list | difference([none]) }}" + +# matrix_synapse_workers_generic_worker_federation_endpoints_regex contains the regex used in matrix_synapse_workers_generic_worker_federation_endpoints. +# It's intentionally put in a separate variable, to avoid tripping ansible-lint's var-spacing rule. +matrix_synapse_workers_generic_worker_federation_endpoints_regex: '.*(/_matrix/federation|/_matrix/key).*' diff --git a/roles/matrix-synapse/vars/workers.yml b/roles/matrix-synapse/vars/workers.yml index 48530312..e535d2cc 100644 --- a/roles/matrix-synapse/vars/workers.yml +++ b/roles/matrix-synapse/vars/workers.yml @@ -1,12 +1,15 @@ --- matrix_synapse_workers_generic_worker_endpoints: - # This worker can handle API requests matching the following regular - # expressions: + # This worker can handle API requests matching the following regular expressions. + # These endpoints can be routed to any worker. If a worker is set up to handle a + # stream then, for maximum efficiency, additional endpoints should be routed to that + # worker: refer to the [stream writers](#stream-writers) section below for further + # information. # Sync requests - - ^/_matrix/client/(v2_alpha|r0|v3)/sync$ - - ^/_matrix/client/(api/v1|v2_alpha|r0|v3)/events$ + - ^/_matrix/client/(r0|v3)/sync$ + - ^/_matrix/client/(api/v1|r0|v3)/events$ - ^/_matrix/client/(api/v1|r0|v3)/initialSync$ - ^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$ @@ -20,20 +23,14 @@ matrix_synapse_workers_generic_worker_endpoints: - ^/_matrix/federation/v1/query/ - ^/_matrix/federation/v1/make_join/ - ^/_matrix/federation/v1/make_leave/ - - ^/_matrix/federation/v1/send_join/ - - ^/_matrix/federation/v2/send_join/ - - ^/_matrix/federation/v1/send_leave/ - - ^/_matrix/federation/v2/send_leave/ - - ^/_matrix/federation/v1/invite/ - - ^/_matrix/federation/v2/invite/ - - ^/_matrix/federation/v1/query_auth/ + - ^/_matrix/federation/(v1|v2)/send_join/ + - ^/_matrix/federation/(v1|v2)/send_leave/ + - ^/_matrix/federation/(v1|v2)/invite/ - ^/_matrix/federation/v1/event_auth/ - ^/_matrix/federation/v1/exchange_third_party_invite/ - ^/_matrix/federation/v1/user/devices/ - - ^/_matrix/federation/v1/get_groups_publicised$ - ^/_matrix/key/v2/query - - ^/_matrix/federation/unstable/org.matrix.msc2946/spaces/ - - ^/_matrix/federation/(v1|unstable/org.matrix.msc2946)/hierarchy/ + - ^/_matrix/federation/v1/hierarchy/ # Inbound federation transaction request - ^/_matrix/federation/v1/send/ @@ -45,22 +42,24 @@ matrix_synapse_workers_generic_worker_endpoints: - ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/context/.*$ - ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/members$ - ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/state$ - - ^/_matrix/client/unstable/org.matrix.msc2946/rooms/.*/spaces$ - - ^/_matrix/client/(v1|unstable/org.matrix.msc2946)/rooms/.*/hierarchy$ + - ^/_matrix/client/v1/rooms/.*/hierarchy$ + - ^/_matrix/client/unstable/org.matrix.msc2716/rooms/.*/batch_send$ - ^/_matrix/client/unstable/im.nheko.summary/rooms/.*/summary$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/account/3pid$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/devices$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/keys/query$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/keys/changes$ + - ^/_matrix/client/(r0|v3|unstable)/account/3pid$ + - ^/_matrix/client/(r0|v3|unstable)/account/whoami$ + - ^/_matrix/client/(r0|v3|unstable)/devices$ - ^/_matrix/client/versions$ - ^/_matrix/client/(api/v1|r0|v3|unstable)/voip/turnServer$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/joined_groups$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/publicised_groups$ - - ^/_matrix/client/(api/v1|r0|v3|unstable)/publicised_groups/ - ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/event/ - ^/_matrix/client/(api/v1|r0|v3|unstable)/joined_rooms$ - ^/_matrix/client/(api/v1|r0|v3|unstable)/search$ + # Encryption requests + - ^/_matrix/client/(r0|v3|unstable)/keys/query$ + - ^/_matrix/client/(r0|v3|unstable)/keys/changes$ + - ^/_matrix/client/(r0|v3|unstable)/keys/claim$ + - ^/_matrix/client/(r0|v3|unstable)/room_keys/ + # Registration/login requests - ^/_matrix/client/(api/v1|r0|v3|unstable)/login$ - ^/_matrix/client/(r0|v3|unstable)/register$ @@ -74,11 +73,27 @@ matrix_synapse_workers_generic_worker_endpoints: - ^/_matrix/client/(api/v1|r0|v3|unstable)/join/ - ^/_matrix/client/(api/v1|r0|v3|unstable)/profile/ +# These appear to be conditional and should not be enabled by default. +# We need to fix up our workers-doc-to-yaml.awk parsing script to exclude them. +# For now, they've been commented out manually. +# # Account data requests +# - ^/_matrix/client/(r0|v3|unstable)/.*/tags +# - ^/_matrix/client/(r0|v3|unstable)/.*/account_data +# +# # Receipts requests +# - ^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt +# - ^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers +# +# # Presence requests +# - ^/_matrix/client/(api/v1|r0|v3|unstable)/presence/ + + # User directory search requests + - ^/_matrix/client/(r0|v3|unstable)/user_directory/search$ # Additionally, the following REST endpoints can be handled for GET requests: # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually - # ^/_matrix/federation/v1/groups/ + # ^/_matrix/client/(api/v1|r0|v3|unstable)/pushrules/ # Pagination requests can also be handled, but all requests for a given # room must be routed to the same instance. Additionally, care must be taken to @@ -155,16 +170,17 @@ matrix_synapse_workers_generic_worker_endpoints: # #### Stream writers - # Additionally, there is *experimental* support for moving writing of specific - # streams (such as events) off of the main process to a particular worker. (This - # is only supported with Redis-based replication.) - - # Currently supported streams are `events` and `typing`. + # Additionally, the writing of specific streams (such as events) can be moved off + # of the main process to a particular worker. + # (This is only supported with Redis-based replication.) # To enable this, the worker must have a HTTP replication listener configured, - # have a `worker_name` and be listed in the `instance_map` config. For example to - # move event persistence off to a dedicated worker, the shared configuration would - # include: + # have a `worker_name` and be listed in the `instance_map` config. The same worker + # can handle multiple streams, but unless otherwise documented, each stream can only + # have a single writer. + + # For example, to move event persistence off to a dedicated worker, the shared + # configuration would include: # ```yaml # instance_map: @@ -176,8 +192,20 @@ matrix_synapse_workers_generic_worker_endpoints: # events: event_persister1 # ``` - # The `events` stream also experimentally supports having multiple writers, where - # work is sharded between them by room ID. Note that you *must* restart all worker + # An example for a stream writer instance: + + # ```yaml + # {{#include systemd-with-workers/workers/event_persister.yaml}} + # ``` + + # Some of the streams have associated endpoints which, for maximum efficiency, should + # be routed to the workers handling that stream. See below for the currently supported + # streams and the endpoints associated with them: + + # ##### The `events` stream + + # The `events` stream experimentally supports having multiple writers, where work + # is sharded between them by room ID. Note that you *must* restart all worker # instances when adding or removing event persisters. An example `stream_writers` # configuration with multiple writers: @@ -188,9 +216,51 @@ matrix_synapse_workers_generic_worker_endpoints: # - event_persister2 # ``` + # ##### The `typing` stream + + # The following endpoints should be routed directly to the worker configured as + # the stream writer for the `typing` stream: + + # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually + # ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/typing + + # ##### The `to_device` stream + + # The following endpoints should be routed directly to the worker configured as + # the stream writer for the `to_device` stream: + + # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually + # ^/_matrix/client/(r0|v3|unstable)/sendToDevice/ + + # ##### The `account_data` stream + + # The following endpoints should be routed directly to the worker configured as + # the stream writer for the `account_data` stream: + + # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually + # ^/_matrix/client/(r0|v3|unstable)/.*/tags + # ^/_matrix/client/(r0|v3|unstable)/.*/account_data + + # ##### The `receipts` stream + + # The following endpoints should be routed directly to the worker configured as + # the stream writer for the `receipts` stream: + + # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually + # ^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt + # ^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers + + # ##### The `presence` stream + + # The following endpoints should be routed directly to the worker configured as + # the stream writer for the `presence` stream: + + # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually + # ^/_matrix/client/(api/v1|r0|v3|unstable)/presence/ + # #### Background tasks - # There is also *experimental* support for moving background tasks to a separate + # There is also support for moving background tasks to a separate # worker. Background tasks are run periodically or started via replication. Exactly # which tasks are configured to run depends on your Synapse configuration (e.g. if # stats is enabled). @@ -203,9 +273,58 @@ matrix_synapse_workers_generic_worker_endpoints: # run_background_tasks_on: background_worker # ``` - # You might also wish to investigate the `update_user_directory` and + # You might also wish to investigate the `update_user_directory_from_worker` and # `media_instance_running_background_jobs` settings. + # An example for a dedicated background worker instance: + + # ```yaml + # {{#include systemd-with-workers/workers/background_worker.yaml}} + # ``` + + # #### Updating the User Directory + + # You can designate one generic worker to update the user directory. + + # Specify its name in the shared configuration as follows: + + # ```yaml + # update_user_directory_from_worker: worker_name + # ``` + + # This work cannot be load-balanced; please ensure the main process is restarted + # after setting this option in the shared configuration! + + # User directory updates allow REST endpoints matching the following regular + # expressions to work: + + # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually + # ^/_matrix/client/(r0|v3|unstable)/user_directory/search$ + + # The above endpoints can be routed to any worker, though you may choose to route + # it to the chosen user directory worker. + + # This style of configuration supersedes the legacy `synapse.app.user_dir` + # worker application type. + + + # #### Notifying Application Services + + # You can designate one generic worker to send output traffic to Application Services. + + # Specify its name in the shared configuration as follows: + + # ```yaml + # notify_appservices_from_worker: worker_name + # ``` + + # This work cannot be load-balanced; please ensure the main process is restarted + # after setting this option in the shared configuration! + + # This style of configuration supersedes the legacy `synapse.app.appservice` + # worker application type. + + # pusher worker (no API endpoints) [ # Handles sending push notifications to sygnal and email. Doesn't handle any # REST endpoints itself, but you should set `start_pushers: False` in the @@ -223,6 +342,9 @@ matrix_synapse_workers_generic_worker_endpoints: # ] # appservice worker (no API endpoints) [ + # **Deprecated as of Synapse v1.59.** [Use `synapse.app.generic_worker` with the + # `notify_appservices_from_worker` option instead.](#notifying-application-services) + # Handles sending output traffic to Application Services. Doesn't handle any # REST endpoints itself, but you should set `notify_appservices: False` in the # shared configuration file to stop the main synapse sending appservice notifications. @@ -289,21 +411,33 @@ matrix_synapse_workers_media_repository_endpoints: # Note that if a reverse proxy is used , then `/_matrix/media/` must be routed for both inbound client and federation requests (if they are handled separately). matrix_synapse_workers_user_dir_endpoints: + # **Deprecated as of Synapse v1.59.** [Use `synapse.app.generic_worker` with the + # `update_user_directory_from_worker` option instead.](#updating-the-user-directory) + # Handles searches in the user directory. It can handle REST endpoints matching # the following regular expressions: - - ^/_matrix/client/(api/v1|r0|v3|unstable)/user_directory/search$ + - ^/_matrix/client/(r0|v3|unstable)/user_directory/search$ - # When using this worker you must also set `update_user_directory: False` in the + # When using this worker you must also set `update_user_directory: false` in the # shared configuration file to stop the main synapse running background # jobs related to updating the user directory. + # Above endpoint is not *required* to be routed to this worker. By default, + # `update_user_directory` is set to `true`, which means the main process + # will handle updates. All workers configured with `client` can handle the above + # endpoint as long as either this worker or the main process are configured to + # handle it, and are online. + + # If `update_user_directory` is set to `false`, and this worker is not running, + # the above endpoint may give outdated results. + matrix_synapse_workers_frontend_proxy_endpoints: # Proxies some frequently-requested client endpoints to add caching and remove # load from the main synapse. It can handle REST endpoints matching the following # regular expressions: - - ^/_matrix/client/(api/v1|r0|v3|unstable)/keys/upload + - ^/_matrix/client/(r0|v3|unstable)/keys/upload # If `use_presence` is False in the homeserver config, it can also handle REST # endpoints matching the following regular expressions: diff --git a/setup.yml b/setup.yml index 82429d43..a4d95da7 100755 --- a/setup.yml +++ b/setup.yml @@ -17,7 +17,9 @@ - matrix-bridge-appservice-slack - matrix-bridge-appservice-webhooks - matrix-bridge-appservice-irc + - matrix-bridge-appservice-kakaotalk - matrix-bridge-beeper-linkedin + - matrix-bridge-go-skype-bridge - matrix-bridge-mautrix-facebook - matrix-bridge-mautrix-twitter - matrix-bridge-mautrix-hangouts @@ -26,10 +28,10 @@ - matrix-bridge-mautrix-signal - matrix-bridge-mautrix-telegram - matrix-bridge-mautrix-whatsapp + - matrix-bridge-mautrix-discord - matrix-bridge-mx-puppet-discord - matrix-bridge-mx-puppet-groupme - matrix-bridge-mx-puppet-steam - - matrix-bridge-mx-puppet-skype - matrix-bridge-mx-puppet-slack - matrix-bridge-mx-puppet-twitter - matrix-bridge-mx-puppet-instagram @@ -37,6 +39,9 @@ - matrix-bridge-heisenbridge - matrix-bridge-hookshot - matrix-bot-matrix-reminder-bot + - matrix-bot-matrix-registration-bot + - matrix-bot-maubot + - matrix-bot-buscarron - matrix-bot-honoroit - matrix-bot-go-neb - matrix-bot-mjolnir @@ -45,6 +50,7 @@ - matrix-conduit - matrix-synapse-admin - matrix-prometheus-node-exporter + - matrix-prometheus-postgres-exporter - matrix-prometheus - matrix-grafana - matrix-registration @@ -57,10 +63,10 @@ - matrix-etherpad - matrix-email2matrix - matrix-sygnal + - matrix-ntfy - matrix-nginx-proxy - matrix-coturn - matrix-aux - matrix-postgres-backup - - matrix-prometheus-postgres-exporter - matrix-backup-borg - matrix-common-after