ansible/roles/restic/tasks/job.yaml

59 lines
1.7 KiB
YAML
Raw Normal View History

2019-12-15 06:40:49 +00:00
---
- name: create job config directory
file:
path: "{{ restic_etc_path }}/jobs/{{ item.name }}"
owner: root
group: root
mode: 0755
state: directory
2019-12-23 17:30:07 +00:00
- name: create job environment helper
2019-12-16 02:51:51 +00:00
template:
src: job-env.sh.j2
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/env.sh"
owner: root
group: root
mode: 0400
2019-12-25 23:23:36 +00:00
- name: create hooks directory
2019-12-23 17:30:07 +00:00
file:
path: "{{ restic_etc_path }}/jobs/{{ item.name }}/hooks.d"
owner: root
group: root
mode: 0755
state: directory
when: item.hooks is defined and item.hooks | length
2019-12-25 23:23:36 +00:00
- name: create job hooks
copy:
src: "hooks/{{ hook_item }}"
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/hooks.d/{{ '%02d' | format(idx) }}-{{ hook_item | basename | splitext | first }}"
owner: root
group: root
mode: 0755
loop: "{{ item.hooks | default([]) }}"
loop_control:
loop_var: hook_item
index_var: idx
when: item.hooks is defined
2019-12-15 06:40:49 +00:00
- name: create job exclude file
template:
src: exclude.txt.j2
dest: "{{ restic_etc_path }}/jobs/{{ item.name }}/exclude.txt"
owner: root
group: root
mode: 0644
- name: create cron
cron:
name: "restic {{ item.name }} job"
hour: "{{ item.cron.hour | default(omit) }}"
2019-12-16 02:51:51 +00:00
minute: "{{ item.cron.minute | default(60 | random(seed=inventory_hostname)) }}"
2019-12-15 06:40:49 +00:00
day: "{{ item.cron.day | default(omit) }}"
month: "{{ item.cron.month | default(omit) }}"
weekday: "{{ item.cron.weekday | default(omit) }}"
user: "{{ item.cron.user | default('root') }}"
state: "{{ item.cron.state | default('present') }}"
2019-12-23 17:30:21 +00:00
job: "( {{ restic_bin_path }}/restic-job {{ item.name }} | logger --id=$$ -t restic-job -p user.info ) 2>&1 | logger --id=$$ -t restic-job -p user.err"