Skip to content
Latchkey

Ansible vs Terraform: Configuration vs Provisioning

Terraform declaratively provisions and tracks infrastructure with state; Ansible configures and orchestrates existing machines with idempotent tasks.

Terraform is declarative IaC for creating and managing cloud resources with a tracked state file. Ansible is an agentless automation tool that configures servers and orchestrates tasks over SSH using idempotent playbooks. They overlap a little but solve different primary problems - provisioning vs configuration.

AnsibleTerraform
Primary jobConfigure / orchestrateProvision infrastructure
ModelImperative-ish, idempotentDeclarative + state
State trackingNone (push tasks)State file
AgentAgentless (SSH)API-driven
Best forOS/app config, ad hoc tasksCloud resource lifecycle

In CI

Use Terraform to stand up and track cloud resources, and Ansible to configure the machines or run orchestration steps afterward - the two are often used together. If your pipeline only provisions cloud infra, Terraform alone is cleaner. If you mostly configure existing servers or run procedural tasks, Ansible fits better. Both run well in CI as automation steps.

Speed it up

Cache Terraform providers and Ansible collections, and run both in CI. The plan/apply and playbook runs happen on CI runners; faster managed runners shorten them.

The verdict

Provisioning and tracking cloud resources: Terraform. Configuring machines or orchestrating procedural tasks: Ansible. Many teams pair them - Terraform builds it, Ansible configures it.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card