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

This commit is contained in:
2025-09-24 16:08:49 -04:00
parent f7d2a20ef7
commit 7606a0c308
6 changed files with 95 additions and 32 deletions

View File

@ -0,0 +1,39 @@
---
- name: Check previous log file
ansible.builtin.stat:
path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
register: old_rear_log
- name: Backup ReaR log file
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
- name: Remove old ReaR log file
ansible.builtin.file:
path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
state: absent
- 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: Remove Grub2 config
ansible.builtin.file:
path: "/etc/grub.d/45_rear"
state: absent
notify: Rebuild Grub2

View File

@ -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