Cleaning up old data in Ansible Tower
07 May 2019Older Ansible Tower versions don’t have cleanup tasks scheduled by default, which may lead to a very slow or even unusable Tower instance with lots of historic data. At that point it may not even be possible to schedule cleanup task and even if they are set up with lots of patience they may be so slow that they timeout. Luckily there’s a command line tool called awx-manage
, but in my case even that failed as the cleanup tasks also timed out.
At that point the only remedy is to manually delete data in Tower. I managed to unstuck a Ansible Tower 2.1.4 instance as follows:
Run the Tower shell via awx-manage
(ideally in a screen session, this may take a while):
Paste the following code into the shell to cleanup objects in the database:
This iterates through all Job
objects up to record_id=200000
and deletes them. You may have a lot less or a lot more objects in your Tower database, so you might have to adjust the 200000
to something else. I also had to delete the UnifiedJob
objects, so you also might have to run this:
This took several hours in my case, your mileage may vary. After this manual deletion went through the following awx-manage
cleanup commands started working again for me:
Finally I restarted Ansible Tower and the webinterface was reasonably fast again. Hope it works for you, too!
Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻