What is it
Ansible is a configuration management tool focused on automating OS settings and application deployment. Terraform is an infrastructure orchestration tool designed to create and modify resources via provider APIs.
| Parameter | Ansible | Terraform |
|---|---|---|
| Paradigm | Procedural (How to do) | Declarative (What to get) |
| State | Stateless | Stored in tfstate (Stateful) |
| Language | YAML | HCL (HashiCorp Configuration Language) |
| Management | Mutable Infrastructure | Immutable Infrastructure |
| Connection type | SSH / WinRM (Agentless) | Provider APIs |
Performance
Terraform performs faster when creating hundreds of cloud resources due to parallel API calls. By default, the -parallelism parameter is 10 but can be increased. Ansible is limited by SSH connection overhead. When working with 500+ nodes, playbook execution time grows linearly unless mitogen or forks settings in ansible.cfg are used.
Configuration & complexity
Ansible uses YAML, which simplifies entry for system administrators. Logic is built on sequential task execution. Terraform uses HCL, which requires understanding the dependency graph. Terraform code describes the final result, and dependencies (e.g., creating a subnet before launching a VM) are calculated automatically.
When to choose what
- Ansible: Nginx configuration, package installation, user management, security patching on existing servers.
- Terraform: Creating VPCs, RDS databases, Kubernetes clusters (EKS/GKE), load balancers in public clouds.
Cost / licensing
Ansible is distributed under the GNU GPLv3 license. As of August 2023, Terraform moved to the BSL (Business Source License) 1.1, which restricts its use in commercial products competing with HashiCorp. OpenTofu exists as an open-source alternative (Apache 2.0).
Ecosystem & integrations
Ansible Galaxy contains over 30,000 ready-to-use roles. Its strength lies in modules for OS (Linux, Windows, networking). The Terraform Registry provides providers for all major clouds (AWS, Azure, GCP) and SaaS services (Cloudflare, Datadog). Terraform integrates better with CI/CD pipelines for resource lifecycle management.
Verdict
For creating infrastructure from scratch in the cloud, Terraform is optimal. For deep OS configuration and code delivery to servers, Ansible is preferred. In modern projects, these technologies are often combined: Terraform creates VMs, and Ansible configures them via remote-exec or dynamic inventory.