mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-01-11 18:40:24 +00:00
Add Matrix.to (#4750)
This commit is contained in:
100
roles/custom/matrix-matrixto/tasks/install.yml
Normal file
100
roles/custom/matrix-matrixto/tasks/install.yml
Normal file
@@ -0,0 +1,100 @@
|
||||
# SPDX-FileCopyrightText: 2023 - 2025 Slavi Pantaleev
|
||||
# SPDX-FileCopyrightText: 2025 Suguru Hirahara
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Ensure Matrix.to path exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: "0750"
|
||||
owner: "{{ matrix_user_name }}"
|
||||
group: "{{ matrix_group_name }}"
|
||||
with_items:
|
||||
- "{{ matrix_matrixto_base_path }}"
|
||||
|
||||
- name: Ensure Matrix.to support files installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/{{ item }}.j2"
|
||||
dest: "{{ matrix_matrixto_base_path }}/{{ item }}"
|
||||
mode: "0640"
|
||||
owner: "{{ matrix_user_name }}"
|
||||
group: "{{ matrix_group_name }}"
|
||||
with_items:
|
||||
- env
|
||||
- labels
|
||||
|
||||
- name: Run if self-building of Matrix.to container image is not enabled
|
||||
when: "not matrix_matrixto_container_image_self_build | bool"
|
||||
block:
|
||||
- name: Ensure Matrix.to container image is pulled via community.docker.docker_image
|
||||
when: devture_systemd_docker_base_container_image_pull_method == 'ansible-module'
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_matrixto_container_image }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_matrixto_container_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_matrixto_container_image_force_pull }}"
|
||||
register: result
|
||||
retries: "{{ devture_playbook_help_container_retries_count }}"
|
||||
delay: "{{ devture_playbook_help_container_retries_delay }}"
|
||||
until: result is not failed
|
||||
|
||||
- name: Ensure Matrix.to container image is pulled via ansible.builtin.command
|
||||
when: devture_systemd_docker_base_container_image_pull_method == 'command'
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ devture_systemd_docker_base_host_command_docker }} pull {{ matrix_matrixto_container_image }}"
|
||||
register: result
|
||||
retries: "{{ devture_playbook_help_container_retries_count }}"
|
||||
delay: "{{ devture_playbook_help_container_retries_delay }}"
|
||||
until: result is not failed
|
||||
changed_when: "'Downloaded newer image' in result.stdout"
|
||||
|
||||
- name: Run if self-building of Matrix.to container image is enabled
|
||||
when: "matrix_matrixto_container_image_self_build | bool"
|
||||
block:
|
||||
- name: Ensure Matrix.to repository is present on self-build
|
||||
ansible.builtin.git:
|
||||
repo: "{{ matrix_matrixto_container_image_self_build_repo }}"
|
||||
version: "{{ matrix_matrixto_container_image_self_build_repo_version }}"
|
||||
dest: "{{ matrix_matrixto_container_image_self_build_src_files_path }}"
|
||||
force: "yes"
|
||||
register: matrix_matrixto_git_pull_results
|
||||
|
||||
- name: Ensure Matrix.to container image is built
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_matrixto_container_image_self_build_name }}"
|
||||
source: build
|
||||
force_source: "{{ matrix_matrixto_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_matrixto_git_pull_results.changed }}"
|
||||
build:
|
||||
dockerfile: Dockerfile
|
||||
path: "{{ matrix_matrixto_container_image_self_build_src_files_path }}"
|
||||
pull: true
|
||||
args:
|
||||
|
||||
- name: Ensure Matrix.to container network is created via community.docker.docker_network
|
||||
when: devture_systemd_docker_base_container_network_creation_method == 'ansible-module'
|
||||
community.docker.docker_network:
|
||||
enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
|
||||
name: "{{ matrix_matrixto_container_network }}"
|
||||
driver: bridge
|
||||
driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
|
||||
|
||||
- name: Ensure Matrix.to container network is created via ansible.builtin.command
|
||||
when: devture_systemd_docker_base_container_network_creation_method == 'command'
|
||||
ansible.builtin.command:
|
||||
cmd: >-
|
||||
{{ devture_systemd_docker_base_host_command_docker }} network create
|
||||
{% if devture_systemd_docker_base_ipv6_enabled %}--ipv6{% endif %}
|
||||
{{ devture_systemd_docker_base_container_networks_driver_options_string }}
|
||||
{{ matrix_matrixto_container_network }}
|
||||
register: network_creation_result
|
||||
changed_when: network_creation_result.rc == 0
|
||||
failed_when: network_creation_result.rc != 0 and 'already exists' not in network_creation_result.stderr
|
||||
|
||||
- name: Ensure Matrix.to systemd service is present
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-matrixto.service.j2"
|
||||
dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ matrix_matrixto_identifier }}.service"
|
||||
mode: "0644"
|
||||
27
roles/custom/matrix-matrixto/tasks/main.yml
Normal file
27
roles/custom/matrix-matrixto/tasks/main.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
# SPDX-FileCopyrightText: 2023 Slavi Pantaleev
|
||||
# SPDX-FileCopyrightText: 2025 Suguru Hirahara
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Perform Matrix.to installation tasks
|
||||
when: matrix_matrixto_enabled | bool
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-matrixto
|
||||
- install-all
|
||||
- install-matrixto
|
||||
block:
|
||||
- name: Validate Matrix.to configuration
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
- name: Install Matrix.to
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/install.yml"
|
||||
|
||||
- name: Perform Matrix.to uninstallation tasks
|
||||
when: not matrix_matrixto_enabled | bool
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-matrixto
|
||||
block:
|
||||
- name: Uninstall Matrix.to
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/uninstall.yml"
|
||||
45
roles/custom/matrix-matrixto/tasks/uninstall.yml
Normal file
45
roles/custom/matrix-matrixto/tasks/uninstall.yml
Normal file
@@ -0,0 +1,45 @@
|
||||
# SPDX-FileCopyrightText: 2023 Slavi Pantaleev
|
||||
# SPDX-FileCopyrightText: 2025 Suguru Hirahara
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Check existence of Matrix.to systemd service
|
||||
ansible.builtin.stat:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/{{ matrix_matrixto_identifier }}.service"
|
||||
register: matrix_matrixto_service_stat
|
||||
|
||||
- name: Uninstall Matrix.to systemd services and files
|
||||
when: matrix_matrixto_service_stat.stat.exists | bool
|
||||
block:
|
||||
- name: Ensure Matrix.to systemd service is stopped
|
||||
ansible.builtin.service:
|
||||
name: "{{ matrix_matrixto_identifier }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
daemon_reload: true
|
||||
|
||||
- name: Ensure Matrix.to systemd service does not exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/{{ matrix_matrixto_identifier }}.service"
|
||||
state: absent
|
||||
|
||||
- name: Ensure Matrix.to container network does not exist via community.docker.docker_network
|
||||
when: devture_systemd_docker_base_container_network_creation_method == 'ansible-module'
|
||||
community.docker.docker_network:
|
||||
name: "{{ matrix_matrixto_container_network }}"
|
||||
state: absent
|
||||
|
||||
- name: Ensure Matrix.to container network does not exist via ansible.builtin.command
|
||||
when: devture_systemd_docker_base_container_network_creation_method == 'command'
|
||||
ansible.builtin.command:
|
||||
cmd: >-
|
||||
{{ devture_systemd_docker_base_host_command_docker }} network rm
|
||||
{{ matrix_matrixto_container_network }}
|
||||
register: network_deletion_result
|
||||
changed_when: matrix_matrixto_container_network in network_deletion_result.stdout
|
||||
|
||||
- name: Ensure Matrix.to path does not exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_matrixto_base_path }}"
|
||||
state: absent
|
||||
43
roles/custom/matrix-matrixto/tasks/validate_config.yml
Normal file
43
roles/custom/matrix-matrixto/tasks/validate_config.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
# SPDX-FileCopyrightText: 2023 Slavi Pantaleev
|
||||
# SPDX-FileCopyrightText: 2025 Suguru Hirahara
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Fail if required Matrix.to settings not defined
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
You need to define a required configuration setting (`{{ item }}`).
|
||||
when: "lookup('vars', item, default='') | string | length == 0"
|
||||
with_items:
|
||||
- matrix_matrixto_hostname
|
||||
- matrix_matrixto_path_prefix
|
||||
- matrix_matrixto_container_network
|
||||
|
||||
- name: Run if Traefik is enabled
|
||||
when: matrix_matrixto_container_labels_traefik_enabled | bool
|
||||
block:
|
||||
- name: Fail if Traefik settings required for Matrix.to are not defined
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
You need to define a required configuration setting (`{{ item }}`).
|
||||
when: "lookup('vars', item, default='') | string | length == 0"
|
||||
with_items:
|
||||
- matrix_matrixto_container_labels_traefik_hostname
|
||||
- matrix_matrixto_container_labels_traefik_path_prefix
|
||||
|
||||
- name: Fail if matrix_matrixto_container_labels_traefik_path_prefix is different than /
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
matrix_matrixto_container_labels_traefik_path_prefix (`{{ matrix_matrixto_container_labels_traefik_path_prefix }}`) must be `/`.
|
||||
Matrix.to does not support hosting under a subpath yet.
|
||||
when: "matrix_matrixto_container_labels_traefik_path_prefix != '/'"
|
||||
|
||||
# We ensure it doesn't end with a slash, because we handle both (slash and no-slash).
|
||||
# Knowing that `matrix_matrixto_container_labels_traefik_path_prefix` does not end with a slash
|
||||
# ensures we know how to set these routes up without having to do "does it end with a slash" checks elsewhere.
|
||||
- name: Fail if matrix_matrixto_container_labels_traefik_path_prefix ends with a slash
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
matrix_matrixto_container_labels_traefik_path_prefix (`{{ matrix_matrixto_container_labels_traefik_path_prefix }}`) must either be `/` or not end with a slash (e.g. `/matrixto`).
|
||||
when: "matrix_matrixto_container_labels_traefik_path_prefix != '/' and matrix_matrixto_container_labels_traefik_path_prefix[-1] == '/'"
|
||||
Reference in New Issue
Block a user