2019-08-14 16:02:02 +02:00
|
|
|
---
|
2020-11-13 10:01:05 +01:00
|
|
|
- name: reformat dict if necessary
|
|
|
|
set_fact:
|
|
|
|
restic_backups: "{{ restic_backups|dict2items|json_query('[*].value') }}"
|
|
|
|
when:
|
|
|
|
- restic_backups | type_debug == "dict"
|
|
|
|
|
2019-09-11 11:32:07 +02:00
|
|
|
- name: Create backup credentials
|
|
|
|
template:
|
|
|
|
src: restic_access_Linux.j2
|
2021-04-29 14:58:12 +02:00
|
|
|
dest: "{{ restic_script_dir }}/access-{{ item.name | replace(' ', '') }}.sh"
|
2019-09-11 11:32:07 +02:00
|
|
|
mode: '0700'
|
|
|
|
owner: '{{ restic_dir_owner }}'
|
|
|
|
group: '{{ restic_dir_group }}'
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.src is defined or item.stdin is defined
|
|
|
|
- item.src is defined or item.stdin and item.stdin_cmd is defined
|
|
|
|
- item.repo in restic_repos
|
|
|
|
|
2019-08-14 16:02:02 +02:00
|
|
|
- name: Create backup script
|
|
|
|
template:
|
2019-08-14 16:03:03 +02:00
|
|
|
src: restic_script_Linux.j2
|
2021-04-29 14:58:12 +02:00
|
|
|
dest: "{{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"
|
2019-08-14 16:02:02 +02:00
|
|
|
mode: '0700'
|
|
|
|
owner: '{{ restic_dir_owner }}'
|
|
|
|
group: '{{ restic_dir_group }}'
|
2019-08-14 16:59:32 +02:00
|
|
|
no_log: true
|
2019-08-14 16:02:02 +02:00
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- item.name is defined
|
2019-08-15 08:36:57 +02:00
|
|
|
- item.src is defined or item.stdin is defined
|
2019-08-15 10:00:45 +02:00
|
|
|
- item.src is defined or item.stdin and item.stdin_cmd is defined
|
2019-08-14 16:59:32 +02:00
|
|
|
- item.repo in restic_repos
|
2019-08-15 14:47:55 +02:00
|
|
|
|
2021-04-29 14:58:12 +02:00
|
|
|
- name: cleanup CRON jobs
|
2019-08-15 14:47:55 +02:00
|
|
|
cron:
|
|
|
|
name: 'arillso.restic backup {{ item.name }}'
|
|
|
|
job: 'CRON=true {{ restic_script_dir }}/backup-{{ item.name }}.sh'
|
2020-04-06 15:33:07 +02:00
|
|
|
minute: '{{ item.schedule_minute | default("*") }}'
|
|
|
|
hour: '{{ item.schedule_hour | default("*") }}'
|
|
|
|
weekday: '{{ item.schedule_weekday | default("*") }}'
|
|
|
|
month: '{{ item.schedule_month | default("*") }}'
|
2021-04-29 14:58:12 +02:00
|
|
|
state: absent
|
|
|
|
become: true
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- restic_create_cron
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: copy systemd timer
|
|
|
|
become: true
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/restic.timer.j2
|
|
|
|
dest: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.timer"
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- restic_create_cron
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: copy systemd service
|
2019-08-15 14:51:42 +02:00
|
|
|
become: true
|
2021-04-29 14:58:12 +02:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/restic.service.j2
|
|
|
|
dest: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.service"
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
2019-08-15 14:52:43 +02:00
|
|
|
no_log: true
|
2020-11-13 10:01:05 +01:00
|
|
|
with_items: '{{ restic_backups }}'
|
2019-08-15 14:47:55 +02:00
|
|
|
when:
|
|
|
|
- restic_create_cron
|
|
|
|
- item.name is defined
|
2020-06-02 14:09:43 +02:00
|
|
|
- item.scheduled | default(false)
|
2021-04-29 14:58:12 +02:00
|
|
|
|
2021-04-29 15:13:19 +02:00
|
|
|
- name: Enable restic service
|
|
|
|
become: true
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "restic-{{ item.name | replace(' ', '') | string }}.service"
|
|
|
|
enabled: true
|
|
|
|
daemon_reload: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- restic_create_cron
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: Enable and start restic timer
|
2021-04-29 14:58:12 +02:00
|
|
|
become: true
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "restic-{{ item.name | replace(' ', '') | string }}.timer"
|
|
|
|
enabled: true
|
|
|
|
state: started
|
|
|
|
daemon_reload: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- restic_create_cron
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|