Move roles/matrix* to roles/custom/matrix*

This paves the way for installing other roles into `roles/galaxy` using `ansible-galaxy`,
similar to how it's done in:

- https://github.com/spantaleev/gitea-docker-ansible-deploy
- https://github.com/spantaleev/nextcloud-docker-ansible-deploy

In the near future, we'll be removing a lot of the shared role code from here
and using upstream roles for it. Some of the core `matrix-*` roles have
already been extracted out into other reusable roles:

- https://github.com/devture/com.devture.ansible.role.postgres
- https://github.com/devture/com.devture.ansible.role.systemd_docker_base
- https://github.com/devture/com.devture.ansible.role.timesync
- https://github.com/devture/com.devture.ansible.role.vars_preserver
- https://github.com/devture/com.devture.ansible.role.playbook_runtime_messages
- https://github.com/devture/com.devture.ansible.role.playbook_help

We just need to migrate to those.
This commit is contained in:
Slavi Pantaleev
2022-11-03 09:11:29 +02:00
parent 6c131138ad
commit 410a915a8a
722 changed files with 148 additions and 145 deletions

View File

@ -0,0 +1,11 @@
---
# 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 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"
- ansible.builtin.set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-corporal.service'] }}"
when: matrix_corporal_enabled | bool

View File

@ -0,0 +1,24 @@
---
- 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_corporal_enabled | bool"
tags:
- setup-all
- setup-corporal
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_corporal.yml"
when: run_setup | bool
tags:
- setup-all
- setup-corporal
- 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"
tags:
- self-check

View File

@ -0,0 +1,22 @@
---
- ansible.builtin.set_fact:
corporal_client_api_url_endpoint_public: "https://{{ matrix_server_fqn_matrix }}/_matrix/client/corporal"
- name: Check Matrix Corporal HTTP gateway
ansible.builtin.uri:
url: "{{ corporal_client_api_url_endpoint_public }}"
follow_redirects: none
return_content: true
check_mode: false
register: result_corporal_client_api
ignore_errors: true
- name: Fail if Matrix Corporal HTTP gateway not working
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
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 }}`)"

View File

@ -0,0 +1,121 @@
---
#
# Tasks related to setting up matrix-corporal
#
- name: Ensure Matrix Corporal paths exist
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: 0750
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
with_items:
- "{{ matrix_corporal_config_dir_path }}"
- "{{ matrix_corporal_cache_dir_path }}"
- "{{ matrix_corporal_var_dir_path }}"
when: matrix_corporal_enabled | bool
- name: Ensure Matrix Corporal repository is present on self-build
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] }}"
force: "yes"
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"
- name: Ensure Matrix Corporal Docker image is built
community.docker.docker_image:
name: "{{ matrix_corporal_docker_image }}"
source: build
force_source: "{{ matrix_corporal_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_corporal_git_pull_results.changed }}"
build:
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"
- name: Ensure Matrix Corporal Docker image is pulled
community.docker.docker_image:
name: "{{ matrix_corporal_docker_image }}"
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"
register: result
retries: "{{ matrix_container_retries_count }}"
delay: "{{ matrix_container_retries_delay }}"
until: result is not failed
- name: Ensure Matrix Corporal config installed
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
- name: Ensure matrix-corporal.service installed
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
- name: Ensure systemd reloaded after matrix-corporal.service installation
ansible.builtin.service:
daemon_reload: true
when: "matrix_corporal_enabled | bool and matrix_corporal_systemd_service_result.changed"
#
# Tasks related to getting rid of matrix-corporal (if it was previously enabled)
#
- name: Check existence of matrix-corporal service
ansible.builtin.stat:
path: "{{ matrix_systemd_path }}/matrix-corporal.service"
register: matrix_corporal_service_stat
when: "not matrix_corporal_enabled | bool"
- name: Ensure matrix-corporal is stopped
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"
- name: Ensure matrix-corporal.service doesn't exist
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"
- name: Ensure systemd reloaded after matrix-corporal.service removal
ansible.builtin.service:
daemon_reload: true
when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists"
- name: Ensure matrix-corporal files don't exist
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"
- name: Ensure Matrix Corporal Docker image doesn't exist
community.docker.docker_image:
name: "{{ matrix_corporal_docker_image }}"
state: absent
when: "not matrix_corporal_enabled | bool"

View File

@ -0,0 +1,27 @@
---
- name: Fail if required matrix-corporal settings not defined
ansible.builtin.fail:
msg: >-
You need to define a required configuration setting (`{{ item }}`) for using matrix-corporal.
when: "vars[item] == ''"
with_items:
- "matrix_corporal_matrix_homeserver_api_endpoint"
- "matrix_corporal_matrix_auth_shared_secret"
- "matrix_corporal_matrix_registration_shared_secret"
- "matrix_corporal_policy_provider_config"
- name: Fail if HTTP API enabled, but no token set
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 == ''"
- name: (Deprecation) Catch and report renamed corporal variables
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_corporal_container_expose_ports', 'new': '<superseded by matrix_corporal_container_http_gateway_host_bind_port and matrix_corporal_container_http_api_host_bind_port>'}
- {'old': 'matrix_corporal_reconciliation_user_id_local_part', 'new': 'matrix_corporal_corporal_user_id_local_part'}