Pre Checks Role
The pre_checks
role verifies the systems are configured correctly, that they are valid Chef servers, and it collects information from which to determine where in the process the play might have ended previously.
---
- import_tasks: pre_checks.yml
tags:
- pre_checks
- create_backup
- restore_backup
- cleanup
...
---
# Need to enable IPv6 at the grub level first
- name: Enable IPV6 on Ubuntu systems
sysctl:
name: net.ipv6.conf.lo.disable_ipv6
value: '0'
sysctl_set: yes
state: absent
when:
- ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
delegate_to: "{{ item }}"
loop:
- "{{ chefsrv_bkup | lower }}"
- "{{ chefsrv_main | lower }}"
# Verify chef is running on both servers.
- name: "Verify backup command exists on all servers"
shell:
cmd: /opt/opscode/bin/knife ec backup -h
register: knife_ec_backup
failed_when: knife_ec_backup.rc > 1
delegate_to: "{{ item }}"
loop:
- "{{ chefsrv_bkup | lower }}"
- "{{ chefsrv_main | lower }}"
# Verify permissions of log directories.
- name: "Verify /var/log/opscode/postgresql has correct permissions on all servers"
file:
path: /var/log/opscode/postgresql
state: directory
mode: '0750'
owner: opscode
group: opscode
delegate_to: "{{ item }}"
loop:
- "{{ chefsrv_bkup | lower }}"
- "{{ chefsrv_main | lower }}"
# Check if the backup command had been run.
- name: "See if the backup command has run on {{ chefsrv_main | lower }}"
stat:
path: /var/opt/chef-backup/backup_complete.lock
register: orig_backup_check
delegate_to: "{{ chefsrv_main | lower }}"
# Check if it exists on the old server.
- name: "See if the archive is on the {{ chefsrv_main | lower }}"
block:
- name: "See if the archive is on the {{ chefsrv_main | lower }}"
find:
paths: /var/opt/chef-backup/
patterns: 'chef-backup-*.tgz'
age: -12h
register: found_files_on_old_lt12
- name: "Get latest file on {{ chefsrv_main | lower }}"
set_fact:
latest_file_old: "{{ (found_files_on_old_lt12.files|sort(attribute='mtime')|last).path | default('/chef-backup/noarchive.gz') }}"
- name: "Stat latest file on {{ chefsrv_main | lower }}"
stat:
path: "{{ latest_file_old }}"
register: chef_backup_ark
- name: "See if the pem archive is on the {{ chefsrv_main | lower }}"
find:
paths: /var/opt/chef-backup/
patterns: 'chef_admin_pem_*.tgz'
age: -12h
register: found_pem_ark_on_old_lt12
- name: "Get latest pem ark on {{ chefsrv_main | lower }}"
set_fact:
latest_pem_old: "{{ (found_pem_ark_on_old_lt12.files|sort(attribute='mtime')|last).path | default('/chef-backup/noarchive.gz') }}"
- name: "Stat latest pem ark on {{ chefsrv_main | lower }}"
stat:
path: "{{ latest_pem_old }}"
register: chef_admin_pem_ark
delegate_to: "{{ chefsrv_main | lower }}"
# Check if the archive exists on the new server.
- name: "See if the archive is on {{ chefsrv_bkup | lower}}"
find:
paths: /var/opt/chef-backup/
patterns: 'chef-backup-*.tgz'
register: found_files_on_new
- name: "Get latest file on {{ chefsrv_bkup | lower}}"
set_fact:
latest_file_new: "{{ (found_files_on_new.files|sort(attribute='mtime')|last).path | default('/chef-backup/noarchive.gz') }}"
- name: Stat latest file on {{ chefsrv_bkup | lower}}
stat:
path: "{{ latest_file_new }}"
register: new_svr_ark_pre
- name: "See if the pem archive is on {{ chefsrv_bkup | lower}}"
find:
paths: /var/opt/chef-backup/
patterns: 'chef_admin_pem_*.tgz'
register: found_pem_files_on_new
- name: "Get latest pem ark on {{ chefsrv_bkup | lower}}"
set_fact:
latest_pem_new: "{{ (found_pem_files_on_new.files|sort(attribute='mtime')|last).path | default('/chef-backup/noarchive.gz') }}"
- name: "Stat latest pem ark on {{ chefsrv_bkup | lower}}"
stat:
path: "{{ latest_pem_new }}"
register: new_pem_ark_pre
# Setting facts for future playbook use.
- name: Setting pre-check facts.
set_fact:
chef_backup_ark_filename: "{{ chef_backup_ark.stat.path | default('noarchive_old') | basename }}"
chef_admin_pem_ark_filename: "{{ chef_admin_pem_ark.stat.path | default('noarchive_old') | basename }}"
new_svr_ark_filename: "{{ new_svr_ark_pre.stat.path | default('noarchive_new') | basename }}"
new_pem_ark_filename: "{{ new_pem_ark_pre.stat.path | default('noarchive_new') | basename }}"
...