Riot is now Element

Fixes #586 (Github Issue)
This commit is contained in:
Slavi Pantaleev
2020-07-17 11:31:20 +03:00
parent de0efe96e7
commit c6ab1c6a90
54 changed files with 792 additions and 622 deletions

View File

@ -0,0 +1,10 @@
- set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-element'] }}"
when: matrix_client_element_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:
msg: "To self build the Element 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_client_element_container_image_self_build"

View File

@ -0,0 +1,34 @@
- 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"
tags:
- setup-all
- setup-client-element
- 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
tags:
- setup-all
- setup-client-element
- import_tasks: "{{ role_path }}/tasks/setup.yml"
when: run_setup|bool
tags:
- setup-all
- setup-client-element
- 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"
tags:
- self-check

View File

@ -0,0 +1,36 @@
---
- name: Check existence of matrix-riot-web.service
stat:
path: "{{ matrix_systemd_path }}/matrix-riot-web.service"
register: matrix_client_riot_web_service_stat
when: "matrix_client_element_enabled|bool"
- name: Ensure matrix-riot-web is stopped
service:
name: matrix-riot-web
state: stopped
daemon_reload: yes
register: stopping_result
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:
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"
- name: Ensure systemd reloaded after matrix-riot-web.service removal
service:
daemon_reload: yes
when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists"
- name: Check existence of /matrix/riot-web
stat:
path: "/matrix/riot-web"
register: matrix_client_riot_web_dir_stat
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"

View File

@ -0,0 +1,48 @@
---
#
# Tasks related to setting up Element themes
#
- block:
- name: Ensure Element themes repository is pulled
git:
repo: "{{ matrix_client_element_themes_repository_url }}"
dest: "{{ role_path }}/files/scratchpad/themes"
- name: Find all Element theme files
find:
paths: "{{ role_path }}/files/scratchpad/themes"
patterns: "*.json"
recurse: true
register: matrix_client_element_theme_file_list
- name: Read Element theme
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] }}"
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
#
# Tasks related to getting rid of Element themes (if it was previously enabled)
#
- name: Ensure Element themes repository is removed
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"

View File

@ -0,0 +1,22 @@
---
- set_fact:
matrix_client_element_url_endpoint_public: "https://{{ matrix_server_fqn_element }}/config.json"
- name: Check Element
uri:
url: "{{ matrix_client_element_url_endpoint_public }}"
follow_redirects: none
validate_certs: "{{ matrix_client_element_self_check_validate_certificates }}"
register: matrix_client_element_self_check_result
check_mode: no
ignore_errors: true
- name: Fail if Element not working
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:
msg: "Element at `{{ matrix_server_fqn_element }}` is working (checked endpoint: `{{ matrix_client_element_url_endpoint_public }}`)"

View File

@ -0,0 +1,127 @@
---
#
# Tasks related to setting up Element
#
- name: Ensure Element paths exists
file:
path: "{{ item.path }}"
state: directory
mode: 0750
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
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: matrix_client_element_enabled|bool and item.when
- name: Ensure Element Docker image is pulled
docker_image:
name: "{{ matrix_client_element_docker_image }}"
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: matrix_client_element_enabled|bool and not matrix_client_element_container_image_self_build
- name: Ensure Element repository is present on self-build
git:
repo: https://github.com/vector-im/riot-web.git
dest: "{{ matrix_client_element_docker_src_files_path }}"
version: "{{ matrix_client_element_docker_image.split(':')[1] }}"
force: "yes"
when: "matrix_client_element_enabled|bool and matrix_client_element_container_image_self_build"
- name: Ensure Element Docker image is built
docker_image:
name: "{{ matrix_client_element_docker_image }}"
source: build
build:
dockerfile: Dockerfile
path: "{{ matrix_client_element_docker_src_files_path }}"
pull: yes
when: "matrix_client_element_enabled|bool and matrix_client_element_container_image_self_build"
- name: Ensure Element configuration installed
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 }}"
when: matrix_client_element_enabled|bool
- name: Ensure Element config files installed
template:
src: "{{ item.src }}"
dest: "{{ matrix_client_element_data_path }}/{{ item.name }}"
mode: 0644
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
with_items:
- {src: "{{ role_path }}/templates/nginx.conf.j2", name: "nginx.conf"}
- {src: "{{ role_path }}/templates/welcome.html.j2", name: "welcome.html"}
- {src: "{{ matrix_client_element_embedded_pages_home_path }}", name: "home.html"}
when: "matrix_client_element_enabled|bool and item.src is not none"
- name: Ensure Element config files removed
file:
path: "{{ matrix_client_element_data_path }}/{{ item.name }}"
state: absent
with_items:
- {src: "{{ matrix_client_element_embedded_pages_home_path }}", name: "home.html"}
when: "matrix_client_element_enabled|bool and item.src is none"
- name: Ensure matrix-client-element.service installed
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
when: matrix_client_element_enabled|bool
- name: Ensure systemd reloaded after matrix-client-element.service installation
service:
daemon_reload: yes
when: "matrix_client_element_enabled and matrix_client_element_systemd_service_result.changed"
#
# Tasks related to getting rid of Element (if it was previously enabled)
#
- name: Check existence of matrix-client-element.service
stat:
path: "{{ matrix_systemd_path }}/matrix-client-element.service"
register: matrix_client_element_service_stat
when: "not matrix_client_element_enabled|bool"
- name: Ensure matrix-client-element is stopped
service:
name: matrix-client-element
state: stopped
daemon_reload: yes
register: stopping_result
when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists"
- name: Ensure matrix-client-element.service doesn't exist
file:
path: "{{ matrix_systemd_path }}/matrix-client-element.service"
state: absent
when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists"
- name: Ensure systemd reloaded after matrix-client-element.service removal
service:
daemon_reload: yes
when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists"
- name: Ensure Element paths doesn't exist
file:
path: "{{ matrix_client_element_data_path }}"
state: absent
when: "not matrix_client_element_enabled|bool"
- name: Ensure Element Docker image doesn't exist
docker_image:
name: "{{ matrix_client_element_docker_image }}"
state: absent
when: "not matrix_client_element_enabled|bool"

View File

@ -0,0 +1,20 @@
---
- name: Fail if required Element settings not defined
fail:
msg: >
You need to define a required configuration setting (`{{ item }}`) for using Element.
when: "vars[item] == ''"
with_items:
- "matrix_client_element_default_hs_url"
- name: (Deprecation) Catch and report riot-web variables
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.
Please change your configuration (vars.yml) to rename all riot-web variables (`{{ item.old }}` -> `{{ item.new }}`).
Also note that DNS configuration changes may be necessary.
when: "vars | dict2items | selectattr('key', 'match', item.old) | list | items2dict"
with_items:
- {'old': 'matrix_riot_web_.*', 'new': 'matrix_client_element_.*'}