2021-04-29 16:16:35 +02:00
|
|
|
---
|
|
|
|
- name: create systemd timer
|
|
|
|
block:
|
|
|
|
- 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 }}'
|
2021-07-07 11:20:37 +02:00
|
|
|
notify: systemctl restart restic.timer
|
2021-04-29 16:16:35 +02:00
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: copy systemd service
|
|
|
|
become: true
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/restic.service.j2
|
|
|
|
dest: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.service"
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: copy systemd service
|
|
|
|
become: true
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/restic.service.j2
|
|
|
|
dest: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.service"
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: Enable restic service
|
|
|
|
become: true
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "restic-{{ item.name | replace(' ', '') | string }}.service"
|
|
|
|
enabled: true
|
|
|
|
daemon_reload: true
|
2021-08-02 14:13:30 +02:00
|
|
|
masked: false
|
2021-04-29 16:16:35 +02:00
|
|
|
with_items: '{{ restic_backups }}'
|
2021-07-07 11:20:37 +02:00
|
|
|
notify: systemctl restart restic.timer
|
2021-04-29 16:16:35 +02:00
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
|
|
|
|
- name: Enable and start restic timer
|
|
|
|
become: true
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "restic-{{ item.name | replace(' ', '') | string }}.timer"
|
|
|
|
enabled: true
|
|
|
|
state: started
|
|
|
|
daemon_reload: true
|
2021-08-02 14:13:30 +02:00
|
|
|
masked: false
|
2021-04-29 16:16:35 +02:00
|
|
|
with_items: '{{ restic_backups }}'
|
2021-07-07 11:20:37 +02:00
|
|
|
notify: systemctl restart restic.timer
|
2021-04-29 16:16:35 +02:00
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
2021-07-05 16:18:46 +02:00
|
|
|
|
|
|
|
- name: delete old cronjob entry if available
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: "do1jlr.restic backup {{ item.name }}"
|
|
|
|
job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"
|
|
|
|
minute: '{{ item.schedule_minute | default("*") }}'
|
|
|
|
hour: '{{ item.schedule_hour | default("2") }}'
|
|
|
|
weekday: '{{ item.schedule_weekday | default("*") }}'
|
|
|
|
month: '{{ item.schedule_month | default("*") }}'
|
|
|
|
state: absent
|
|
|
|
cron_file: '/etc/crontab'
|
|
|
|
user: 'root'
|
|
|
|
become: true
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
2021-08-02 01:09:02 +02:00
|
|
|
when:
|
|
|
|
- ansible_service_mgr == 'systemd'
|
|
|
|
- restic_schedule_type == "systemd"
|
|
|
|
- restic_create_schedule | bool
|
2021-04-29 16:16:35 +02:00
|
|
|
rescue:
|
2021-07-05 16:18:46 +02:00
|
|
|
- name: set cronjob intead of systemd
|
2021-04-29 16:16:35 +02:00
|
|
|
set_fact:
|
|
|
|
restic_force_cron: true
|
|
|
|
|
|
|
|
- name: install cronjob instead of systemd
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: "do1jlr.restic backup {{ item.name }}"
|
|
|
|
job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"
|
|
|
|
minute: '{{ item.schedule_minute | default("*") }}'
|
2021-07-05 16:18:46 +02:00
|
|
|
hour: '{{ item.schedule_hour | default("2") }}'
|
2021-04-29 16:16:35 +02:00
|
|
|
weekday: '{{ item.schedule_weekday | default("*") }}'
|
|
|
|
month: '{{ item.schedule_month | default("*") }}'
|
|
|
|
state: present
|
|
|
|
cron_file: '/etc/crontab'
|
|
|
|
user: 'root'
|
|
|
|
become: true
|
|
|
|
no_log: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
2021-08-02 14:13:30 +02:00
|
|
|
- restic_create_schedule | bool
|
2021-08-02 01:09:02 +02:00
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
2021-08-02 14:13:30 +02:00
|
|
|
- ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob"
|
2021-08-02 01:09:02 +02:00
|
|
|
|
|
|
|
- name: make sure no unwanted systemd timer is available
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "restic-{{ item.name | replace(' ', '') | string }}.timer"
|
2021-08-02 14:13:30 +02:00
|
|
|
state: 'stopped'
|
2021-08-02 01:09:02 +02:00
|
|
|
enabled: false
|
2021-08-02 14:13:30 +02:00
|
|
|
masked: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
2021-08-02 01:09:02 +02:00
|
|
|
when:
|
2021-08-02 14:13:30 +02:00
|
|
|
- restic_create_schedule | bool
|
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
|
|
|
- ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob"
|
|
|
|
|
|
|
|
- name: mask systemd service
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "restic-{{ item.name | replace(' ', '') | string }}.service"
|
|
|
|
state: 'stopped'
|
|
|
|
enabled: false
|
|
|
|
masked: true
|
|
|
|
with_items: '{{ restic_backups }}'
|
|
|
|
when:
|
|
|
|
- restic_create_schedule | bool
|
2021-04-29 16:16:35 +02:00
|
|
|
- item.name is defined
|
|
|
|
- item.scheduled | default(false)
|
2021-08-02 14:13:30 +02:00
|
|
|
- ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob"
|