Ansible tomcat installation + .war deploy

25/06/2015 Wannes Van Causbroeck

Ansible tomcat installation + .war deploy

Hi all, new employee here.
To start learning about ansible and AWS, I created a small setup that does the following:

  • create an aws instance
  • install tomcat on it
  • deploy a .war file from S3 and edit its contents

While this is a very simple exercise, it does touch on some interesting topics about ansible and aws.
To start, we need something like this:


  • an S3 bucket to store our .war files
  • a nat host so ansible tower can manage servers from our vpc in the remote vpc
  • (and in our case an S3 read-only IAM policy as our version of ansible doesn’t support policy creation yet)

Tower config

To allow our tower to connect through the nat host we need some extra config.
In the root of our project we need an ansible.cfg file containing:

This allows ansible to use the ssh configuration stored on the tower server. This is what it looks like:

I won’t detail the tower configuration of the project/inventory/job/… here in detail as it’s quite straightforward.

Ansible playbook

So, we need two playbooks. The first one sets up a node and installs tomcat.

The second one deploys the war and edits a file.

We need to split these up as both playbooks need a different inventory to work with:

  • provision & install: ‘tower-via-local’ which is located in our VPC
  • configuration: here we get the sandbox vpc ec2 instances and select a specific tagname we gave during provisioning

In theory, you could work with a callback to tower for the second part, but then you need to set up a way for the client to reach the server through the nat instance. As we don’t need this functionality right now, we’re skipping this step.

One of the nice things about tower is you can create simple forms provide variables to our playbooks. In this case I made two forms to provide the number of instances and the name of the war file.

The next role just installs tomcat

Ok, so now we have some servers ready to go. The next playbook uses a different inventory

This concludes our little exercise! Feel free to leave comments, I’m sure there is still room for improvement.

Leave a Reply

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