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,48 @@
---
# Project source code URL: https://github.com/binwiederhier/ntfy
matrix_ntfy_enabled: true
matrix_ntfy_base_path: "{{ matrix_base_data_path }}/ntfy"
matrix_ntfy_config_dir_path: "{{ matrix_ntfy_base_path }}/config"
matrix_ntfy_data_path: "{{ matrix_ntfy_base_path }}/data"
matrix_ntfy_version: v1.28.0
matrix_ntfy_docker_image: "{{ matrix_container_global_registry_prefix }}binwiederhier/ntfy:{{ matrix_ntfy_version }}"
matrix_ntfy_docker_image_force_pull: "{{ matrix_ntfy_docker_image.endswith(':latest') }}"
# Public facing base URL of the ntfy service
matrix_ntfy_base_url: "https://{{ matrix_server_fqn_ntfy }}"
# Controls whether the container exposes its HTTP port (tcp/80 in the container).
#
# Takes an "<ip>:<port>" or "<port>" value (e.g. "127.0.0.1:2586"), or empty string to not expose.
matrix_ntfy_container_http_host_bind_port: ''
# A list of extra arguments to pass to the container (`docker run` command)
matrix_ntfy_container_extra_arguments: []
# Controls whether the self-check feature should validate SSL certificates.
matrix_ntfy_self_check_validate_certificates: true
# Default ntfy 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_ntfy_configuration_extension_yaml`)
# or completely replace this variable with your own template.
matrix_ntfy_configuration_yaml: "{{ lookup('template', 'templates/ntfy/server.yml.j2') }}"
matrix_ntfy_configuration_extension_yaml: |
# Your custom YAML configuration for ntfy goes here.
# This configuration extends the default starting configuration (`matrix_ntfy_configuration_yaml`).
#
# 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_ntfy_configuration_yaml`.
matrix_ntfy_configuration_extension: "{{ matrix_ntfy_configuration_extension_yaml | from_yaml if matrix_ntfy_configuration_extension_yaml | from_yaml is mapping else {} }}"
# Holds the final ntfy configuration (a combination of the default and its extension).
# You most likely don't need to touch this variable. Instead, see `matrix_ntfy_configuration_yaml`.
matrix_ntfy_configuration: "{{ matrix_ntfy_configuration_yaml | from_yaml | combine(matrix_ntfy_configuration_extension, recursive=True) }}"

View File

@ -0,0 +1,5 @@
---
- ansible.builtin.set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ntfy.service'] }}"
when: matrix_ntfy_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/setup_install.yml"
when: "run_setup | bool and matrix_ntfy_enabled | bool"
tags:
- setup-all
- setup-ntfy
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml"
when: "run_setup | bool and not matrix_ntfy_enabled | bool"
tags:
- setup-all
- setup-ntfy
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml"
delegate_to: 127.0.0.1
become: false
when: "run_self_check | bool and matrix_ntfy_enabled | bool"
tags:
- self-check

View File

@ -0,0 +1,25 @@
---
# Query an arbitrary ntfy topic using ntfy's UnifiedPush topic name syntax.
# Expect an empty response (because we query 'since=1s').
- ansible.builtin.set_fact:
matrix_ntfy_url_endpoint_public: "{{ matrix_ntfy_base_url }}/upSELFCHECK123/json?poll=1&since=1s"
- name: Check ntfy
ansible.builtin.uri:
url: "{{ matrix_ntfy_url_endpoint_public }}"
follow_redirects: none
validate_certs: "{{ matrix_ntfy_self_check_validate_certificates }}"
register: matrix_ntfy_self_check_result
check_mode: false
ignore_errors: true
- name: Fail if ntfy not working
ansible.builtin.fail:
msg: "Failed checking ntfy is up at `{{ matrix_server_fqn_ntfy }}` (checked endpoint: `{{ matrix_ntfy_url_endpoint_public }}`). Is ntfy running? Is port 443 open in your firewall? Full error: {{ matrix_ntfy_self_check_result }}"
when: "matrix_ntfy_self_check_result.failed"
- name: Report working ntfy
ansible.builtin.debug:
msg: "ntfy at `{{ matrix_server_fqn_ntfy }}` is working (checked endpoint: `{{ matrix_ntfy_url_endpoint_public }}`)"

View File

@ -0,0 +1,44 @@
---
- name: Ensure matrix-ntfy image is pulled
community.docker.docker_image:
name: "{{ matrix_ntfy_docker_image }}"
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
force_source: "{{ matrix_ntfy_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_ntfy_docker_image_force_pull }}"
register: result
retries: "{{ matrix_container_retries_count }}"
delay: "{{ matrix_container_retries_delay }}"
until: result is not failed
- name: Ensure matrix-ntfy paths exists
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: 0750
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
with_items:
- "{{ matrix_ntfy_base_path }}"
- "{{ matrix_ntfy_config_dir_path }}"
- "{{ matrix_ntfy_data_path }}"
- name: Ensure matrix-ntfy config installed
ansible.builtin.copy:
content: "{{ matrix_ntfy_configuration | to_nice_yaml(indent=2, width=999999) }}"
dest: "{{ matrix_ntfy_config_dir_path }}/server.yml"
mode: 0644
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
- name: Ensure matrix-ntfy.service installed
ansible.builtin.template:
src: "{{ role_path }}/templates/systemd/matrix-ntfy.service.j2"
dest: "{{ matrix_systemd_path }}/matrix-ntfy.service"
mode: 0644
register: matrix_ntfy_systemd_service_result
- name: Ensure systemd reloaded after matrix-ntfy.service installation
ansible.builtin.service:
daemon_reload: true
when: "matrix_ntfy_systemd_service_result.changed"

View File

@ -0,0 +1,36 @@
---
- name: Check existence of matrix-ntfy service
ansible.builtin.stat:
path: "{{ matrix_systemd_path }}/matrix-ntfy.service"
register: matrix_ntfy_service_stat
- name: Ensure matrix-ntfy is stopped
ansible.builtin.service:
name: matrix-ntfy
state: stopped
enabled: false
daemon_reload: true
register: stopping_result
when: "matrix_ntfy_service_stat.stat.exists"
- name: Ensure matrix-ntfy.service doesn't exist
ansible.builtin.file:
path: "{{ matrix_systemd_path }}/matrix-ntfy.service"
state: absent
when: "matrix_ntfy_service_stat.stat.exists"
- name: Ensure systemd reloaded after matrix-ntfy.service removal
ansible.builtin.service:
daemon_reload: true
when: "matrix_ntfy_service_stat.stat.exists"
- name: Ensure matrix-ntfy path doesn't exist
ansible.builtin.file:
path: "{{ matrix_ntfy_base_path }}"
state: absent
- name: Ensure ntfy Docker image doesn't exist
community.docker.docker_image:
name: "{{ matrix_ntfy_docker_image }}"
state: absent

View File

@ -0,0 +1,4 @@
base_url: {{ matrix_ntfy_base_url }}
behind_proxy: true
cache_file: /data/cache.db
listen-http: :8080

View File

@ -0,0 +1,38 @@
#jinja2: lstrip_blocks: "True"
[Unit]
Description=matrix-ntfy
After=docker.service
Requires=docker.service
DefaultDependencies=no
[Service]
Type=simple
Environment="HOME={{ matrix_systemd_unit_home_path }}"
ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-ntfy 2>/dev/null || true'
ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-ntfy 2>/dev/null || true'
ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-ntfy \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--read-only \
{% for arg in matrix_ntfy_container_extra_arguments %}
{{ arg }} \
{% endfor %}
--network={{ matrix_docker_network }} \
{% if matrix_ntfy_container_http_host_bind_port %}
-p {{ matrix_ntfy_container_http_host_bind_port }}:8080 \
{% endif %}
--mount type=bind,src={{ matrix_ntfy_config_dir_path }},dst=/etc/ntfy,ro \
--mount type=bind,src={{ matrix_ntfy_data_path }},dst=/data \
{{ matrix_ntfy_docker_image }} \
serve
ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-ntfy 2>/dev/null || true'
ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-ntfy 2>/dev/null || true'
Restart=always
RestartSec=30
SyslogIdentifier=matrix-ntfy
[Install]
WantedBy=multi-user.target