Add cleanup check; task migration; Add ansible-lint action
Some checks failed
Ansible Lint Pipeline / Ansible-Development-Pipeline (ansible-dev-centos) (push) Failing after 11s
Some checks failed
Ansible Lint Pipeline / Ansible-Development-Pipeline (ansible-dev-centos) (push) Failing after 11s
This commit is contained in:
@ -1,39 +1,29 @@
|
||||
---
|
||||
- name: Check previous log file
|
||||
- name: Check ReaR Output details
|
||||
ansible.builtin.stat:
|
||||
path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
|
||||
register: old_rear_log
|
||||
path: "/var/lib/rear"
|
||||
register: file_details
|
||||
|
||||
- name: Backup ReaR log file
|
||||
- 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:
|
||||
- old_rear_log['stat']['exists']
|
||||
block:
|
||||
- name: Copy old ReaR log file to backup location
|
||||
ansible.builtin.copy:
|
||||
src: "/var/log/rear/rear-{{ ansible_hostname }}.log"
|
||||
dest: "/var/log/rear-{{ ansible_hostname }}-{{ '%Y-%m-%d' | strftime(old_rear_log['stat']['mtime']) }}.log"
|
||||
mode: "0644"
|
||||
backup: true
|
||||
remote_src: true
|
||||
- file_details['stat']['exists'] | bool
|
||||
|
||||
- name: Remove old ReaR log file
|
||||
ansible.builtin.file:
|
||||
path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
|
||||
state: absent
|
||||
- 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: Remove files
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- "/boot/rear-initrd.cgz"
|
||||
- "/boot/rear-kernel"
|
||||
- "/etc/rear"
|
||||
- "/tmp/rear"
|
||||
- "/var/lib/rear"
|
||||
# - 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: Remove Grub2 config
|
||||
ansible.builtin.file:
|
||||
path: "/etc/grub.d/45_rear"
|
||||
state: absent
|
||||
notify: Rebuild Grub2
|
||||
- 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
|
||||
|
Reference in New Issue
Block a user