Add remove playbook/role

This commit is contained in:
Chris Hammer 2025-02-27 16:30:50 -05:00
parent f314e943f5
commit 54d44730fe
4 changed files with 68 additions and 0 deletions

10
playbooks/rear_remove.yml Normal file
View File

@ -0,0 +1,10 @@
---
- name: ReaR Remove Playbook
hosts: all
gather_facts: true
become: false
tasks:
- name: Run cleanup directly
ansible.builtin.include_role:
name: ../roles/rear_remove

View File

@ -0,0 +1,3 @@
---
- name: Rebuild Grub2
ansible.builtin.include_tasks: handlers/rebuild_grub.yml

View File

@ -0,0 +1,17 @@
---
- name: UEFI Check
ansible.builtin.stat:
path: /boot/efi/EFI/redhat/grub.cfg
register: is_efi
- name: Rebuild Grub config - BIOS
ansible.builtin.command:
cmd: "grub2-mkconfig -o /boot/grub2/grub.cfg"
when:
- not is_efi['stat']['exists'] | bool
- name: Rebuild Grub config - UEFI
ansible.builtin.command:
cmd: "grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg"
when:
- is_efi['stat']['exists'] | bool

View File

@ -0,0 +1,38 @@
---
- 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"
notify: Rebuild Grub2