--- - name: Check if ReaR restore was already completed ansible.builtin.find: paths: - /var/tmp patterns: - "rear_restore.{{ rear_backup_workflow }}*" register: rear_restore_file - name: Check for ReaR restore when: - rear_restore_file['files'] | length > 0 block: - name: Check for ReaR restore ansible.builtin.debug: msg: "ReaR restore was already completed - {{ rear_restore_file['files'] | json_query('[].path') | string }}" - name: End host for servers that already completed a ReaR restore ansible.builtin.meta: end_host - name: Check if /etc/rear backup exists ansible.builtin.stat: path: "/root/etc-rear-backup-{{ rear_backup_workflow }}.tar.gz" register: rear_config_backup_stat - name: Restore the server when: - rear_config_backup_stat['stat']['exists'] | bool block: - name: Create tmpdir ansible.builtin.file: path: "{{ rear_restore_tmpdir }}" state: directory mode: "0755" - name: Extract /etc/rear archive contents ansible.builtin.unarchive: remote_src: true src: "/root/etc-rear-backup-{{ rear_backup_workflow }}.tar.gz" dest: "{{ rear_restore_tmpdir }}" - name: Copy local.cfg from backup into /etc/rear ansible.builtin.copy: src: "{{ rear_restore_tmpdir }}/rear/local.conf" dest: /etc/rear/local.conf remote_src: true mode: "0600" - name: Rebuild ReaR initrd ansible.builtin.command: cmd: rear -d -v mkrescue register: rear_initrd_cmd - name: Update menu item for ReaR in Grub config ansible.builtin.include_role: name: rhc.rear.rear_grub_cfg - name: Flush handlers to update grub.cfg ansible.builtin.meta: flush_handlers - name: Restore the server using ReaR backup ansible.builtin.command: "grub2-reboot 'Relax-and-Recover {{ rear_vars_grub_label }}'" - name: Reboot host to restore server ansible.builtin.import_role: name: verified_reboot - name: Cleanup leftover artifacts ansible.builtin.file: path: "{{ item }}" state: absent loop: - "{{ rear_restore_tmpdir }}" - "{{ rear_restore_file['files'] | json_query('[].path') }}" - "{{ rear_backup_success_file_path }}/{{ rear_backup_workflow }}_rear_success" - name: Create file for ReaR restore success ansible.builtin.file: path: "/var/tmp/rear_restore.{{ rear_backup_workflow }}.{{ ansible_date_time.iso8601_basic }}" state: touch mode: "0664" - name: Show ReaR restore results ansible.builtin.debug: msg: "ReaR restore has successfully completed."