Compare commits
4 Commits
main
...
validate_b
Author | SHA1 | Date | |
---|---|---|---|
7000622d46 | |||
ae9f0cfd8a | |||
32ef96ad03 | |||
9a06928cdb |
@ -3,6 +3,7 @@ run-name: ${{ gitea.actor }} is running Ansible Code Pipeline
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- validate_backup
|
||||
- main
|
||||
|
||||
jobs:
|
||||
|
15
playbooks/rear_backup_validation.yml
Normal file
15
playbooks/rear_backup_validation.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Perform ReaR Backup Validation
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: true
|
||||
strategy: free
|
||||
|
||||
tasks:
|
||||
- name: Import rear_vars role
|
||||
ansible.builtin.import_role:
|
||||
name: rhc.rear.rear_vars
|
||||
|
||||
- name: Validiate ReaR Backup Completion
|
||||
ansible.builtin.include_role:
|
||||
name: rhc.rear.rear_backup_validation
|
@ -16,6 +16,6 @@ collections:
|
||||
- name: rhc.rear
|
||||
source: https://gitea.thezengarden.net/ansible_collections/ansible-collection-rear.git
|
||||
type: git
|
||||
version: main
|
||||
version: validate_backup
|
||||
|
||||
...
|
||||
|
40
roles/rear_backup_validation/tasks/main.yml
Normal file
40
roles/rear_backup_validation/tasks/main.yml
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
- name: Check if ReaR backup log exists
|
||||
ansible.builtin.stat:
|
||||
path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
|
||||
register: rear_backup_log_presence
|
||||
|
||||
- name: Validate backup completion and other stuff
|
||||
when:
|
||||
- rear_backup_log_presence['stat']['exists'] | bool
|
||||
block:
|
||||
- name: Validate ReaR backup completion
|
||||
ansible.builtin.command:
|
||||
cmd: "grep 'Finished running mkbackup workflow' /var/log/rear/rear-{{ ansible_hostname }}.log"
|
||||
register: rear_backup_validate
|
||||
failed_when: rear_backup_validate['rc'] not in [0]
|
||||
|
||||
- name: Debug rear_backup_validate
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ rear_backup_validate }}"
|
||||
|
||||
- name: Set current time and capture ReaR backup timestamp
|
||||
ansible.builtin.set_fact:
|
||||
rear_backup_date_now: "{{ ansible_date_time['date'] }}"
|
||||
# rear_backup_timestamp: "{{ rear_backup_validate['stdout'] | split(' ') | first }}"
|
||||
rear_backup_timestamp: '2025-09-24'
|
||||
|
||||
- name: Capture number of days since last backup
|
||||
ansible.builtin.set_fact:
|
||||
rear_backup_age: "{{ ((rear_backup_date_now | to_datetime('%Y-%m-%d')) - (rear_backup_timestamp | to_datetime('%Y-%m-%d'))).days }}"
|
||||
|
||||
- name: Debug rear_backup_age
|
||||
ansible.builtin.debug:
|
||||
msg: "Number of days since last backup success: {{ rear_backup_age }}."
|
||||
|
||||
- name: Fail if backup older than desired
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- rear_backup_age | int <= 6
|
||||
success_msg: "Backup is new enough."
|
||||
fail_msg: "Backup is too old like your stinky grandma!"
|
Reference in New Issue
Block a user