diff --git a/tasks/restic_delete_cron.yml b/tasks/restic_delete_cron.yml new file mode 100644 index 0000000..8378171 --- /dev/null +++ b/tasks/restic_delete_cron.yml @@ -0,0 +1,18 @@ +--- +- name: remove restic backup cronjob + 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: present + user: 'root' + cron_file: restic_backup + become: true + no_log: "{{ restic_no_log }}" + with_items: '{{ restic_backups }}' + when: + - item.name is defined + - item.scheduled | default(false) diff --git a/tasks/schedule.yml b/tasks/schedule.yml index 244aa69..3b4eda3 100644 --- a/tasks/schedule.yml +++ b/tasks/schedule.yml @@ -22,3 +22,11 @@ when: - restic_create_schedule | bool - ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob" + +- name: remove restic cronjobs + ansible.builtin.include_tasks: restic_delete_cron.yml + when: + - restic_create_schedule | bool + - ansible_service_mgr == 'systemd' + - not restic_force_cron | default(false) + - restic_schedule_type != "cronjob"