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

3
.ci.env Normal file
View File

@ -0,0 +1,3 @@
export ANSIBLE_LINT_EXCLUSION="--exclude collections/ansible_collections --exclude .gitea"
export ANSIBLE_INVENTORY="-i 127.0.0.1, --connection=local"
export ANSIBLE_PLAYBOOK="playbooks/gather_ipv4.yml"

View File

@ -0,0 +1,29 @@
name: Ansible Lint Pipeline
run-name: ${{ gitea.actor }} is running Ansible Code Pipeline
on:
push:
branches:
- main
jobs:
Ansible-Development-Pipeline:
strategy:
matrix:
os: [ ansible-dev-centos ]
runs-on: ${{ matrix.os }}
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Ansible Environment Verify
run: |
. ./.ci.env
env
git log -1
ansible --version
ansible-lint --version
- name: Run Ansible-Lint
run: |
. ./.ci.env
ansible-lint --offline $ANSIBLE_LINT_EXCLUSION

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ deprecated
collections/ansible_collections collections/ansible_collections
roles/verified_reboot roles/verified_reboot
roles/requirements.yml roles/requirements.yml
inventory

View File

@ -1,3 +1,4 @@
[defaults] [defaults]
inventory = inventory/hosts
collections_path = collections collections_path = collections
roles_path = roles roles_path = roles

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: ansible.builtin.stat:
path: "/var/log/rear/rear-{{ ansible_hostname }}.log" path: "/var/lib/rear"
register: old_rear_log 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: when:
- old_rear_log['stat']['exists'] - file_details['stat']['exists'] | bool
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 - name: Compare Dates to delete based on our 2 days retention policy
ansible.builtin.file: ansible.builtin.set_fact:
path: "/var/log/rear/rear-{{ ansible_hostname }}.log" file_status: "{{ ((date_now | to_datetime('%Y-%m-%d')) - (file_date | to_datetime('%Y=%m-%d'))).days }}"
state: absent when:
- file_details['stat']['exists'] | bool
- name: Remove files # - name: Include Cleanup if the ReaR file is created 6 days back
ansible.builtin.file: # ansible.builtin.include_tasks: cleanup.yml
path: "{{ item }}" # when:
state: absent # - not (file_status|int <= 6)
loop:
- "/boot/rear-initrd.cgz"
- "/boot/rear-kernel"
- "/etc/rear"
- "/tmp/rear"
- "/var/lib/rear"
- name: Remove Grub2 config - name: Print Msg if ReaR file doesnt exist
ansible.builtin.file: ansible.builtin.debug:
path: "/etc/grub.d/45_rear" msg: "The ReaR files don't exist on this server."
state: absent when:
notify: Rebuild Grub2 - not file_details['stat']['exists'] | bool