Ansible vs Terraform
Compare configuration management with infrastructure provisioning tools.
| Dimension | Ansible | Terraform | What it means in practice |
|---|---|---|---|
| Primary job | Configure systems and devices (packages, files, services, device config). | Create and change infrastructure resources (VMs, networks, cloud services). | Many teams use Terraform to create and Ansible to configure. |
| Model | Ordered tasks in playbooks; modules aim to be idempotent. | Declarative resources with a dependency graph. | Terraform plans the whole change before applying. |
| State | No state file; reads current state from targets. | State file maps resources to real objects. | Protect and lock Terraform state; it may contain secrets. |
| Connection | SSH, WinRM or network device APIs; agentless. | Provider APIs. | Ansible needs reachability to each host. |
| Preview | --check and --diff (if modules support it). | terraform plan. | Review plans in CI before apply. |
| Verification | ansible-playbook site.yml --check --diff | terraform plan -detailed-exitcode | Exit code 2 from plan means changes are pending. |