From 4a5a0beca18a90e94456ec85f058d1993345ef63 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 19 Jul 2025 10:12:56 +0200 Subject: [PATCH] restic: Fix backup container conditionals Change the inclusion of backup containers so they actually work. They check that restic is enabled globally, and that restic is enabled for the individual stack they belong to. If either of the conditions is not met they do not deploy. This way we can simply enable restic globally with `restic_enable` and by default all stacks will be backed up. But if we want to exclude specific stacks from backups we can do so with the individual `_restic_enable = False` variable. Finally found a good version of doing so with the help of the following medium article: https://medium.com/opsops/is-defined-in-ansible-d490945611ae which basically makes use of default fallbacks instead. --- roles/arr/templates/compose.yaml.jinja | 2 +- roles/grocy/templates/compose.yaml.jinja | 2 +- roles/paperless/templates/compose.yaml.jinja | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/arr/templates/compose.yaml.jinja b/roles/arr/templates/compose.yaml.jinja index 19181dd..c61e3d0 100644 --- a/roles/arr/templates/compose.yaml.jinja +++ b/roles/arr/templates/compose.yaml.jinja @@ -290,7 +290,7 @@ services: caddy: "{{ arrstack_gonic_subdomain }}" caddy.reverse_proxy: "{{ '{{' }}upstreams 80{{ '}}'}}" -{% if restic_enable is not undefined and not false and arrstack_restic_enable is not undefined and not false %} +{% if restic_enable|d(False) == True and arrstack_restic_enable|d(False) == True %} backup: image: mazzolino/restic hostname: "{{ ansible_hostname | default() }}" diff --git a/roles/grocy/templates/compose.yaml.jinja b/roles/grocy/templates/compose.yaml.jinja index b3b1cc0..8b75bd6 100644 --- a/roles/grocy/templates/compose.yaml.jinja +++ b/roles/grocy/templates/compose.yaml.jinja @@ -16,7 +16,7 @@ services: caddy: "{{ stack_grocy_subdomain }}" caddy.reverse_proxy: "{{ '{{' }}upstreams 80{{ '}}'}}" -{% if restic_enable is not undefined and not false and stack_grocy_restic_enable is not undefined and not false %} +{% if restic_enable|d(False) == True and stack_grocy_restic_enable|d(False) == True %} backup: image: mazzolino/restic hostname: "{{ ansible_hostname | default() }}" diff --git a/roles/paperless/templates/compose.yaml.jinja b/roles/paperless/templates/compose.yaml.jinja index 2bf7681..06dc145 100644 --- a/roles/paperless/templates/compose.yaml.jinja +++ b/roles/paperless/templates/compose.yaml.jinja @@ -65,7 +65,7 @@ services: environment: REDIS_ARGS: "--save 60 10" -{% if restic_enable is not undefined and not false and stack_paperless_restic_enable is not undefined and not false %} +{% if restic_enable|d(False) == True and stack_paperless_restic_enable|d(False) == True %} backup: image: mazzolino/restic hostname: "{{ ansible_hostname | default() }}"