From c28a195f49817c13ea2cd56e8c70650d39378765 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 8 Oct 2024 00:54:09 +0200 Subject: [PATCH] Add autorestic.all file and move two services --- playbooks/filter_plugins/service_filters.py | 3 +- roles/backup/tasks/main.yml | 8 +++++ roles/backup/vars/main.yml | 38 ++++++++++++++------- services.auto.tfvars | 4 +-- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/playbooks/filter_plugins/service_filters.py b/playbooks/filter_plugins/service_filters.py index 8c356c0..5f22977 100644 --- a/playbooks/filter_plugins/service_filters.py +++ b/playbooks/filter_plugins/service_filters.py @@ -8,7 +8,8 @@ class FilterModule(object): def my_service_attributes(self, services, host, attribute="name"): result = [] for service in services: - if service["host"] != host: + # only compare the host if it is set + if host and service["host"] != host: continue attribute_value = service.get(attribute) diff --git a/roles/backup/tasks/main.yml b/roles/backup/tasks/main.yml index 2cff5a3..ea7880d 100644 --- a/roles/backup/tasks/main.yml +++ b/roles/backup/tasks/main.yml @@ -21,6 +21,14 @@ dest: "{{ (service_path, '.autorestic.yml') | path_join }}" mode: "0644" + - name: Template autorestic.all.yml + ansible.builtin.template: + src: yml.j2 + dest: "{{ (service_path, '.autorestic.all.yml') | path_join }}" + mode: "0644" + vars: + yml: "{{ backup_yml_all }}" + - name: Import tasks specific to the hooks scripts ansible.builtin.import_tasks: hooks.yml - name: Import tasks specific to systemd diff --git a/roles/backup/vars/main.yml b/roles/backup/vars/main.yml index 4291e3c..f15dfb4 100644 --- a/roles/backup/vars/main.yml +++ b/roles/backup/vars/main.yml @@ -4,6 +4,7 @@ backup_svc: name: backup backup_list: "{{ all_services | my_service_attributes(inventory_hostname, 'backup') }}" +backup_list_all: "{{ all_services | my_service_attributes('', 'backup') }}" backup_msg_start: "Backup started" backup_msg_fail: "Backup failed" @@ -28,6 +29,20 @@ backup_default_hooks: - '{{ backup_hc_curl_base }} --data "{{ backup_msg_fail_location }}${AUTORESTIC_LOCATION}" {{ backup_hc_url }}/fail' - '{{ backup_gatus_curl_base }} "{{ backup_gatus_url }}?success=false&error={{ backup_msg_fail_location | urlencode }}${AUTORESTIC_LOCATION}' +backup_global: + all: + cache-dir: "{{ (service_path, 'cache') | path_join }}" + retry-lock: 5m + forget: + keep-last: 7 + keep-daily: 14 + keep-weekly: 16 + keep-monthly: 12 + keep-yearly: 2 + host: "{{ ansible_facts.hostname }}" + backup: + host: "{{ ansible_facts.hostname }}" + backup_yml: version: 2 @@ -35,16 +50,13 @@ backup_yml: locations: "{{ backup_list | map_backup_locations(vault_backup.backends, backup_default_hooks ) }}" - global: - all: - cache-dir: "{{ (service_path, 'cache') | path_join }}" - retry-lock: 5m - forget: - keep-last: 7 - keep-daily: 14 - keep-weekly: 16 - keep-monthly: 12 - keep-yearly: 2 - host: "{{ ansible_facts.hostname }}" - backup: - host: "{{ ansible_facts.hostname }}" + global: "{{ backup_global }}" + +backup_yml_all: + version: 2 + + backends: "{{ vault_backup.backends }}" + + locations: "{{ backup_list_all | map_backup_locations(vault_backup.backends, backup_default_hooks ) }}" + + global: "{{ backup_global }}" diff --git a/services.auto.tfvars b/services.auto.tfvars index 1df2338..536cab6 100644 --- a/services.auto.tfvars +++ b/services.auto.tfvars @@ -123,7 +123,7 @@ services = { "homebox" = { name = "homebox" - host = "node002" + host = "node003" dns = [{ domain = "serguzim.me" target = "inventory" @@ -285,7 +285,7 @@ services = { "ntfy" = { name = "ntfy" - host = "node002" + host = "node003" dns = [{ domain = "serguzim.me" target = "push"