diff --git a/playbooks/gather_ipv4.yml b/playbooks/gather_ipv4.yml new file mode 100644 index 0000000..6570298 --- /dev/null +++ b/playbooks/gather_ipv4.yml @@ -0,0 +1,13 @@ +--- +- name: Gather IPv4 Addresses + hosts: all + gather_facts: true + become: false + + tasks: + - name: Set stats + ansible.builtin.set_stats: + data: + ip_addresses: "{{ ansible_all_ipv4_addresses }}" + server_hostname: "{{ ansible_hostname }}" + aggregate: true diff --git a/playbooks/nfs_export.yml b/playbooks/nfs_export.yml new file mode 100644 index 0000000..c5c0c68 --- /dev/null +++ b/playbooks/nfs_export.yml @@ -0,0 +1,46 @@ +--- +- name: Check SSH connectivity and create group of reachable hosts + hosts: rear_server + gather_facts: false + become: true + + tasks: + - name: Check SSH connectivity + ansible.builtin.ping: + register: result + failed_when: false + + - name: Clear unreachable host errors + ansible.builtin.meta: clear_host_errors + + - name: Add reachable hosts to group + ansible.builtin.group_by: + key: reachable_hosts + when: + - result['ping'] is defined + - "'pong' in result['ping']" + + +- name: Update NFS exports on reachable servers + hosts: reachable_hosts + become: true + gather_facts: false + + tasks: + - name: Grab the template name + ansible.builtin.set_stats: + data: + nfs_exports_template_name: "{{ tower_job_template_name | default('NA') }}" + aggregate: true + + - name: Create IP list and add to NFS exports + when: not rear_backup_skip | default(false) | bool + block: + - name: Create list with IP addresses and hostnames + ansible.builtin.set_fact: + client_ips: "{{ ip_addresses | list | flatten }}" + namehost: "{{ server_hostname }}" + + - name: Include NFS export role + ansible.builtin.include_role: + name: ../roles/nfs_export diff --git a/playbooks/rear_backup_validate.yml b/playbooks/rear_backup_validate.yml index 5e6e09d..37e1efe 100644 --- a/playbooks/rear_backup_validate.yml +++ b/playbooks/rear_backup_validate.yml @@ -1,5 +1,5 @@ --- -- name: Perform a ReaR backup +- name: ReaR Backup Validation hosts: all become: true gather_facts: true @@ -44,7 +44,7 @@ rescue: - name: No backup log found ansible.builtin.debug: - msg: "ReaR backup log could not be found to verify backup status. Please run the backup and try again." + msg: "ReaR backup log could not be found or an error was encountered. Please run the backup and try again." - name: OS Failure ansible.builtin.debug: diff --git a/roles/nfs_export/handlers/main.yml b/roles/nfs_export/handlers/main.yml new file mode 100644 index 0000000..27e6594 --- /dev/null +++ b/roles/nfs_export/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Export share + ansible.builtin.command: "exportfs -rav" diff --git a/roles/nfs_export/tasks/main.yml b/roles/nfs_export/tasks/main.yml new file mode 100644 index 0000000..1433e0e --- /dev/null +++ b/roles/nfs_export/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- name: Check disk space on ReaR Backup filesystem for NFS servers + ansible.builtin.shell: | + set -o pipefail + df -BG {{ share }} | tail -1 | awk '{print substr($4, 1, length($4)-1))' + register: disk_space + changed_when: false + +- name: Debug disk_space + ansible.builtin.debug: + var: disk_space + +- name: Fail job if less than 50GB space + ansible.builtin.fail: + msg: ReaR NFS server {{ inventory_hostname }} has less than 50GB of space on filesystem." + when: (disk_space.stdout|int <= 50) + +- name: Validate IP address fact + ansible.builtin.fail: + msg: "Missing client_ips variable" + when: + - client_ips is not defined + +- name: Ensure share directory exists + ansible.builtin.file: + path: "{{ share }}" + state: directory + mode: "0777" + owner: root + group: root + +- name: Add remote hosts to /etc/exports + ansible.builtin.lineinfile: + path: /etc/exports + state: present + line: "{{ share }} {{ _options }}" + loop: "{{ client_ips | list | flatten }}" + vars: + _options: "{{ item }}(fsid=0,rw,sync,no_subtree_check,crossmnt)" + notify: Export share diff --git a/roles/nfs_export/vars/main.yml b/roles/nfs_export/vars/main.yml new file mode 100644 index 0000000..1f2c20a --- /dev/null +++ b/roles/nfs_export/vars/main.yml @@ -0,0 +1,2 @@ +--- +share: "/backups/standalone" diff --git a/roles/rear_backup/defaults/main.yml b/roles/rear_backup/defaults/main.yml index 148e650..57376bc 100644 --- a/roles/rear_backup/defaults/main.yml +++ b/roles/rear_backup/defaults/main.yml @@ -1,11 +1,2 @@ --- -rear_nfs_srv: "10.10.42.180/backups" - -rear_backup_success_file: /var/log/IPE/IPU/bigboot_success - -# rear_backup_initrd_modules_exclude: -# - scsi_debug -# - falcon_lsm_serviceable -# - falcon_nf_netcontains -# - falcon_kal -# - falcon_lsm_pinned_16407 +rear_nfs_srv: "10.10.42.180" diff --git a/roles/rear_backup/tasks/main.yml b/roles/rear_backup/tasks/main.yml index 81c0543..6cfb973 100644 --- a/roles/rear_backup/tasks/main.yml +++ b/roles/rear_backup/tasks/main.yml @@ -19,10 +19,10 @@ when: - rear_force_backup | default(false) | bool block: - - name: Execute ReaR backup - ansible.builtin.command: rear -d -v mkbackup - changed_when: true - register: rear_mkbackup + # - name: Execute ReaR backup + # ansible.builtin.command: rear -d -v mkbackup + # changed_when: true + # register: rear_mkbackup - name: ReaR backup success ansible.builtin.debug: