Terraform on Ubuntu 26.04 LTS - sudo-rs, APT Rollback, and Hardened Base Images
Install and run Terraform on Ubuntu 26.04 LTS Resolute Raccoon. Covers sudo-rs as default, APT 3.2 rollback, Kernel 7.0, Wayland-only, ROCm, and building...
DevOps
Compare Terraform and Ansible for infrastructure automation. Learn when to use each tool, their strengths, and how to combine them for maximum efficiency.
| Criterion | Terraform | Ansible |
|---|---|---|
| Primary purpose | Provision infrastructure | Configure & orchestrate systems |
| Paradigm | Declarative | Procedural (with declarative modules) |
| Language | HCL | YAML |
| State | Stateful | Stateless |
| Best for | Cloud IaC across AWS / Azure / GCP | OS config & app deploys |
Terraform and Ansible are two of the most popular automation tools in the DevOps ecosystem. While they can overlap in functionality, they excel in different areas. Understanding when to use each — and how to combine them — is key to efficient infrastructure management.
| Feature | Terraform | Ansible |
|---|---|---|
| Primary Use | Infrastructure provisioning | Configuration management |
| Language | HCL (HashiCorp Configuration Language) | YAML (Playbooks) |
| Approach | Declarative | Procedural + Declarative |
| State | Maintains state file | Stateless |
| Agent | Agentless | Agentless |
| Idempotency | Built-in | Module-dependent |
Terraform excels at infrastructure provisioning:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = {
Name = "web-server"
}
}Ansible excels at configuration management:
- name: Configure web server
hosts: web_servers
tasks:
- name: Install nginx
apt:
name: nginx
state: present
- name: Start nginx
service:
name: nginx
state: started
enabled: yesThe most powerful approach combines both tools:
# Terraform creates the instance
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
key_name = "deploy-key"
}
# Output IP for Ansible
output "web_ip" {
value = aws_instance.web.public_ip
}# Ansible configures it
- hosts: "{{ web_ip }}"
tasks:
- name: Deploy application
git:
repo: https://github.com/myapp.git
dest: /opt/myappTerraform tracks state — it knows what exists and what changed. Ansible is stateless — it checks current state on each run.
Terraform advantage: Can detect and fix drift automatically. Ansible advantage: No state file to manage or corrupt.
Ansible uses YAML, which most engineers already know. Terraform uses HCL, which requires learning a new syntax.
Terraform has providers for 3000+ services. Ansible has 7000+ modules covering everything from cloud to network devices.
Choose Terraform when:
Choose Ansible when:
Choose both when:
Related: Fix the Terraform inconsistent dependency lock file error — quick fix for this common issue.
Terraform and Ansible are complementary tools, not competitors. Use Terraform for infrastructure provisioning and Ansible for configuration management. Together, they form a powerful automation pipeline.
Install and run Terraform on Ubuntu 26.04 LTS Resolute Raccoon. Covers sudo-rs as default, APT 3.2 rollback, Kernel 7.0, Wayland-only, ROCm, and building...
Set up Terraform CI-CD with GitHub Actions. Covers plan on PR, apply on merge, state locking, secrets management, and environment protection.
Deploy and manage Docker containers with Terraform. Covers the Docker provider, images, containers, networks, and volumes with practical examples.
Import existing cloud resources into Terraform state. Step-by-step guide covering AWS, Azure, and GCP resources with import block syntax.