midDevOps
Ansible vs Terraform: When to use which?
Updated Apr 28, 2026
Short answer
Terraform is an orchestration tool for provisioning infrastructure. Ansible is a configuration management tool for configuring software inside that infrastructure.
Deep explanation
Terraform excels at maintaining the immutable desired state of cloud resources (VPCs, EC2s, Security Groups) using its state file. Ansible excels at imperative execution (installing packages, updating config files) via SSH without needing an agent. They are often used together.
Real-world example
Using Terraform to provision an AWS EC2 instance and a Load Balancer, then invoking Ansible to install and configure Docker and the application inside the EC2 instance.
Common mistakes
- Trying to use Ansible to manage complex cloud infrastructure states, which leads to difficult-to-maintain imperative scripts.
Follow-up questions
- Is Ansible declarative or imperative?