From ba17cc66576292cf98aa533a6b31997164b7d54d Mon Sep 17 00:00:00 2001 From: Jeremy Hettenhouser Date: Tue, 21 Mar 2023 20:18:23 -0400 Subject: [PATCH] Update delete_legacy_cron_entry.yml Fixed (SCHEDULE) (OLD) check tainting the play recap as well as the assumption that cron_delete.failed will be defined. Signed-off-by: Jeremy Hettenhouser --- tasks/delete_legacy_cron_entry.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tasks/delete_legacy_cron_entry.yml b/tasks/delete_legacy_cron_entry.yml index e684cdb..acbf5be 100644 --- a/tasks/delete_legacy_cron_entry.yml +++ b/tasks/delete_legacy_cron_entry.yml @@ -6,6 +6,10 @@ fail_msg: "[ERROR] Youre ansible version is above 2.12.0" success_msg: "Congratulations. You are using ansible version {{ ansible_version.full }}" delegate_to: localhost + when: + - ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob" + register: old_af + failed_when: false ignore_errors: true - name: (SCHEDULE) (OLD) try to remove entries from /etc/crontab @@ -18,32 +22,32 @@ weekday: '{{ item.schedule_weekday | default("*") }}' month: '{{ item.schedule_month | default("*") }}' state: absent - cron_file: '/etc/crontab' - user: 'root' + cron_file: "/etc/crontab" + user: "root" no_log: "{{ restic_no_log }}" - with_items: '{{ restic_backups }}' + with_items: "{{ restic_backups }}" when: - 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" + - old_af.success_msg is defined register: cron_delete failed_when: false - name: "(SCHEDULE) (OLD) make sure do1jlr.restic backup script is not in /etc/crontab" become: true ansible.builtin.lineinfile: - path: '/etc/crontab' + path: "/etc/crontab" state: absent search_string: "do1jlr.restic backup {{ item.name }}" - when: cron_delete.failed - with_items: '{{ restic_backups }}' + when: cron_delete.failed is defined and cron_delete.failed + with_items: "{{ restic_backups }}" - name: "(SCHEDULE) (OLD) make sure restic script is not in /etc/crontab" become: true ansible.builtin.lineinfile: - path: '/etc/crontab' + path: "/etc/crontab" state: absent search_string: "{{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" - when: cron_delete.failed - with_items: '{{ restic_backups }}' + when: cron_delete.failed is defined and cron_delete.failed + with_items: "{{ restic_backups }}"