Add success file detection; put stuff in block

This commit is contained in:
Chris Hammer 2025-02-28 15:44:14 -05:00
parent c5a3a86878
commit 9f069eb612

View File

@ -11,43 +11,57 @@
tasks: tasks:
- name: Include the backup role - name: Check for backup success file
ansible.builtin.include_role: ansible.builtin.stat:
name: ../roles/rear_backup path: "{{ standalone_backup_success_file }}"
register: standalone_backup_success
- name: End if backup for Bigboot already exists
ansible.builtin.meta: end_host
when:
- standalone_backup_success['stat']['exists'] | bool
- not rear_force_backup | default(false) | bool
- name: Perform ReaR Backup and write success log
when: when:
- ansible_distribution_major_version >= '7' - ansible_distribution_major_version >= '7'
- not rear_backup_skip | default(false) | bool - not rear_backup_skip | default(false) | bool
- name: Verify ReaR backup log is present
ansible.builtin.stat:
path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
register: rear_backup_log_stat
- name: Backup ReaR log file and create success file
when:
- rear_backup_log_stat['stat']['exists']
block: block:
- name: Copy ReaR log file to backup location - name: Include the backup role
ansible.builtin.copy: ansible.builtin.include_role:
src: "/var/log/rear/rear-{{ ansible_hostname }}.log" name: ../roles/rear_backup
dest: "/var/log/rear-{{ ansible_hostname }}-{{ '%Y-%m-%d' | strftime(rear_backup_log_stat['stat']['mtime']) }}.log"
mode: "0644"
backup: true
remote_src: true
- name: Remove ReaR log file - name: Confirm ReaR backup log is present
ansible.builtin.file: ansible.builtin.stat:
path: "/var/log/rear/rear-{{ ansible_hostname }}.log" path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
state: absent register: rear_backup_log_stat
- name: Create success file directory if not present - name: Backup ReaR log file and create success file
ansible.builtin.file: when:
path: "{{ standalone_backup_success_path }}" - rear_backup_log_stat['stat']['exists']
state: directory block:
mode: "0755" - name: Copy 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(rear_backup_log_stat['stat']['mtime']) }}.log"
mode: "0644"
backup: true
remote_src: true
- name: Create backup success file - name: Remove ReaR log file
ansible.builtin.copy: ansible.builtin.file:
dest: "{{ standalone_backup_success_file }}" path: "/var/log/rear/rear-{{ ansible_hostname }}.log"
content: "success\n" state: absent
mode: "0644"
- name: Create success file directory if not present
ansible.builtin.file:
path: "{{ standalone_backup_success_path }}"
state: directory
mode: "0755"
- name: Create backup success file
ansible.builtin.copy:
dest: "{{ standalone_backup_success_file }}"
content: "success\n"
mode: "0644"