Ansible & Hashicorp Terraform

Automatic Creation of Inventory from Terraformer

To use ansible on the resources provisioned by Terraformer, ansible needs to know the ips of the provisioned resources.

We will be leveraging the local provider. This will allow us to create the inventory file using the output of terraformer.

Add the following block to end of


resource "local_file" "AnsibleInventory" {
 content = templatefile("inventory.tmpl",
  droplet-ip = digitalocean_droplet.personal-automated.ipv4_address
 filename = "../inventory"

This requires the template file inventory.tmpl which should be created with the below contents


Here, I am provisioning a digitalocean_droplet with the resource name personal-automated, which is why you see those referenced above.

After adding the local_file provider, you will need to run terraformer init to install it.

terraformer init

As usual, you can apply the changes using

terraformer apply

The changes for this post can be referred to in this pull request.

The Repository at this point of time will look something like this.

Next Steps

Now, we need to setup ansible and run some playbooks on the newly minted server.

Project Page


Related Posts

2 thoughts on “Automatic Creation of Inventory from Terraformer

Leave a Reply

%d bloggers like this: