From 8c4ce22fe047b95c1b5230f6869b4829912e14c1 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 5 Mar 2025 13:52:08 -0500 Subject: [PATCH] Restore mock up; cleanup --- playbooks/hi.yml | 12 ------- playbooks/rear_restore.yml | 53 +++++++++++++++++++--------- roles/rear_vars/defaults/main.yml | 5 ++- roles/say_hi/README.md | 38 --------------------- roles/say_hi/meta/main.yml | 57 ------------------------------- roles/say_hi/tasks/main.yml | 30 ---------------- roles/say_hi/vars/main.yml | 2 -- 7 files changed, 41 insertions(+), 156 deletions(-) delete mode 100644 playbooks/hi.yml delete mode 100644 roles/say_hi/README.md delete mode 100644 roles/say_hi/meta/main.yml delete mode 100644 roles/say_hi/tasks/main.yml delete mode 100644 roles/say_hi/vars/main.yml diff --git a/playbooks/hi.yml b/playbooks/hi.yml deleted file mode 100644 index 7ff6620..0000000 --- a/playbooks/hi.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Say hi playbook - hosts: all - become: true - gather_facts: true - strategy: free - - - tasks: - - name: Import say-hi playbook - ansible.builtin.include_role: - name: ../roles/say_hi diff --git a/playbooks/rear_restore.yml b/playbooks/rear_restore.yml index c93d083..5563dc4 100644 --- a/playbooks/rear_restore.yml +++ b/playbooks/rear_restore.yml @@ -4,19 +4,30 @@ gather_facts: true become: false - vars: - rear_backup_workflow: standalone - - # We need to extract the contents of the archive, and then restore /etc/rear/local.conf - # after that THEN run mkrescue + rear_restore - - # For /etc/rear/local.conf - first stat and see if exists; if exists use it - # else restore from archive - - # How would this work if we restore from a differnt workflow? - # Won't we need to regenerate the local.cfg? - # Could we save the archive to etc-rear-{{ workflow }}.tar.gz and restore from that? tasks: + - name: Import rear_vars role + ansible.builtin.import_role: + name: rhc.rear.rear_vars + + - name: Check if ReaR restore was already completed + ansible.builtin.find: + paths: + - /var/tmp + patterns: + - rear_restore* + register: rear_restore_file + + - name: Check for previous restore and end host if already completed + 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 configuration backup exists ansible.builtin.stat: path: "/root/etc-rear-backup-{{ rear_backup_workflow }}.tar.gz" @@ -28,7 +39,7 @@ block: - name: Create tmpdir ansible.builtin.file: - path: /tmp/unarchive + path: "{{ rear_restore_tmpdir }}" state: directory mode: "0755" @@ -36,11 +47,11 @@ ansible.builtin.unarchive: remote_src: true src: "/root/etc-rear-backup-{{ rear_backup_workflow }}.tar.gz" - dest: /tmp/unarchive + dest: "{{ rear_restore_tmpdir }}" - name: Copy local.cfg from backup into /etc/rear ansible.builtin.copy: - src: /tmp/unarchive/rear/local.conf + src: "{{ rear_restore_tmpdir }}/rear/local.conf" dest: /etc/rear/local.conf remote_src: true mode: "0600" @@ -52,7 +63,17 @@ - name: Cleanup leftover artifacts ansible.builtin.file: - path: /tmp/unarchive + path: "{{ item }}" + state: absent + loop: + - "{{ rear_backup_success_file_path }}/{{ rear_backup_workflow }}_rear_success" + - "{{ rear_restore_tmpdir }}" + + - name: Create file for ReaR restore success + ansible.builtin.file: + path: "/var/tmp/rear_restore.{{ ansible_date_time.iso8601_basic }}" + state: touch + mode: "0664" # - name: Import rear_vars role # ansible.builtin.import_role: diff --git a/roles/rear_vars/defaults/main.yml b/roles/rear_vars/defaults/main.yml index 7c21f2f..987ddac 100644 --- a/roles/rear_vars/defaults/main.yml +++ b/roles/rear_vars/defaults/main.yml @@ -6,11 +6,14 @@ # - rear_restore rear_backup_workflow: standalone +# Used by: +# - rear_restore +rear_restore_tmpdir: /tmp/rear_restore + # Used by: # - rear_backup rear_backup_success_file_path: "/var/IPE/IPU/el7to8" - # Used by: # - nfs_export # - nfs_server_define diff --git a/roles/say_hi/README.md b/roles/say_hi/README.md deleted file mode 100644 index 225dd44..0000000 --- a/roles/say_hi/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Role Name -========= - -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. - -Role Variables --------------- - -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. - -Dependencies ------------- - -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } - -License -------- - -BSD - -Author Information ------------------- - -An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/say_hi/meta/main.yml b/roles/say_hi/meta/main.yml deleted file mode 100644 index f62fca5..0000000 --- a/roles/say_hi/meta/main.yml +++ /dev/null @@ -1,57 +0,0 @@ -galaxy_info: - author: Chris Hammer - description: Say Hi. - company: Hi. - - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Choose a valid license ID from https://spdx.org - some suggested licenses: - # - BSD-3-Clause (default) - # - MIT - # - GPL-2.0-or-later - # - GPL-3.0-only - # - Apache-2.0 - # - CC-BY-4.0 - license: GPL-2.0-or-later - - min_ansible_version: "2.14.0" - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. - # To view available platforms and versions (or releases), visit: - # https://galaxy.ansible.com/api/v1/platforms/ - # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 - platforms: - - name: EL - versions: - - "8" - - "9" - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. - -dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. diff --git a/roles/say_hi/tasks/main.yml b/roles/say_hi/tasks/main.yml deleted file mode 100644 index 2299a5b..0000000 --- a/roles/say_hi/tasks/main.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -- name: Say hi role - ansible.builtin.debug: - msg: "Hi." - -- name: Debug client_ips - ansible.builtin.debug: - msg: "{{ client_ips }}" - when: - - client_ips is defined - -- name: Debug namehost - ansible.builtin.debug: - msg: "{{ namehost }}" - when: - - namehost is defined - -- name: Debug roles_path - ansible.builtin.debug: - var: role_path - -# - name: Include rear_restore role for fun -# ansible.builtin.import_role: -# name: ../roles/rear_restore - -- name: Include rear_restore role for fun - ansible.builtin.import_role: - name: "{{ role_path }}/../rear_restore" - -... diff --git a/roles/say_hi/vars/main.yml b/roles/say_hi/vars/main.yml deleted file mode 100644 index debf2a1..0000000 --- a/roles/say_hi/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for say_hi