Ansible vs Terraform

Ansible and Terraform are both amazing tools with different use cases, however, some of their use cases can overlap. For example, both Ansible and Terraform can be used to deploy and configure AWS, Azure, GCP, Cisco ACI or hundreds of other platforms. In most environments, especially mutli-cloud or hybrid environments, you could, and may be should use both tools to get best of both worlds. For example, you’d setup the Infrastructure-as-code (IAC) using Terraform, and then also use a Terraform “provisioner” to invoke an Ansible Playbook to do the required configuration.

Here are some key differences between the two platforms at a high-level.

PurposePrimarily designed for configuration management, but can also be utilized as an Infrastructure-as-code (IAC) toolEntirely designed to be an infrastructure-as-code tool, but, can also handle light configuration activities.
StateAnsible does not maintain infrastructure or configuration stateTerraform maintains infrastructure state
IdempotencyIs idempotent – but less idempotent than Terraform. For example, if you have a playbook to create an EC2 instance, depending on how it’s written, it may create a new instance.Is idempotent for the infrastructure that is within it’s state file. Is not idempotent if it’s not in the state file or is not imported into the state file. In the EC2 example, it will NOT create a new instance when a Terraform configuration is applied a second time using the same configuraiton.
ComplexityAnsible has a significantly higher learning curve – but is also more configurable.Much easier to get started with, but, lacks the configurability of Ansible.
Platforms SupportOnly runs on Linux, Mac and Unix (but it’s easily enough to run a Linux VM if you are on Windows!)Natively supported on Windows, Linux, Unix, Solaris, Mac, etc.
Supported PlatformsCan manage and configure anything that has a CLI or API.

Functionality, idempotency and features can be enhanced using the Ansible Collections. As of May 4, 2022, there are 31,000 collections
Terraform natively can only support platforms listed in the Terraform Registry:

As of May 4, 2022, there are 2059 supported platforms
TroubleshootingErrors are very crypticErrors are very easy to decipher
Ease of ConfigurationYAML can be a pain to work with – as the spaces, tabs, etc. are significant, and can lead to frustrating errors when off by just a single space character. When everything is correct however, it’s easy to read and decipher.Hashicorp Configuration Language (HCL) is super easy to read and decipher, and doesn’t suffer from the limitations and frustrations of dealing with YAML. It doesn’t care about spaces or indentation. There is also a nice “terraform fmt” command to keep code clean looking.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: