The Short Answer
Use Terraform to bring infrastructure into existence through a platform's API, and Ansible to log in to the resulting servers and set them up. Terraform answers "which servers, networks, and records should exist?"; Ansible answers "what should be installed and configured on each server?". The tools themselves are introduced in what Terraform is and what Ansible is.
Side by Side
| Terraform | Ansible | |
|---|---|---|
| Main job | Provisioning | Configuration |
| Talks to | Platform APIs | Servers over SSH |
| Language | HCL | YAML |
| Style | End state | Ordered tasks |
| Memory | State file | None |
| Agent | None | None |
| Deletes things | When removed from code | Only when told |
Provisioning vs Configuration
Provisioning means creating the pieces: a virtual server with a given size and image, a private network, a firewall rule at the platform, a DNS record, a storage bucket. Terraform does this through providers that call each platform's API.
Configuration means what happens inside a running server: install Nginx, write its configuration from a template, create users, start services, open ports in the server's own firewall. Ansible does this over SSH with modules for packages, files, services, and much more.
State File vs Ordered Tasks
Terraform keeps a state file that records what it created. On every run it compares your files, the state, and reality, and plans the difference. Remove a resource from your files and Terraform plans to delete it.
Ansible keeps no state. A playbook is a list of tasks run in order, and each module checks the current state before acting, so a second run changes nothing. Remove a task from a playbook and Ansible stops managing that thing; the package it installed stays on the server until you write a task that removes it.
Neither Needs an Agent
Terraform runs on your computer or in a pipeline and talks to APIs. Ansible runs on a control node and connects over SSH. Nothing has to be installed or kept running on the servers apart from SSH and Python for Ansible, and neither tool opens a port: SSH is the only one Ansible uses, so it can stay limited to your own addresses.
How Each Handles Drift
Drift is a difference between the code and reality, often from a change made by hand. terraform plan shows drift in the resources it manages and offers to put them back. Ansible detects drift only in what its tasks cover: running the playbook with --check --diff reports what would change, and a normal run corrects it. Changes outside both tools stay invisible to both.
Using Both Together
- Terraform creates the servers, networks, and DNS records, and outputs the new servers' addresses.
- cloud-init handles first boot: a user, an SSH key, and Python if needed.
- An Ansible inventory built from those outputs lists the servers.
- Ansible configures everything inside them, and keeps them configured on later runs.
Terraform can run scripts on a new server through provisioners, but its own documentation advises exhausting all alternatives before using them. Ansible has modules for cloud APIs, but it does not track what it created the way a state file does. Each tool is best at its own half.
When Ansible Alone Is Enough
With a handful of servers that rarely change, created once in a control panel, Terraform adds a state file to look after and little else. Ansible alone keeps the servers consistent and documented. Bring in Terraform when you create and remove infrastructure often, need identical test and production setups, or manage networks and DNS alongside servers. Set up key login first in either case; see how to generate SSH keys.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations