From 2ffabd234ac7b9b12c3614f5712119e39739eeda Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 13 Mar 2022 14:36:23 +0100 Subject: [PATCH] Feat: rename templates and add borgmatic_name --- roles/borgmatic/tasks/main.yml | 6 +++--- .../{borgmatic.afterboot.timer.j2 => afterboot.timer.j2} | 2 ++ .../templates/{borgmatic.config.yaml.j2 => config.yaml.j2} | 6 +++--- .../templates/{borgmatic.service.j2 => service.j2} | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) rename roles/borgmatic/templates/{borgmatic.afterboot.timer.j2 => afterboot.timer.j2} (61%) rename roles/borgmatic/templates/{borgmatic.config.yaml.j2 => config.yaml.j2} (97%) rename roles/borgmatic/templates/{borgmatic.service.j2 => service.j2} (90%) diff --git a/roles/borgmatic/tasks/main.yml b/roles/borgmatic/tasks/main.yml index f6db61e..9a436c2 100644 --- a/roles/borgmatic/tasks/main.yml +++ b/roles/borgmatic/tasks/main.yml @@ -30,7 +30,7 @@ - name: Borgmatic config template: - src: borgmatic.config.yaml.j2 + src: config.yaml.j2 dest: "{{ borgmatic_config_file }}" mode: 644 @@ -45,14 +45,14 @@ - name: copy systemd service template: - src: borgmatic.service.j2 + src: service.j2 dest: "/lib/systemd/system/borgmatic_{{ borgmatic_name }}.service" mode: 644 notify: "reload systemd" - name: copy systemd timer for executing borgmatic after boot template: - src: borgmatic.afterboot.timer.j2 + src: afterboot.timer.j2 dest: "/lib/systemd/system/borgmatic_{{ borgmatic_name }}.timer" notify: "reload systemd" diff --git a/roles/borgmatic/templates/borgmatic.afterboot.timer.j2 b/roles/borgmatic/templates/afterboot.timer.j2 similarity index 61% rename from roles/borgmatic/templates/borgmatic.afterboot.timer.j2 rename to roles/borgmatic/templates/afterboot.timer.j2 index dea5f20..4637707 100644 --- a/roles/borgmatic/templates/borgmatic.afterboot.timer.j2 +++ b/roles/borgmatic/templates/afterboot.timer.j2 @@ -1,3 +1,5 @@ +#jinja2: lstrip_blocks: "True", trim_blocks: "True" +{{ ansible_managed | comment }} [Unit] Description=Run borgmatic {{ borgmatic_name }} backup diff --git a/roles/borgmatic/templates/borgmatic.config.yaml.j2 b/roles/borgmatic/templates/config.yaml.j2 similarity index 97% rename from roles/borgmatic/templates/borgmatic.config.yaml.j2 rename to roles/borgmatic/templates/config.yaml.j2 index 5f2b21d..b05f71b 100644 --- a/roles/borgmatic/templates/borgmatic.config.yaml.j2 +++ b/roles/borgmatic/templates/config.yaml.j2 @@ -102,7 +102,7 @@ storage: # also specify a prefix in the retention section to avoid accidental pruning of # archives with a different archive name format. And you should also specify a # prefix in the consistency section as well. - archive_name_format: '{hostname}-{now:%Y-%m-%d-%H%M%S}' + archive_name_format: '{hostname}-{{ borgmatic_name }}-{now:%Y-%m-%d-%H%M%S}' # Bypass Borg error about a repository that has been moved. relocated_repo_access_is_ok: {{ borgmatic_relocated_repo_access_is_ok }} @@ -149,7 +149,7 @@ retention: # When pruning, only consider archive names starting with this prefix. # Borg placeholders can be used. See the output of "borg help placeholders" for # details. Default is "{hostname}-". - prefix: '{hostname}-' + prefix: '{hostname}-{{ borgmatic_name }}' # Consistency checks to run after backups. See # https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and @@ -174,7 +174,7 @@ consistency: # When performing the "archives" check, only consider archive names starting with # this prefix. Borg placeholders can be used. See the output of # "borg help placeholders" for details. Default is "{hostname}-". - prefix: '{hostname}-' + prefix: '{hostname}-{{ borgmatic_name }}' # Shell commands or scripts to execute before and after a backup or if an error has occurred. # IMPORTANT: All provided commands and scripts are executed with user permissions of borgmatic. diff --git a/roles/borgmatic/templates/borgmatic.service.j2 b/roles/borgmatic/templates/service.j2 similarity index 90% rename from roles/borgmatic/templates/borgmatic.service.j2 rename to roles/borgmatic/templates/service.j2 index 9e67d74..8b3b3b1 100644 --- a/roles/borgmatic/templates/borgmatic.service.j2 +++ b/roles/borgmatic/templates/service.j2 @@ -1,3 +1,4 @@ +#jinja2: lstrip_blocks: "True", trim_blocks: "True" {{ ansible_managed | comment }} [Unit]