Site icon techbeatly

Ansible Tower – How to Backup and Restore

Image Background : datafloq.com

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.

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.

See detailed demo here.

Exit mobile version