Ansible Tower
Share on facebook
Share on twitter
Share on linkedin

Automating rolling server updates with Ansible Tower

Rob Marti
Rob Marti

Ansible Tower is a useful tool that can significantly improve your workflow, and it’s customizable specifically to your company’s procedures. One thing that’s common to quite a few different environments is the requirement to remove a web server from a load balancer, update its software, and then add it back into the load balancing pool. In this post, I’ll show how to accomplish this using Ansible and Ansible Tower.

What is Ansible? What is Ansible Tower?

Ansible is a great tool for managing your infrastructure by allowing you to define infrastructure as code. From deploying environments, managing software, to other daily maintenance, you can use Ansible to do it all. Ansible Tower brings all the power of Ansible into a functional web interface.

How to automate rolling server updates with Ansible

The first thing you’ll need to do is set up a git repository for your project. I’ve got mine here:

The playbook we’ll be using here is in blog/manage_LB.yml

Create your Project in Ansible Tower:

We set the SCM (Source Code Management) type to Git, give a link to our repository, and name the Project.

Now we can create the Job Template to actually run the playbook.

For playbooks that make changes to a server, I prefer to set Job Type to “Check” so that accidental job runs won’t make changes I’m not expecting. Checking the “Prompt on Launch” box will allow me to change that when needed.

We set the inventory to our Production inventory, select the relevant Project and playbook, and set up our credentials. Finally, I set a limit of “web” because I’m sending the entire production inventory to the playbook but I only want to run this playbook against web servers.

Once we run that job in “Check” mode and see that everything runs as expected, we can re-run it in “Run” mode. This is what the results page would look like:

As you can see here the first task to remove a server from the load balancer succeeded, updates were run (which took about 20 minutes) and then the server was added back to the load balancer. The script that adds/removes edits the nginx configuration file and restarts the service. It’s not the most perfect solution but it works for this example. 

As you can see, using Tower to manage Ansible tasks is both useful and easy. Using this methodology you can run all kinds of tasks to modify and manage your environment. If needed you can even use Workflows to set your tasks up for better management.

Here we sync our Project to make sure we have the latest playbook information, then we attempt to remove a server from the load balancer — causing a failure alert if it fails. If it works, however, we update the software on the web server — again, causing a failure alert if there are issues. Finally, we attempt to add the server back to the load balancer where there’s only an alert if it doesn’t work, and no other tasks.

Curious to know more about Ansible Tower? Check out ACG’s Red Hat Certified Specialist in Advanced Automation: Ansible Best Practices (EX447) Exam Preparation course where we cover this and more!

Master the most in-demand skills

A Cloud Guru makes it easy (and awesome) to level up your cloud career — whether you’re new to cloud or a seasoned pro. Check out ACG’s current free courses or get started now with a free trial.


Get more insights, news, and assorted awesomeness around all things cloud learning.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?