--- - name: Check ReaR Output details ansible.builtin.stat: path: /boot/rear-initrd.cgz register: file_details - name: Check dates and cleanup ReaR backup as needed when: - file_details['stat']['exists'] | bool block: - name: Set current Date and ReaR file date ansible.builtin.set_fact: date_now: "{{ ansible_date_time['date'] }}" file_date: "{{ '%Y-%m-%d' | strftime(file_details['stat']['mtime']) }}" when: - file_details['stat']['exists'] | bool - name: Compare Dates to delete based on our 2 days retention policy ansible.builtin.set_fact: file_status: "{{ ((date_now | to_datetime('%Y-%m-%d')) - (file_date | to_datetime('%Y-%m-%d'))).days }}" when: - file_details['stat']['exists'] | bool - name: Include Cleanup if the ReaR file is created 6 days back ansible.builtin.include_tasks: cleanup.yml when: - not (file_status|int <= 6) - name: Print Msg if ReaR file doesnt exist ansible.builtin.debug: msg: "The ReaR files don't exist on this server." when: - not file_details['stat']['exists'] | bool