From 0edd7e808985e59524a76f0f1156d42c83b8a1e6 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sun, 25 Aug 2019 10:37:05 +0300 Subject: [PATCH] Make Riot-web configuration extensible Fixes #71 (Github Issue). --- CHANGELOG.md | 14 ++++++++ docs/configuring-playbook-riot-web.md | 29 ++++++++++++++++ docs/configuring-playbook.md | 2 ++ roles/matrix-riot-web/defaults/main.yml | 33 +++++++++++++++++++ .../matrix-riot-web/tasks/setup_riot_web.yml | 9 ++++- .../matrix-riot-web/templates/config.json.j2 | 1 - 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 docs/configuring-playbook-riot-web.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f96fa76..427a0f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# 2019-08-25 + +## Extensible Riot-web configuration + +Similarly to [Extensible Synapse configuration](#extensible-synapse-configuration) (below), Riot-web configuration is also extensible now. + +From now on, you can extend/override Riot-web's configuration by making use of the `matrix_riot_web_configuration_extension_json` variable. +This should be enough for most customization needs. + +If you need even more power, you can now also take full control and override `matrix_riot_web_configuration_default` (or `matrix_riot_web_configuration`) directly. + +Learn more here in [Configuring Riot-web](docs/configuring-playbook-riot-web.md). + + # 2019-08-22 ## Extensible Synapse configuration diff --git a/docs/configuring-playbook-riot-web.md b/docs/configuring-playbook-riot-web.md new file mode 100644 index 00000000..af8e2175 --- /dev/null +++ b/docs/configuring-playbook-riot-web.md @@ -0,0 +1,29 @@ +# Configuring Riot-web (optional) + +By default, this playbook installs the [Riot-web](https://github.com/vector-im/riot-web) Matrix client web application. +If that's okay, you can skip this document. + + +## Disabling riot-web + +If you'd like for the playbook to not install (or to uninstall the previously installed riot-web), you can disable it in your configuration file (`inventory/host_vars/matrix./vars.yml`): + +```yaml +matrix_riot_web_enabled: false +``` + +## Configuring riot-web settings + +The playbook provides some customization variables you could use to change riot-web's settings. + +Their defaults are defined in [`roles/matrix-riot-web/defaults/main.yml`](../roles/matrix-riot-web/defaults/main.yml) and they ultimately end up in the generated `/matrix/riot-web/config.json` file (on the server). This file is generated from the [`roles/matrix-riot-web/templates/config.json.j2`](../roles/matrix-riot-web/templates/config.json.j2) template. + +**If there's an existing variable** which controls a setting you wish to change, you can simply define that variable in your configuration file (`inventory/host_vars/matrix./vars.yml`) and [re-run the playbook](installing.md) to apply the changes. + +Alternatively, **if there is no pre-defined variable** for a riot-web setting you wish to change: + +- you can either **request a variable to be created** (or you can submit such a contribution yourself). Keep in mind that it's **probably not a good idea** to create variables for each one of riot-web's various settings that rarely get used. + +- or, you can **extend and override the default configuration** ([`config.json.j2`](../roles/matrix-riot-web/templates/config.json.j2)) by making use of the `matrix_riot_web_configuration_extension_json_` variable. You can find information about this in [`roles/matrix-riot-web/defaults/main.yml`](../roles/matrix-riot-web/defaults/main.yml). + +- or, if extending the configuration is still not powerful enough for your needs, you can **override the configuration completely** using `matrix_riot_web_configuration_default` (or `matrix_riot_web_configuration`). You can find information about this in [`roles/matrix-riot-web/defaults/main.yml`](../roles/matrix-riot-web/defaults/main.yml). diff --git a/docs/configuring-playbook.md b/docs/configuring-playbook.md index 11a55795..e541ad56 100644 --- a/docs/configuring-playbook.md +++ b/docs/configuring-playbook.md @@ -36,6 +36,8 @@ When you're done with all the configuration you'd like to do, continue with [Ins - [Configuring Synapse](configuring-playbook-synapse.md) (optional) +- [Configuring Riot-web](configuring-playbook-riot-web.md) (optional) + - [Storing Matrix media files on Amazon S3](configuring-playbook-s3.md) (optional) - [Using an external PostgreSQL server](configuring-playbook-external-postgres.md) (optional) diff --git a/roles/matrix-riot-web/defaults/main.yml b/roles/matrix-riot-web/defaults/main.yml index 93f322af..1816731d 100644 --- a/roles/matrix-riot-web/defaults/main.yml +++ b/roles/matrix-riot-web/defaults/main.yml @@ -43,3 +43,36 @@ matrix_riot_web_registration_enabled: false # Controls whether Riot shows the presence features matrix_riot_web_enable_presence_by_hs_url: ~ + +# Default riot-web 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_riot_web_configuration_extension_json`) +# 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_riot_web_configuration_default: "{{ lookup('template', 'templates/config.json.j2') }}" + +# Your custom JSON configuration for riot-web should go to `matrix_riot_web_configuration_extension_json`. +# This configuration extends the default starting configuration (`matrix_riot_web_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_riot_web_configuration_default`. +# +# Example configuration extension follows: +# +# matrix_riot_web_configuration_extension_json: | +# { +# "disable_3pid_login": true, +# "disable_login_language_selector": true +# } +matrix_riot_web_configuration_extension_json: '{}' + +matrix_riot_web_configuration_extension: "{{ matrix_riot_web_configuration_extension_json|from_json if matrix_riot_web_configuration_extension_json|from_json is mapping else {} }}" + +# Holds the final riot-web configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_riot_web_configuration_default`. +matrix_riot_web_configuration: "{{ matrix_riot_web_configuration_default|combine(matrix_riot_web_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-riot-web/tasks/setup_riot_web.yml b/roles/matrix-riot-web/tasks/setup_riot_web.yml index f72d4369..dcb3b5e7 100644 --- a/roles/matrix-riot-web/tasks/setup_riot_web.yml +++ b/roles/matrix-riot-web/tasks/setup_riot_web.yml @@ -21,6 +21,14 @@ force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_riot_web_docker_image_force_pull }}" when: matrix_riot_web_enabled|bool +- name: Ensure Matrix riot-web configuration installed + copy: + content: "{{ matrix_riot_web_configuration|to_nice_json }}" + dest: "{{ matrix_riot_web_data_path }}/config.json" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_username }}" + - name: Ensure Matrix riot-web config files installed template: src: "{{ item.src }}" @@ -29,7 +37,6 @@ owner: "{{ matrix_user_username }}" group: "{{ matrix_user_username }}" with_items: - - {src: "{{ role_path }}/templates/config.json.j2", name: "config.json"} - {src: "{{ role_path }}/templates/nginx.conf.j2", name: "nginx.conf"} - {src: "{{ role_path }}/templates/welcome.html.j2", name: "welcome.html"} - {src: "{{ matrix_riot_web_embedded_pages_home_path }}", name: "home.html"} diff --git a/roles/matrix-riot-web/templates/config.json.j2 b/roles/matrix-riot-web/templates/config.json.j2 index c5e5cad0..69fb1393 100644 --- a/roles/matrix-riot-web/templates/config.json.j2 +++ b/roles/matrix-riot-web/templates/config.json.j2 @@ -1,4 +1,3 @@ -#jinja2: lstrip_blocks: "True" { "default_hs_url": {{ matrix_riot_web_default_hs_url|string|to_json }}, "default_is_url": {{ matrix_riot_web_default_is_url|string|to_json }},