Basics of Packer / Ansible / Terraform and how they fit together

Yatin Gupta
2 min readJul 20, 2021

In this article, I’ll try to summarise the learnings I had when I worked with these technologies to handle the DevOps side of things

What are these tools?

These are DevOps tools that can be used to create immutable structures. They are used for automating the process of creation, installation, etc of our servers.

Why Immutable structures?

  • Predictable systems
  • Faster to deploy
  • More secure, since they are generally ephemeral

How do these tools work together?

Connection of these tools ( In AWS context )

“Packer is an open-source tool for creating identical machine images for multiple platforms from a single source configuration.”

Packer is used to create VMs, add required configuration and then package it as an AMI. Packer supports multiple “provisioners,” which handle the actual server configuration. These configurations can be shell scripts or tools like Ansible.

Ansible is a configuration management tool using YAML syntax which automates software installation, starting custom servers, pulling docker images, etc whatever is required.

Terraform is a tool that allows us to “safely and predictably create, change, and improve infrastructure.” We use terraform to write infrastructure as a declarative code.

So the AMI made with PACKER + ANSIBLE can be used in TERRAFORM. This is how these tools connect.

We can also replace terraform with custom Gitlab CI/CD and trigger a rolling deployment on AWS ASG.

Packer and ansible make an efficient, predictable combination where complex projects can be built. Packer can start a new clean machine, using Ansible we can install everything, run our heavy tests, and only after tests pass, packer packages into a new AMI. Then this AMI can be released.

This makes the release process on complex projects fast, predictable, safe and automated.

References :

  1. https://madeintandem.com/blog/packer-ansible-terraform-devops-immutable-servers/

--

--