digitalboard.core/roles/traefik/tasks/main.yml
Simon Bärlocher 02d45026a5
feat: drop blanket recreates, ACME-DNS knobs, notify_push override
- Drop `recreate: always` from collabora/drawio/homarr/opencloud/traefik
  handlers and the authentik_outpost_ldap start task. `up -d` with
  `state: present` already recreates exactly the services whose
  compose definition changed; the blanket recreate was forcing
  restarts even when nothing relevant moved.
- Rewrite the `*_domains` Traefik Host loop to the `Host(\`a\`) ||
  Host(\`b\`)` form across authentik/collabora/garage/nextcloud so the
  rule still matches when traefik can't normalize the comma-form into
  the same canonical shape.
- Traefik: add `traefik_acme_tcp_only` (sets LEGO_EXPERIMENTAL_DNS_TCP_ONLY)
  and `traefik_acme_disable_ans_checks` (disables lego's authoritative-NS
  propagation check) for environments where the DNS path between the
  traefik container and the zone's nameservers is constrained.
- Traefik DMZ collector: two-step merge so a `traefik_dmz_exposed_services`
  entry that sets its own `backend_host` wins over the host fallback;
  lets a route target an internal FQDN covered by the backend cert's
  SANs instead of the raw IP.
- Nextcloud: add `nextcloud_notify_push_domain` override for the
  `occ notify_push:setup` call so the setup check can hit an internal
  FQDN instead of hairpinning through the DMZ. Push router now matches
  every entry in `nextcloud_domains`.
- Nextcloud: also %2F-escape slashes in the postgres user/password
  inside the notify_push DATABASE_URL.
2026-05-20 22:44:41 +02:00

108 lines
No EOL
3.4 KiB
YAML

#SPDX-License-Identifier: MIT-0
---
# tasks file for traefik
- name: Determine which backend servers to proxy (DMZ mode)
set_fact:
_backend_servers: "{{ traefik_backend_servers_to_proxy if traefik_backend_servers_to_proxy | length > 0 else groups['backend_servers'] | default([]) }}"
when: traefik_mode == 'dmz'
- name: Build service registry from backend servers (DMZ mode)
set_fact:
# Two-step merge so a service entry's own `backend_host` wins:
# entries that set it pass through unchanged, entries that don't
# get the backend host's ansible_host as fallback. The override
# lets a route target an internal FQDN covered by the backend
# cert's SANs instead of the raw IP (which would fail backend
# TLS verification at the proxy hop).
proxied_services: >-
{{
proxied_services | default([])
+ (hostvars[item].traefik_dmz_exposed_services | default([]) | selectattr('backend_host', 'defined') | list)
+ (hostvars[item].traefik_dmz_exposed_services | default([]) | rejectattr('backend_host', 'defined') | map('combine', {'backend_host': hostvars[item].ansible_host | default(item)}) | list)
}}
loop: "{{ _backend_servers | default([]) }}"
when: traefik_mode == 'dmz'
- name: Add directly defined services to registry (DMZ mode)
set_fact:
proxied_services: "{{ proxied_services | default([]) + traefik_services | default([]) }}"
when: traefik_mode == 'dmz'
- name: Debug service registry
debug:
var: proxied_services
when:
- traefik_mode == 'dmz'
- proxied_services is defined
- name: Create docker compose directory
file:
path: "{{ docker_compose_dir }}"
state: directory
mode: '0755'
- name: Create docker volume directory
file:
path: "{{ docker_volume_dir }}"
state: directory
mode: '0755'
- name: Create traefik config directory
file:
path: "{{ docker_volume_dir }}/config"
state: directory
mode: '0755'
- name: Create letsencrypt directory
file:
path: "{{ docker_volume_dir }}/letsencrypt"
state: directory
mode: '0755'
when: traefik_cert_mode == 'acme'
- name: Create traefik Docker network
community.docker.docker_network:
name: "{{ traefik_network }}"
state: present
- name: Generate traefik static configuration
template:
src: traefik.yml.j2
dest: "{{ docker_volume_dir }}/traefik.yml"
mode: '0644'
notify: restart traefik
- name: Generate traefik dynamic configuration for DMZ services
template:
src: services.yml.j2
dest: "{{ docker_volume_dir }}/config/services.yml"
mode: '0644'
notify: restart traefik
when: traefik_mode == 'dmz'
- name: Generate dashboard routing configuration
template:
src: dashboard.yml.j2
dest: "{{ docker_volume_dir }}/config/dashboard.yml"
mode: '0644'
notify: restart traefik
when: traefik_enable_dashboard | bool and traefik_dashboard_domain | length > 0
- name: Remove dashboard routing configuration when not needed
file:
path: "{{ docker_volume_dir }}/config/dashboard.yml"
state: absent
notify: restart traefik
when: not (traefik_enable_dashboard | bool) or traefik_dashboard_domain | length == 0
- name: Create docker-compose file for traefik
template:
src: docker-compose.yml.j2
dest: "{{ docker_compose_dir }}/docker-compose.yml"
mode: '0644'
- name: Start traefik container
community.docker.docker_compose_v2:
project_src: "{{ docker_compose_dir }}"
state: present