diff --git a/roles/restic/tasks/backend.yml b/roles/restic/tasks/backend.yml index d392f9f..187aa2b 100644 --- a/roles/restic/tasks/backend.yml +++ b/roles/restic/tasks/backend.yml @@ -8,12 +8,5 @@ mode: "0700" when: restic_repo is defined and restic_repo.startswith('/') # only local path -- name: Ensure restic repo is initialized - ansible.builtin.shell: | - set -euo pipefail - source /etc/restic/restic.env - restic snapshots > /dev/null 2>&1 || restic init - touch /etc/restic/.initialized - args: - creates: /etc/restic/.initialized +- ansible.builtin.include_tasks: init.yml diff --git a/roles/restic/tasks/backend_sftp.yml b/roles/restic/tasks/backend_sftp.yml index 2795f1d..7f38c48 100644 --- a/roles/restic/tasks/backend_sftp.yml +++ b/roles/restic/tasks/backend_sftp.yml @@ -20,11 +20,5 @@ dest: /root/.ssh/config mode: "0644" -- name: Initialize restic repo on Storage Box (if needed) - ansible.builtin.shell: | - source /etc/restic/restic.env - restic snapshots > /dev/null 2>&1 || restic init - touch /etc/restic/.initialized - args: - creates: /etc/restic/.initialized +- ansible.builtin.include_tasks: init.yml diff --git a/roles/restic/tasks/init.yml b/roles/restic/tasks/init.yml new file mode 100644 index 0000000..83f65b0 --- /dev/null +++ b/roles/restic/tasks/init.yml @@ -0,0 +1,9 @@ +--- +- name: Initialize restic repo (if needed) + ansible.builtin.shell: | + set -euo pipefail + source /etc/restic/restic.env + restic snapshots > /dev/null 2>&1 || restic init + touch /etc/restic/.initialized + args: + creates: /etc/restic/.initialized