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:
3
.ci.env
Normal file
3
.ci.env
Normal 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"
|
29
.gitea/workflows/ansible-lint.yml
Normal file
29
.gitea/workflows/ansible-lint.yml
Normal 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
1
.gitignore
vendored
@ -2,3 +2,4 @@ deprecated
|
||||
collections/ansible_collections
|
||||
roles/verified_reboot
|
||||
roles/requirements.yml
|
||||
inventory
|
||||
|
@ -1,3 +1,4 @@
|
||||
[defaults]
|
||||
inventory = inventory/hosts
|
||||
collections_path = collections
|
||||
roles_path = roles
|
||||
|
39
roles/rear_remove/tasks/cleanup.yml
Normal file
39
roles/rear_remove/tasks/cleanup.yml
Normal 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
|
@ -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