Skip to content

Ansible Tower – How to Backup and Restore

Avatar photo

https://www.linkedin.com/in/gineesh/ https://twitter.com/GiniGangadharan

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.

  • -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.

See detailed demo here.

Disclaimer:

The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.

Avatar photo


https://www.linkedin.com/in/gineesh/ https://twitter.com/GiniGangadharan
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)

Comments

1 Response

  1. […] Read : How to back and restore Ansible Tower ? […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.