Extract restic repo init to shared task file
Deduplicate nearly identical init logic from backend.yml and backend_sftp.yml into init.yml. Also fixes missing set -euo pipefail in the sftp backend variant. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
16da843131
commit
796428cbda
3 changed files with 11 additions and 15 deletions
|
|
@ -8,12 +8,5 @@
|
||||||
mode: "0700"
|
mode: "0700"
|
||||||
when: restic_repo is defined and restic_repo.startswith('/') # only local path
|
when: restic_repo is defined and restic_repo.startswith('/') # only local path
|
||||||
|
|
||||||
- name: Ensure restic repo is initialized
|
- ansible.builtin.include_tasks: init.yml
|
||||||
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
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,5 @@
|
||||||
dest: /root/.ssh/config
|
dest: /root/.ssh/config
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
- name: Initialize restic repo on Storage Box (if needed)
|
- ansible.builtin.include_tasks: init.yml
|
||||||
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
|
|
||||||
|
|
||||||
|
|
|
||||||
9
roles/restic/tasks/init.yml
Normal file
9
roles/restic/tasks/init.yml
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue