ansible/roles/restic/tasks/repo.yaml

66 lines
1.7 KiB
YAML
Raw Normal View History

2019-12-15 06:40:49 +00:00
---
- name: get repo status
shell:
2019-12-16 02:51:51 +00:00
cmd: restic -q -r {{ item.repo }} --no-lock snapshots 2> /dev/null
2019-12-15 06:40:49 +00:00
ignore_errors: yes
environment: "{{ item.environment | default({}) }}"
register: restic_init
changed_when: false
2019-12-15 06:40:49 +00:00
- name: init repos
shell:
cmd: restic -q -r {{ item.repo }} init
environment: "{{ item.environment | default({}) }}"
when: restic_init.rc != 0
- name: create repo config directory
file:
path: "{{ restic_etc_path }}/repos/{{ item.name }}"
owner: root
group: root
mode: 0755
state: directory
- name: create repo env directory
file:
path: "{{ restic_etc_path }}/repos/{{ item.name }}"
owner: root
group: root
mode: 0755
state: directory
- name: create repo environment helper
template:
2019-12-16 02:51:51 +00:00
src: repo-env.sh.j2
2019-12-15 06:40:49 +00:00
dest: "{{ restic_etc_path }}/repos/{{ item.name }}/env.sh"
owner: root
group: root
mode: 0400
2019-12-16 02:51:51 +00:00
2019-12-19 04:09:05 +00:00
- name: symlink default repo
block:
- name: explicit default
file:
src: "{{ restic_etc_path }}/repos/{{ item.name }}"
dest: "{{ restic_etc_path }}/repos/default"
state: link
force: yes
when: item.default is defined and item.default == True
- name: implicit default
file:
src: "{{ restic_etc_path }}/repos/{{ item.name }}"
dest: "{{ restic_etc_path }}/repos/default"
state: link
force: yes
when: restic_repos | count == 1
2019-12-16 02:51:51 +00:00
- name: create cron
cron:
name: "restic {{ item.name }} tidy"
hour: "0"
minute: "{{ 60 | random(seed=inventory_hostname) }}"
user: root
state: present
2019-12-23 17:30:21 +00:00
job: "( {{ restic_bin_path }}/restic-tidy {{ item.name }} | logger --id=$$ -t restic-tidy -p user.info ) 2>&1 | logger --id=$$ -t restic-tidy -p user.err"
when: restic_tidy_enabled