From c96a0156c0d63f1aa4d07fc9c2b455ce5f0e99a4 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 13 Jan 2024 17:17:03 +0200 Subject: [PATCH] Make matrix-dynamic-dns use its own container network --- group_vars/matrix_servers | 2 ++ roles/custom/matrix-dynamic-dns/defaults/main.yml | 2 ++ roles/custom/matrix-dynamic-dns/tasks/setup_install.yml | 5 +++++ roles/custom/matrix-dynamic-dns/tasks/validate_config.yml | 8 ++++++++ .../templates/systemd/matrix-dynamic-dns.service.j2 | 2 +- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index fd9b2f754..5e3bd585d 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -2928,6 +2928,8 @@ etherpad_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_k matrix_dynamic_dns_enabled: false +matrix_dynamic_dns_container_network: matrix-dynamic-dns + ###################################################################### # # /matrix-dynamic-dns diff --git a/roles/custom/matrix-dynamic-dns/defaults/main.yml b/roles/custom/matrix-dynamic-dns/defaults/main.yml index bdf100eb6..ac4f533b9 100644 --- a/roles/custom/matrix-dynamic-dns/defaults/main.yml +++ b/roles/custom/matrix-dynamic-dns/defaults/main.yml @@ -18,6 +18,8 @@ matrix_dynamic_dns_docker_image_name_prefix: "{{ 'localhost/' if matrix_dynamic_ # The image to force pull matrix_dynamic_dns_docker_image_force_pull: "{{ matrix_dynamic_dns_docker_image.endswith(':latest') }}" +matrix_dynamic_dns_container_network: '' + # List of extra arguments to pass to the ontainer mode matrix_dynamic_dns_container_extra_arguments: [] diff --git a/roles/custom/matrix-dynamic-dns/tasks/setup_install.yml b/roles/custom/matrix-dynamic-dns/tasks/setup_install.yml index e64cc0a7d..17e13963d 100644 --- a/roles/custom/matrix-dynamic-dns/tasks/setup_install.yml +++ b/roles/custom/matrix-dynamic-dns/tasks/setup_install.yml @@ -56,6 +56,11 @@ owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" +- name: Ensure matrix-dynamic-dns container network is created + community.general.docker_network: + name: "{{ matrix_dynamic_dns_container_network }}" + driver: bridge + - name: Ensure matrix-dynamic-dns.service installed ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-dynamic-dns.service.j2" diff --git a/roles/custom/matrix-dynamic-dns/tasks/validate_config.yml b/roles/custom/matrix-dynamic-dns/tasks/validate_config.yml index 60adade89..8174a8487 100644 --- a/roles/custom/matrix-dynamic-dns/tasks/validate_config.yml +++ b/roles/custom/matrix-dynamic-dns/tasks/validate_config.yml @@ -14,3 +14,11 @@ with_items: "{{ matrix_dynamic_dns_domain_configurations }}" loop_control: loop_var: configuration + +- name: Fail if required mautrix-dynamic-dns settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item.name }}`). + when: "item.when | bool and vars[item.name] == ''" + with_items: + - {'name': 'matrix_dynamic_dns_container_network', when: true} diff --git a/roles/custom/matrix-dynamic-dns/templates/systemd/matrix-dynamic-dns.service.j2 b/roles/custom/matrix-dynamic-dns/templates/systemd/matrix-dynamic-dns.service.j2 index 8e3538085..08cdb84f1 100644 --- a/roles/custom/matrix-dynamic-dns/templates/systemd/matrix-dynamic-dns.service.j2 +++ b/roles/custom/matrix-dynamic-dns/templates/systemd/matrix-dynamic-dns.service.j2 @@ -17,7 +17,7 @@ ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_s ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-dynamic-dns 2>/dev/null || true' ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-dynamic-dns \ --log-driver=none \ - --network={{ matrix_docker_network }} \ + --network={{ matrix_dynamic_dns_container_network }} \ -e PUID={{ matrix_user_uid }} \ -e PGID={{ matrix_user_gid }} \ --mount type=bind,src={{ matrix_dynamic_dns_config_path }},dst=/config \