Cyber Deals - Get up to 65% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

Ansible Tower – How to Backup and Restore

Ansible Tower – How to Backup and Restore
Image Background : datafloq.com
[Ansible Tower](https://access.redhat.com/products/ansible-tower-red-hat/) 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](https://access.redhat.com/products/red-hat-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.

  • -b : Perform a database backup.
  • -r : Perform a database restore operation.

Please note, backup-restore operation for Ansible Tower Cluster is almost same but refer documentation to undertstand the difference.

How to backup Ansible Tower

./setup.sh -b will invoke few playbooks ( backup.yml and other ansible roles) to backup each and every configurations as well as database.

[root@tower root]# cd ansible-tower-setup-3.5.2-1/

[root@tower 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.

[root@tower 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

How to restore Ansible Tower from backup

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.

[root@tower 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 .

[root@tower ansible-tower-setup-3.5.2-1]# ./setup.sh -e 'restore_backup_file=/path/to/your-backup.tar.gz' -r

That’s it.

Subscribe YouTube Channel

See detailed demo here.

Gineesh Madapparambath

Gineesh Madapparambath

Gineesh Madapparambath is the founder of techbeatly. He is the co-author of The Kubernetes Bible, Second Edition and the author of Ansible for Real Life Automation. 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). (Read more: iamgini.com)


Disclaimer: Views expressed in articles are those of the respective authors and do not necessarily reflect the views of their employers or this site. While we aim for accuracy, please verify information before relying on it, and let us know if you spot an error.
Share:

Related Posts

Ansible Deployment

Ansible Deployment

Hope you are clear on the concept and installation of Ansible program. Lets configure our Ansible environment now. See all parts of Automation with …

Managing Ansible Facts

Managing Ansible Facts

Ansible facts are nothing but some variables which are automatically discovered by the Ansible on managed hosts while running ansible adhoc commands …

Ansible

Ansible Nested Loop with List and Dictionary

Ansible loops are simple and powerful with mixed data. You will sure say “awesome” when you realize the easiness with loops. During our technical …

Ansible Introduction

Ansible Introduction

You have hundreds and thousands of online documentation and wiki pages for learning Ansible, and this is our attempt to cover Ansible in a simple...

SSSD AD integration on RHEL7 using Ansible

SSSD AD integration on RHEL7 using Ansible

Most of the time , we have requirement to integrate Linux systems in our environment with AD for Centralized user management. It will be tedious...

Ansible and Jenkins integration – Red Hat Webinar

Ansible and Jenkins integration – Red Hat Webinar

Join this Red Hat webinar to see how to use Jenkins pipelines to deploy simple applications using Ansible Tower. Here see the quick overview of...