From 9f069eb6129c62d8f100d91f3918db14a52b1309 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Fri, 28 Feb 2025 15:44:14 -0500 Subject: [PATCH] Add success file detection; put stuff in block --- playbooks/rear_backup.yml | 78 +++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/playbooks/rear_backup.yml b/playbooks/rear_backup.yml index 35cbede..ad45c6a 100644 --- a/playbooks/rear_backup.yml +++ b/playbooks/rear_backup.yml @@ -11,43 +11,57 @@ tasks: - - name: Include the backup role - ansible.builtin.include_role: - name: ../roles/rear_backup + - name: Check for backup success file + ansible.builtin.stat: + 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: - ansible_distribution_major_version >= '7' - 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: - - 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: Include the backup role + ansible.builtin.include_role: + name: ../roles/rear_backup - - name: Remove ReaR log file - ansible.builtin.file: + - name: Confirm ReaR backup log is present + ansible.builtin.stat: path: "/var/log/rear/rear-{{ ansible_hostname }}.log" - state: absent + register: rear_backup_log_stat - - name: Create success file directory if not present - ansible.builtin.file: - path: "{{ standalone_backup_success_path }}" - state: directory - mode: "0755" + - name: Backup ReaR log file and create success file + when: + - rear_backup_log_stat['stat']['exists'] + block: + - 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 - ansible.builtin.copy: - dest: "{{ standalone_backup_success_file }}" - content: "success\n" - mode: "0644" + - name: Remove ReaR log file + ansible.builtin.file: + path: "/var/log/rear/rear-{{ ansible_hostname }}.log" + state: absent + + - 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"