Ansible Tower is a wonderful product which help to implement a central hub for IT automation. Ansible Tower is basically a web console and REST API for underlying Ansible Engine but with more features and acts as centralized system with logging and RBAC (Role Based Access Control).
Refer Ansible Tower Installation document for installation.
Installing and configuring Ansible Tower (with or without HA) is a straightforward task but what if we need to take backup of the setup ? We have jobs, templates, projects, credentials everything in Tower; how can we take backup of the Ansible Tower and restore it in case of emergency ?
Fortunately this is made easy with the setup.sh file that comes with tower package . Yes, the same setup.sh file that you use for installing Ansible Tower.
So, the setup.sh script will take below arguments for backup or restore operations. And setup.sh script will use the same inventory file (which you have used for installation, for backup/restore operations.
Please note, backup-restore operation for Ansible Tower Cluster is almost same but refer documentation to undertstand the difference.
./setup.sh -b will invoke few playbooks (backup.yml and other ansible roles) to backup each and every configurations as well as database.
[[email protected] root]# cd ansible-tower-setup-3.5.2-1/
[[email protected] ansible-tower-setup-3.5.2-1]# ./setup.sh -b
Using /etc/ansible/ansible.cfg as config file
[WARNING]: Could not match supplied host pattern, ignoring: instance_group_*
PLAY [tower:instance_group_*] *********************************************************************************
TASK [Gathering Facts] ****************************************************************************************
ok: [localhost]
TASK [check_config_static : Ensure expected variables are defined] ********************************************
.
.
<output truncated>
.
.
PLAY RECAP ****************************************************************************************************
localhost : ok=37 changed=29 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
The setup process completed successfully.
Setup log saved to /var/log/tower/setup-2019-09-24-09:18:58.log
You can see the backup file at the end of output and which is linked as tower-backup-latest.tar.gz and pointing to actual backup file in same location. This is for easiness during restore operation.
[[email protected] ansible-tower-setup-3.5.2-1]# ls -l |grep tower-backup
-rw-r--r--. 1 root root 247266 Sep 24 09:19 tower-backup-2019-09-24-09:19:03.tar.gz
lrwxrwxrwx. 1 root root 82 Sep 24 09:19 tower-backup-latest.tar.gz -> /root/installs/ansible-tower-setup-3.5.2-1/tower-backup-2019-09-24-09:19:03.tar.gz
We use same setup.sh script to restore Ansible Tower from a backup file but with -r argument. This will invoke restore.yml playbook and restore operation.
[[email protected] ansible-tower-setup-3.5.2-1]# ./setup.sh -r
Using /etc/ansible/ansible.cfg as config file
PLAY [database] ***********************************************************************************************skipping: no hosts matched
[WARNING]: Could not match supplied host pattern, ignoring: instance_group_*
PLAY [tower:instance_group_*] *********************************************************************************
TASK [Gathering Facts] ****************************************************************************************
ok: [localhost]
.
.
<output truncated>
.
.
PLAY RECAP ****************************************************************************************************
localhost : ok=43 changed=24 unreachable=0 failed=0 skipped=14 rescued=0 ignored=0
The setup process completed successfully.
Setup log saved to /var/log/tower/setup-2019-09-24-09:29:08.log
Please note, Ansible Tower services will be stopped/restarted during restore operation.
As I told before, you can mention default backup file (tower-backup-latest.tar.gz) to restore unless you saved it in a different path. You can mention different restore path as below by using EXTRA_VARS.
[[email protected] ansible-tower-setup-3.5.2-1]# ./setup.sh -e 'restore_backup_file=/path/to/your-backup.tar.gz' -r
That’s it.
See detailed demo here.
Disclaimer: The views expressed and the content shared are those of the author and do not reflect the views of the author’s employer or techbeatly platform.
Gineesh Madapparambath
Gineesh Madapparambath is the founder of techbeatly and he is the author of the book - ๐๐ป๐๐ถ๐ฏ๐น๐ฒ ๐ณ๐ผ๐ฟ ๐ฅ๐ฒ๐ฎ๐น-๐๐ถ๐ณ๐ฒ ๐๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป.
He has worked as a Systems Engineer, Automation Specialist, and content author. His primary focus is on Ansible Automation, Containerisation (OpenShift & Kubernetes), and Infrastructure as Code (Terraform).
(aka Gini Gangadharan - iamgini.com)
This site uses Akismet to reduce spam. Learn how your comment data is processed.1 Response
Leave a Reply Cancel reply
[…] Read : How to back and restore Ansible Tower ? […]