Skip to content
CAMPUX Cloud Bootcamp
Field notes · DevOps
Ansible vs Terraform

Ansible vs Terraform: what each does and which to learn for a cloud job

By Captain O7 min readUpdated Aug 2026

This gets argued about as if it were a fight, and half of that is a category mistake. Terraform and Ansible are not two tools for the same job — they are two tools for two jobs that sit next to each other. Get that straight and the whole "versus" dissolves into a much more useful question: which problem are you solving first?

New to cloud? CAMPUX is a free, build-first course. Start here →

Here is the confusion at the root of it. Terraform is a provisioning tool: it builds and manages infrastructure — the virtual machines, the networks, the cloud resources themselves. Ansible is a configuration-management tool: it sets up what runs on that infrastructure — installing software, editing config files, deploying applications. One creates the servers; the other configures them. They overlap a little at the edges, which is where the arguments come from, but each is built for a different lane, and the professionals who use both know exactly where the line sits.

The short version

Terraform builds the infrastructure; Ansible configures it. Terraform is declarative infrastructure as code with a state file — it provisions cloud resources and tracks them. Ansible is task-based automation over SSH — it configures existing machines, installing and setting up what runs on them, with no agent and no state file. They are complementary, and the common professional pattern is to use both: Terraform provisions, Ansible configures. If you must pick one to learn first for a cloud or DevOps job, learn Terraform — provisioning cloud infrastructure as code is the more common requirement. Add Ansible when you need to configure fleets of machines.

Terraform: builds the infrastructure

Terraform, from HashiCorp, is an infrastructure-as-code tool for provisioning. You describe the infrastructure you want — networks, virtual machines, databases, cloud services — in declarative HCL, run terraform plan to preview and terraform apply to build, and Terraform keeps a state file recording what it created so it can reason about changes and drift. It is declarative (you describe the end state, not the steps), it spans clouds through providers, and its whole worldview is "here is the infrastructure that should exist — make reality match." When the job is standing up the servers and the network in the first place, Terraform is the tool.

Ansible: configures what runs on it

Ansible, from Red Hat, is a configuration-management and automation tool. Once machines exist, Ansible connects to them — agentless, over SSH for Linux or WinRM for Windows, with nothing to install on the targets — and runs playbooks: ordered lists of tasks written in YAML that install packages, edit files, start services, and deploy applications. Its modules are idempotent, so running a playbook twice does not double-apply, and it keeps no separate state file — it checks each machine's current state as it goes. Ansible's worldview is "here are the machines, here is how they should be set up — go make it so." When the job is configuring what lives on the servers, Ansible is the tool.

TerraformAnsible
Primary jobProvision infrastructureConfigure machines
CategoryInfrastructure as codeConfiguration management
LanguageHCL (declarative)YAML playbooks (task-based)
StateKeeps a state fileNo state file — checks live state
AgentN/A (calls cloud APIs)Agentless — SSH / WinRM
Best atBuilding servers, networks, cloud resourcesInstalling, configuring, deploying on them
MakerHashiCorpRed Hat

Terraform builds the house. Ansible furnishes it. Arguing which is "better" is like arguing whether you need a builder or an electrician.

The pattern that ends the argument: use both

In real work, the two are not an either/or — they are a relay. Terraform provisions the infrastructure: it creates the virtual machines, wires the network, opens the right ports. Then it hands off to Ansible, which configures those freshly-built machines: installs the runtime, drops in the config, deploys the app. One builds, the other sets up. Understanding where that handoff sits is exactly the kind of thing that lands well in an interview, because it shows you grasp each tool's real job instead of treating them as interchangeable. Yes, each can technically stray into the other's lane — Ansible has cloud modules, Terraform has provisioners — but doing so usually fights the tool, and it is not how strong teams work.

So which do you learn first?

Since they do different jobs, "which first" is really "which problem do you need to solve first."

Whichever you start with, both are declarative-minded, both live in Git, and both teach the same core habit: describe what you want as code and let a tool make it real. Learn one well and the second is far less daunting — a new syntax over a mindset you already hold. If you want the wider map of where these sit, the order to learn DevOps tools places them in the full sequence, and what is infrastructure as code covers the idea underneath Terraform.

Your next class · free
You've read the idea. Class 21 — Infrastructure as Code: Terraform is where you build it, hands-on — no account needed.Start Class 21 →
Captain O
Founder & instructor · CAMPUX Cloud Engineering Bootcamp

Questions people also ask

What is the difference between Ansible and Terraform?

They solve different problems. Terraform is a provisioning tool — it builds and manages infrastructure, like virtual machines, networks and cloud resources, from declarative code and a state file. Ansible is a configuration-management tool — it sets up what runs on that infrastructure, like installing packages, editing config files and deploying apps, through task-based playbooks over SSH. The short version: Terraform creates the servers, Ansible configures them. They overlap a little at the edges, but each is built for a different job.

Should I learn Ansible or Terraform first?

For a cloud or DevOps role, learn Terraform first. Provisioning cloud infrastructure as code is the more common requirement on cloud-engineer job specs, and Terraform is the widely-listed tool for it. Add Ansible when you need to configure fleets of servers, work with on-premises or Linux estates, or manage what runs inside machines rather than the machines themselves. If your work is mostly configuring existing servers rather than building cloud infrastructure, that order flips — but for most people entering cloud, Terraform is the higher-priority first learn.

Can Ansible replace Terraform?

Not cleanly, and usually not well. Ansible can provision cloud resources through its modules, and Terraform can run some configuration through provisioners, so each can technically stray into the other's lane. But each is worse at the other's job: Ansible lacks Terraform's state-driven view of infrastructure and its plan-before-apply safety, and Terraform is clumsy at the in-place, step-by-step configuration Ansible does naturally. Using one to replace the other tends to fight the tool. Most teams use each for what it is good at.

Do Ansible and Terraform work together?

Yes — that is the most common professional pattern, not the exception. Terraform provisions the infrastructure (the virtual machines, the network, the cloud resources) and hands off to Ansible, which configures those machines (installs software, applies settings, deploys the application). One builds the house, the other furnishes it. Learning both and understanding where the handoff sits is a strong signal in an interview, because it shows you know each tool's actual job rather than treating them as interchangeable.

Is Terraform or Ansible better for beginners?

Neither is harder in the abstract; it depends on the problem you want to solve first. If your goal is cloud engineering, start with Terraform, because building cloud infrastructure as code is the core skill those roles hire for and it maps directly to what you will do. If your goal is server administration or automating configuration across many machines, Ansible is the more natural first step and its playbooks read approachably. Pick by the job you are aiming at, not by a vague sense of difficulty.

Keep reading — the DevOps set
Built hands-on in Class 21 (Terraform). Next note: Bicep vs Terraform →