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:
52
roles/custom/matrix-dynamic-dns/defaults/main.yml
Normal file
52
roles/custom/matrix-dynamic-dns/defaults/main.yml
Normal file
@ -0,0 +1,52 @@
|
||||
---
|
||||
# Project source code URL: https://github.com/linuxserver/docker-ddclient
|
||||
|
||||
# Whether dynamic dns is enabled
|
||||
matrix_dynamic_dns_enabled: true
|
||||
|
||||
# The dynamic dns daemon interval
|
||||
matrix_dynamic_dns_daemon_interval: '300'
|
||||
|
||||
matrix_dynamic_dns_version: v3.10.0-ls103
|
||||
|
||||
# The docker container to use when in mode
|
||||
matrix_dynamic_dns_docker_image: "{{ matrix_dynamic_dns_docker_image_name_prefix }}linuxserver/ddclient:{{ matrix_dynamic_dns_version }}"
|
||||
|
||||
matrix_dynamic_dns_docker_image_name_prefix: "{{ 'localhost/' if matrix_dynamic_dns_container_image_self_build else matrix_container_global_registry_prefix }}"
|
||||
|
||||
# The image to force pull
|
||||
matrix_dynamic_dns_docker_image_force_pull: "{{ matrix_dynamic_dns_docker_image.endswith(':latest') }}"
|
||||
|
||||
# List of extra arguments to pass to the ontainer mode
|
||||
matrix_dynamic_dns_container_extra_arguments: []
|
||||
|
||||
# List of wanted services when running in mode
|
||||
matrix_dynamic_dns_systemd_wanted_services_list: []
|
||||
|
||||
# List of required services when running in mode
|
||||
matrix_dynamic_dns_systemd_required_services_list: ['docker.service']
|
||||
|
||||
# Build the container from source when running in mode
|
||||
matrix_dynamic_dns_container_image_self_build: false
|
||||
matrix_dynamic_dns_container_image_self_build_repo: "https://github.com/linuxserver/docker-ddclient.git"
|
||||
matrix_dynamic_dns_container_image_self_build_repo_branch: "{{ matrix_dynamic_dns_version }}"
|
||||
|
||||
# Config paths
|
||||
matrix_dynamic_dns_base_path: "{{ matrix_base_data_path }}/dynamic-dns"
|
||||
matrix_dynamic_dns_config_path: "{{ matrix_dynamic_dns_base_path }}/config"
|
||||
matrix_dynamic_dns_docker_src_files_path: "{{ matrix_dynamic_dns_base_path }}/docker-src"
|
||||
|
||||
# Holds the configurations (the domains to update DNS for, the providers they use, etc.)
|
||||
#
|
||||
# Example:
|
||||
# matrix_dynamic_dns_domain_configurations:
|
||||
# - provider: domains.google.com
|
||||
# protocol: dyndn2
|
||||
# username: XXXXXXXXXXXXXXXX
|
||||
# password: XXXXXXXXXXXXXXXX
|
||||
# domain: "{{ matrix_domain }}"
|
||||
matrix_dynamic_dns_domain_configurations: []
|
||||
|
||||
# Config options
|
||||
matrix_dynamic_dns_additional_configuration_blocks: []
|
||||
matrix_dynamic_dns_use: "web"
|
11
roles/custom/matrix-dynamic-dns/tasks/init.yml
Normal file
11
roles/custom/matrix-dynamic-dns/tasks/init.yml
Normal 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 Dynamic DNS 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_dynamic_dns_container_image_self_build and matrix_dynamic_dns_enabled"
|
||||
|
||||
- ansible.builtin.set_fact:
|
||||
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dynamic-dns.service'] }}"
|
||||
when: "matrix_dynamic_dns_enabled | bool"
|
69
roles/custom/matrix-dynamic-dns/tasks/install.yml
Normal file
69
roles/custom/matrix-dynamic-dns/tasks/install.yml
Normal file
@ -0,0 +1,69 @@
|
||||
---
|
||||
|
||||
- name: Ensure Dynamic DNS image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_dynamic_dns_docker_image }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_dynamic_dns_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_dynamic_dns_docker_image_force_pull }}"
|
||||
when: matrix_dynamic_dns_enabled | bool and not matrix_dynamic_dns_container_image_self_build
|
||||
register: result
|
||||
retries: "{{ matrix_container_retries_count }}"
|
||||
delay: "{{ matrix_container_retries_delay }}"
|
||||
until: result is not failed
|
||||
|
||||
- name: Ensure Dynamic DNS paths exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
mode: 0751
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
with_items:
|
||||
- {path: "{{ matrix_dynamic_dns_base_path }}", when: true}
|
||||
- {path: "{{ matrix_dynamic_dns_config_path }}", when: true}
|
||||
- {path: "{{ matrix_dynamic_dns_docker_src_files_path }}", when: "{{ matrix_dynamic_dns_container_image_self_build }}"}
|
||||
when: matrix_dynamic_dns_enabled | bool and item.when | bool
|
||||
|
||||
- name: Ensure Dynamic DNS repository is present on self build
|
||||
ansible.builtin.git:
|
||||
repo: "{{ matrix_dynamic_dns_container_image_self_build_repo }}"
|
||||
version: "{{ matrix_dynamic_dns_container_image_self_build_repo_branch }}"
|
||||
dest: "{{ matrix_dynamic_dns_docker_src_files_path }}"
|
||||
force: "yes"
|
||||
become: true
|
||||
become_user: "{{ matrix_user_username }}"
|
||||
register: matrix_dynamic_dns_git_pull_results
|
||||
when: "matrix_dynamic_dns_enabled | bool and matrix_dynamic_dns_container_image_self_build | bool"
|
||||
|
||||
- name: Ensure Dynamic DNS Docker image is built
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_dynamic_dns_docker_image }}"
|
||||
source: build
|
||||
force_source: "{{ matrix_dynamic_dns_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_dynamic_dns_git_pull_results.changed }}"
|
||||
build:
|
||||
dockerfile: Dockerfile
|
||||
path: "{{ matrix_dynamic_dns_docker_src_files_path }}"
|
||||
pull: true
|
||||
when: "matrix_dynamic_dns_enabled | bool and matrix_dynamic_dns_container_image_self_build | bool"
|
||||
|
||||
- name: Ensure Dynamic DNS ddclient.conf installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/ddclient.conf.j2"
|
||||
dest: "{{ matrix_dynamic_dns_config_path }}/ddclient.conf"
|
||||
mode: 0644
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure matrix-dynamic-dns.service installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-dynamic-dns.service.j2"
|
||||
dest: "/etc/systemd/system/matrix-dynamic-dns.service"
|
||||
mode: 0644
|
||||
register: matrix_dynamic_dns_systemd_service_result
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-dynamic-dns.service installation
|
||||
ansible.builtin.service:
|
||||
daemon_reload: true
|
||||
when: "matrix_dynamic_dns_systemd_service_result.changed"
|
23
roles/custom/matrix-dynamic-dns/tasks/main.yml
Normal file
23
roles/custom/matrix-dynamic-dns/tasks/main.yml
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- 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_dynamic_dns_enabled | bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-dynamic-dns
|
||||
|
||||
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/install.yml"
|
||||
when: "run_setup | bool and matrix_dynamic_dns_enabled | bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-dynamic-dns
|
||||
|
||||
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/uninstall.yml"
|
||||
when: "run_setup | bool and not matrix_dynamic_dns_enabled | bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-dynamic-dns
|
28
roles/custom/matrix-dynamic-dns/tasks/uninstall.yml
Normal file
28
roles/custom/matrix-dynamic-dns/tasks/uninstall.yml
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
|
||||
- name: Check existence of matrix-dynamic-dns service
|
||||
ansible.builtin.stat:
|
||||
path: "{{ matrix_systemd_path }}/matrix-dynamic-dns.service"
|
||||
register: matrix_dynamic_dns_service_stat
|
||||
|
||||
- name: Ensure matrix-dynamic-dns is stopped
|
||||
ansible.builtin.service:
|
||||
name: matrix-dynamic-dns
|
||||
state: stopped
|
||||
enabled: false
|
||||
daemon_reload: true
|
||||
when: "matrix_dynamic_dns_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure matrix-dynamic-dns.service doesn't exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_systemd_path }}/matrix-dynamic-dns.service"
|
||||
state: absent
|
||||
when: "matrix_dynamic_dns_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-dynamic-dns.service removal
|
||||
ansible.builtin.service:
|
||||
daemon_reload: true
|
||||
when: "matrix_dynamic_dns_service_stat.stat.exists"
|
||||
|
||||
# Intentionally not removing the Docker image when uninstalling.
|
||||
# We can't be sure it had been pulled by us in the first place.
|
16
roles/custom/matrix-dynamic-dns/tasks/validate_config.yml
Normal file
16
roles/custom/matrix-dynamic-dns/tasks/validate_config.yml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
|
||||
- name: Fail if no configurations specified
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
You need to define at least one configuration in `matrix_dynamic_dns_domain_configurations` for using matrix-dynamic-dns.
|
||||
when: "matrix_dynamic_dns_domain_configurations | length == 0"
|
||||
|
||||
- name: Fail if required settings not defined in configuration blocks
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
One of the configurations in matrix_dynamic_dns_domain_configurations is missing a required key (domain, provider, protocol).
|
||||
when: "'domain' not in configuration or 'provider' not in configuration or 'protocol' not in configuration"
|
||||
with_items: "{{ matrix_dynamic_dns_domain_configurations }}"
|
||||
loop_control:
|
||||
loop_var: configuration
|
26
roles/custom/matrix-dynamic-dns/templates/ddclient.conf.j2
Normal file
26
roles/custom/matrix-dynamic-dns/templates/ddclient.conf.j2
Normal file
@ -0,0 +1,26 @@
|
||||
daemon={{ matrix_dynamic_dns_daemon_interval }}
|
||||
syslog=no
|
||||
pid=/var/run/ddclient/ddclient.pid
|
||||
ssl=yes
|
||||
use={{ matrix_dynamic_dns_use }}
|
||||
|
||||
{% for dynamic_dns_domain_configuration in matrix_dynamic_dns_domain_configurations %}
|
||||
protocol={{ dynamic_dns_domain_configuration.protocol }}
|
||||
server={{ dynamic_dns_domain_configuration.provider }} {% if 'username' in dynamic_dns_domain_configuration %}
|
||||
login='{{ dynamic_dns_domain_configuration.username }}' {% endif %} {% if 'password' in dynamic_dns_domain_configuration %}
|
||||
password='{{ dynamic_dns_domain_configuration.password }}' {% endif %} {% if 'static' in dynamic_dns_domain_configuration %}
|
||||
static=yes {% endif %} {% if 'custom' in dynamic_dns_domain_configuration %}
|
||||
custom=yes {% endif %} {% if 'zone' in dynamic_dns_domain_configuration %}
|
||||
zone={{ dynamic_dns_domain_configuration.zone }} {% endif %} {% if 'ttl' in dynamic_dns_domain_configuration %}
|
||||
ttl={{ dynamic_dns_domain_configuration.ttl }} {% endif %} {% if 'mx' in dynamic_dns_domain_configuration %}
|
||||
mx={{ dynamic_dns_domain_configuration.mx }} {% endif %} {% if 'wildcard' in dynamic_dns_domain_configuration %}
|
||||
wildcard=yes {% endif %}
|
||||
{{ dynamic_dns_domain_configuration.domain }}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% for matrix_dynamic_dns_additional_configuration in matrix_dynamic_dns_additional_configuration_blocks %}
|
||||
{{ matrix_dynamic_dns_additional_configuration }}
|
||||
|
||||
{% endfor %}
|
@ -0,0 +1,36 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
[Unit]
|
||||
Description=Matrix Dynamic DNS
|
||||
{% for service in matrix_dynamic_dns_systemd_required_services_list %}
|
||||
Requires={{ service }}
|
||||
After={{ service }}
|
||||
{% endfor %}
|
||||
{% for service in matrix_dynamic_dns_systemd_wanted_services_list %}
|
||||
Wants={{ service }}
|
||||
{% endfor %}
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment="HOME={{ matrix_systemd_unit_home_path }}"
|
||||
ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-dynamic-dns 2>/dev/null || true'
|
||||
ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-dynamic-dns 2>/dev/null || true'
|
||||
ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-dynamic-dns \
|
||||
--log-driver=none \
|
||||
--network={{ matrix_docker_network }} \
|
||||
-e PUID={{ matrix_user_uid }} \
|
||||
-e PGID={{ matrix_user_gid }} \
|
||||
-v {{ matrix_dynamic_dns_config_path }}:/config:z \
|
||||
{% for arg in matrix_dynamic_dns_container_extra_arguments %}
|
||||
{{ arg }} \
|
||||
{% endfor %}
|
||||
{{ matrix_dynamic_dns_docker_image }}
|
||||
|
||||
ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-dynamic-dns 2>/dev/null || true'
|
||||
ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-dynamic-dns 2>/dev/null || true'
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
SyslogIdentifier=matrix-dynamic-dns
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Reference in New Issue
Block a user