Skip to content

Instantly share code, notes, and snippets.

@aleksandar-babic
Created July 19, 2017 22:40
Show Gist options
  • Save aleksandar-babic/ef29868899b0d96b7446c3c393643f50 to your computer and use it in GitHub Desktop.
Save aleksandar-babic/ef29868899b0d96b7446c3c393643f50 to your computer and use it in GitHub Desktop.
---
- hosts:
- containers
tasks:
#Check if nestegg3.py main script file exists
- stat:
path: /usr/local/sbin/nestegg3.py
register: resultPy
#Check if .nestegg3 exists in root home directory
- stat:
path: /root/.nestegg3
register: resultHome
#Get backup server which nestegg is using
- name: Read nestegg3.py file
shell: grep BACKUPSERVER= /usr/local/sbin/nestegg3.py | sed -e "s/\(.*'\)\(.*\)\('.*\)/\\2/"
register: resultBackupServer
when: resultPy.stat.exists == true and resultHome.stat.exists == true
#Get container backup ID
- name: Read container ID from .nestegg
shell: cat /root/.nestegg3 | cut -d "=" -f2
register: resultContainerId
when: resultPy.stat.exists == true and resultHome.stat.exists == true
#Get time of last backup
- name: Read last backup
shell: /usr/local/sbin/last_backup
register: resultLastBackup
ignore_errors: yes
when: resultPy.stat.exists == true and resultHome.stat.exists == true
#Write log file
- name: Add variables to Local log file(has nestegg)
local_action: shell echo "{{ansible_default_ipv4.address}},yes,{{ resultContainerId.stdout_lines }},{{ resultBackupServer.stdout_lines }},{{ resultLastBackup.stdout_lines }}" >> /root/nesteggLog.log
when: resultPy.stat.exists == true and resultHome.stat.exists == true
#Write log file
- name: Add variables to Local log file(does not nestegg)
local_action: shell echo "{{ansible_default_ipv4.address}},no,-,-,-" >> /root/nesteggLog.log
when: resultPy.stat.exists == false or resultHome.stat.exists == false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment