Ansible configures servers, Terraform creates infrastructure. They’re not competitors — they complement each other.
Terraform¶
- Infrastructure as Code
- Declarative (HCL)
- Creates/destroys infrastructure (VM, DB, DNS)
- State file
- Idempotent
Ansible¶
- Configuration Management + Orchestration
- Procedural playbooks (YAML)
- Configures existing servers (packages, files, services)
- Agentless (SSH)
- Ad-hoc commands
Example¶
Terraform — create a server¶
resource “aws_instance” “web” { ami = “ami-12345” instance_type = “t3.micro” }
Ansible — configure a server¶
- hosts: web tasks:
- apt: name=nginx state=present
- service: name=nginx state=started
When to Use Which¶
- Terraform — infrastructure provisioning (VM, DB, VPC, DNS)
- Ansible — server configuration (packages, files, services)
- Both — Terraform creates the VM, Ansible configures it
Terraform + Ansible = Complete IaC¶
They’re not competitors. Terraform for infra, Ansible for configuration.
ansibleterraformiacconfiguration management