From 025a5ab5e5f6bdb3191b4c5e456b8141979a4d5f Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Fri, 17 Dec 2021 19:00:17 +0200 Subject: [PATCH] Add matrix_homeserver_implementation, tracking the current homeserver implementation The goal is to have a single variable which tells us which homeserver software is in use. Much simpler than having if/elif/elif checks for variables like (`matrix_synapse_enabled` and `matrix_dendrite_enabled`, etc.) everywhere. --- group_vars/matrix_servers | 11 +++++++++++ roles/matrix-base/defaults/main.yml | 7 +++++++ roles/matrix-base/tasks/sanity_check.yml | 11 +++++++++++ roles/matrix-base/vars/main.yml | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 65f14d501..19e243735 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -17,6 +17,17 @@ matrix_container_global_registry_prefix: "docker.io/" # ###################################################################### +matrix_homeserver_enabled_implementations_list: | + {{ + ( + (['synapse'] if matrix_synapse_enabled else []) + + + (['dendrite'] if matrix_dendrite_enabled else []) + ) + }} + +matrix_homeserver_implementation: "{{ matrix_homeserver_enabled_implementations_list[0] if matrix_homeserver_enabled_implementations_list|length == 1 else '' }}" + matrix_identity_server_url: "{{ ('https://' + matrix_server_fqn_matrix) if matrix_ma1sd_enabled else None }}" # If Synapse workers are enabled and matrix-nginx-proxy is disabled, certain APIs may not work over 'http://matrix-synapse:{{ matrix_synapse_container_client_api_port }}'. diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index 4767bcf43..34ef0145f 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -7,6 +7,13 @@ # Example value: example.com matrix_domain: ~ +# This will contain the homeserver implementation that is in use. +# Example values: 'synapse', 'dendrite', etc. +# You normally don't need to set this variable manually. +# Its value is automatically set depending on the homeserver implementation that you have enabled via other variables +# (e.g. `matrix_synapse_enabled`, `matrix_dendrite_enabled`, etc.) +matrix_homeserver_implementation: '' + # This is where your data lives and what we set up. # This and the Element FQN (see below) are expected to be on the same server. matrix_server_fqn_matrix: "matrix.{{ matrix_domain }}" diff --git a/roles/matrix-base/tasks/sanity_check.yml b/roles/matrix-base/tasks/sanity_check.yml index 265dc282d..1e525b80e 100644 --- a/roles/matrix-base/tasks/sanity_check.yml +++ b/roles/matrix-base/tasks/sanity_check.yml @@ -1,5 +1,16 @@ --- +- name: Fail if 0 or more than 1 homeserver implementations enabled + fail: + msg: >- + You have 0 or more than 1 homeserver implementations enabled + ({{ matrix_homeserver_enabled_implementations_list|join(', ') }}). + + If you have more than 1 implementation enabled, you can disable the unnecessary implementations by adding `matrix_IMPLEMENTATION_enabled: false` to your vars.yml file. + + If you have 0 implementations enabled, you can enable one by adding `matrix_IMPLEMENTATION_enabled: false` to your vars.yml file (e.g. `matrix_dendrite_enabled: true`). + when: "matrix_homeserver_enabled_implementations_list|length != 1" + # We generally support Ansible 2.7.1 and above. - name: Fail if running on Ansible < 2.7.1 fail: diff --git a/roles/matrix-base/vars/main.yml b/roles/matrix-base/vars/main.yml index e4e9c1668..8b99708b7 100644 --- a/roles/matrix-base/vars/main.yml +++ b/roles/matrix-base/vars/main.yml @@ -1,3 +1,3 @@ # This will contain a list of enabled services that the playbook is managing. # Each component is expected to append its service name to this list. -matrix_systemd_services_list: [] \ No newline at end of file +matrix_systemd_services_list: []