Skip to content

Ansible and Terraform: the best of both worlds

Ansible and Terraform are the fastest growing automation tools at this point in time. So, “What tool should we use in our company?” is becoming a Frequently Asked Question (FAQ). These tools don’t have to be competitive, you can combine them to achieve great things. 

In this series, we will show you how these tools can work together and how you can benefit from them. Ansible will be used as the orchestrator, as a glue to put everything together. Based on a live example we will show you how to work with these tools. 

We will install a web- and a database server on Amazon AWS using Terraform and Ansible. We will use the free Micro instances to provision and deploy the example Virtual Machines.  

In the first episode of this series, we set up the prerequisites. The second episode is where the “magic happens”: we will run the playbook and let Ansible and Terraform do the “hocus-pocus” to deploy the servers. In the third and last episode, we will explain what goes on “behind the scenes”: the Ansible and Terraform code explained. 

Episode 1: Ansible, Terraform installation and prerequisites for AWS

1. Install Ansible and Terraform.

Let’s get started. First, we are going to install Ansible.

This can be done as follows:

As you can guess, we will also need Terraform, this is not in the standard repo’s and can be installed this way:

– you need wget and unzip

– Install the latest Terraform: version 0.12.18.

  (please check for newer versions here)

Now, we can check if these tools are installed.

Looking good.

2. AWS account 

You can get a free AWS account here.

Click on the [Create a Free Account]-button and follow the steps. You need to enter your credit card details, but no worries. As long as you stick to our example, it will be free of charge, because we are using components of the free-tier which will stay free even after 12 months. 

Once you have created your account you should be able to login into the webconsole and create a user.

[Add User] – button.

We will create an integration user which will be used for the Ansible/Terraform automation.

Add this user to the Admins group.

Make sure you have the credentials stored!

Download the credentials via the [Download .csv]-button. We will need these in the next episode.

Next, we are going to create a ssh-key on our machine that we can use to access the VM’s on AWS after we deployed them.

Leave the passphrase empty, the private key (id_rsa) will be created together with a public one. ( This public key will be added to the virtual machines.

So, now that you have Ansible and Teraform installed, created the ssh keys and an integration user on your new (or existing) AWS account, you are ready to move on.

What’s next?

This blog post is part of the series “Ansible and Terraform working together: the best of both worlds”. Next time we will provision and deploy the servers on the AWS. 

If you have any questions or need help with your tools, don’t hesitate to contact Hans Neefs via mail or phone.