← All comparisons
Ansible iconTerraform icon

Ansible vs Terraform

Terraform provisions infrastructure and Ansible configures servers. Here is how they differ and when to use each.

Ansible vs Terraform: the short answer

Use Terraform to create cloud resources: servers, databases, networks, DNS. Use Ansible to configure what runs on a machine once it exists: packages, files, services. They overlap less than the names suggest, and many teams run both. If you only have one or two VPS instances, Ansible alone is usually enough. If you live in a cloud console, start with Terraform.

What is Ansible?

Ansible is a free, open source configuration management tool. It runs tasks against servers over SSH using YAML playbooks, with no agent to install on the target machines. Playbooks describe desired state, and rerunning one only changes what is out of sync.

What is Terraform?

Terraform is a declarative infrastructure-as-code tool. You describe cloud resources in HCL files, and it works out a plan to make reality match. It supports nearly every major cloud and SaaS provider, and it is now owned by IBM after the HashiCorp acquisition.

Ansible vs Terraform pricing

Ansible:

  • The tool itself is free and open source.
  • Red Hat sells Ansible Automation Platform for enterprise support, with pricing set by Red Hat. Check the pricing page.

Terraform:

  • The open source CLI is free to use.
  • HCP Terraform, the hosted product, is priced per managed resource per month: Essentials at $0.10, Standard at $0.47, Premium at $0.99. Enterprise is custom.
  • New users get a $500 trial credit. A separate permanent free tier wasn't confirmed on the pricing page, so check it before relying on one.

Pricing checked November 2026. For a solo builder both are free if you run the CLI yourself. The cost shows up only when you want hosted state, team workflows or vendor support.

Key differences

  • Provision vs configure. Terraform creates the infrastructure. Ansible sets up the software on it. Ansible can create cloud resources too, but it is weaker at that.
  • State. Terraform keeps a state file of what it believes exists, which enables diffs and drift detection. Ansible has no equivalent, so it simply runs tasks against hosts.
  • Plan before change. terraform plan shows what will change before anything applies. That is the main protection against surprise destructive changes. Ansible can dry-run with check mode, but it is less complete.
  • Agentless over SSH. Ansible connects with existing SSH credentials. Terraform talks to cloud APIs instead, so it needs provider credentials rather than server access.
  • Language. Ansible uses YAML playbooks. Terraform uses HCL, which is more structured but one more thing to learn.
  • Ecosystem. Terraform has hundreds of providers and a public module registry. Ansible has a large module collection covering package managers and common services.

When to pick Ansible

  • You manage bare VPS instances or a mixed fleet that isn't fully containerized.
  • You need to install packages, template config files and restart services repeatably.
  • You want something that works over SSH with nothing to install on the servers.
  • You have a handful of servers and don't need to track cloud resources.

When to pick Terraform

  • You create and change cloud resources: VPCs, databases, DNS records, IAM.
  • You want a reviewable plan before every change.
  • You work across several providers or accounts and want one workflow.
  • You've outgrown clicking resources together in a console.

Other options

If the license matters to you, OpenTofu is the open source Terraform fork with the same HCL workflow. If you'd rather write infrastructure in TypeScript, Python or Go, look at Pulumi. If everything you run is containerized, Docker replaces much of what a playbook configures.

Verdict

Pick the tool that matches the job: Terraform for creating infrastructure, Ansible for configuring servers. For a solo builder with a couple of VPS instances, Ansible is the smaller step. Add Terraform when you have cloud resources worth tracking, and run both once you do.