From 9b8962cc5f6f7a6ac6e845f3dfbba230ba63ad3d Mon Sep 17 00:00:00 2001 From: L3D Date: Mon, 10 Jan 2022 11:32:43 +0100 Subject: [PATCH] in case of systemd timers are used, remove possible installed cronjobs --- tasks/restic_delete_cron.yml | 18 ++++++++++++++++++ tasks/schedule.yml | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 tasks/restic_delete_cron.yml 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"