Ansible tomcat installation + .war deploy

25/06/2015 Wannes Van Causbroeck

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:
setup

 

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

Share this AWSome post

Comments (2)

  1. Jaypal

    How to deploy ear,war and jar files with ansible playbooks

    Thanks
    Jaypal

    • Bert Mertens

      Hi Jaypal,

      The blog post you responded to describes how to deploy WAR files on Apache Tomcat.

      The site.yml playbook first creates and prepares an EC2 instance using the infrastructure role and then installs Tomcat using the tomcat role.

      When the server has been prepared, you can run the deploy.yml playbook.

      This will then deploy the WAR file from an S3 bucket.

      Concerning JAR and EAR files, please see for example following link (https://stackoverflow.com/questions/1594667/war-vs-ear-file) describing the differences.

      You’ll be able to find plenty more guides online on setting up infrastructure and deployment guides.

      Feel free to reach out to our sales department if you need any assistance.

      Kind regards,
      Bert

Leave a Reply

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