How to Backup Ansible AWX? Ansible Tower comes along with “setup.sh“ to backup the database. If you are using the AWX (Ansible Tower’s upstream project), you could leverage tower-cli to take the object backups in the JSON format. You could also try this for Ansible Tower if the number of hosts are less than 100. In this article, we will walk through how to backup the AWX and restore it. If you do not have the towe-cli module, install it using pip module.
Here are some of the screenshots which took before deleting those objects.





tower cli configuration:
[root@ansible-server ~]# tower-cli config # User options (set with `tower-cli config`; stored in ~/.tower_cli.cfg). host: http://192.168.3.151:80 username: admin password: password verify_ssl: False # Defaults. format: human certificate: verbose: False description_on: False oauth_token: use_token: False color: True [root@ansible-server ~]#
Backup Ansibe AWX / Tower Configuration:
1. Execute the following command to take the complete AWX objects backup in flat file. You could see that backup created in JSON format.
[root@ansible-server ~]# tower-cli receive --all > 27032018.json [root@ansible-server ~]# more 27032018.json [ { "asset_type": "organization", "name": "Default", "asset_relation": { "roles": [ { "name": "Credential Admin", "team": [], "user": [] }, { "name": "Read", "team": [], "user": [] }, { "name": "Member", "team": [], "user": [] },
We have successfully backup the Ansible AWX / Tower objects in to file.
How to Check the Backup integrity? Can we delete the objects and try to restore?
Here are the snapshots after deleting objects on AWX/Tower.




Restore from the backup:
1. Restore the config using tower-cli send command.
[root@ansible-server ~]# tower-cli send 27032018.json USER [rajkumar] ***************************************************************************************************** Asset up to date USER [raffic] ****************************************************************************************************** Asset up to date USER [lingesh] ************************************************************************************** Asset up to date USER [admin] **************************************************************************************** Asset up to date ORGANIZATION [Default] *************************************************************************************************** Asset up to date All roles are up to date ORGANIZATION [UnixArena] *************************************************************************************************** Created organization UnixArena Added user rajkumar to Member role Added user lingesh to Member role Added user raffic to Member role Added user lingesh to Admin role TEAM [Database] *********************************************************************************** Created team Database TEAM [Unix] ************************************************************************************** Created team Unix TEAM [Wintel] ************************************************************************************ Created team Wintel CREDENTIAL [Demo Credential] ************************************************************************************************* Asset up to date All roles are up to date CREDENTIAL [UA-Linuxhost1] ************************************************************************************************ [WARNING]: Setting password for UA-Linuxhost1 to 'password' Created credential UA-Linuxhost1 Added user admin to Admin role PROJECT [Demo Project] ********************************************************************************************* Asset up to date All roles are up to date All schedules are up to date PROJECT [UnixArena_Project] ******************************************************************************************* Asset up to date All roles are up to date All schedules are up to date INVENTORY [Demo Inventory] ******************************************************************************************* Asset up to date All inventory host are up to date All inventory inventory_source are up to date All inventory groups are up to date All roles are up to date INVENTORY [Linux_UA_Hosts] ******************************************************************************************* Created inventory Linux_UA_Hosts Unable to create inventory_source named (Linux_UA_Hosts - 7) : The Tower server claims it was sent a bad request. POST http://192.168.3.151:80/api/v2/inventory_sources/ Params: None Data: {"name": " (Linux_UA_Hosts - 7)", "source": "file", "inventory": 3, "source_path": "/var/lib/awx/hosts_add"} Response: {"detail":["Cannot set source_path if not SCM type."]} Schedules are up to date All inventory groups are up to date All roles are up to date JOB TEMPLATE [Check Filesystem usage on hosts] ********************************************************************************************* Created job_template Check Filesystem usage on hosts Added user raffic to Execute role Added team Unix to Admin role Added schedule Test Updating survey All labels are up to date All extra creds are up to date JOB TEMPLATE [Demo Job Template] ******************************************************************************************** Asset up to date All roles are up to date All schedules are up to date Survey up to date All labels are up to date All extra creds are up to date JOB TEMPLATE [Grant Root access to Normal user] ******************************************************************************************* Created job_template Grant Root access to Normal user All roles are up to date All schedules are up to date Survey up to date All labels are up to date All extra creds are up to date JOB TEMPLATE [Servers ping test] ****************************************************************************************** Created job_template Servers ping test All roles are up to date All schedules are up to date Survey up to date All labels are up to date All extra creds are up to date WORKFLOW [Test workflow] ************************************************************************** Checking on workflow_nodes Created workflow Test workflow All roles are up to date All schedules are up to date Survey up to date All labels are up to date Building new workflow nodes Building workflow node relations PLAY RECAP ****************************************************************** ok=45 changed=21 warnings=1 failed=1 [root@ansible-server ~]#
We have successfully restored the complete AWX/tower objects. You could log in to AWX/Tower portal and check the object status.
You could face the issue with credentials its likely due to encrypted nature. You might need to update the password again after tower-cli restore.
Hope this article is informative to you. Share it! Comment it!! Be Sociable!!!
The post Backup/Restore – Ansible AWX – tower-cli appeared first on UnixArena.