Ansible

Ansible automates server configuration and application deployment using declarative YAML playbooks. It's agentless — it connects over SSH and needs nothing installed on the target beyond Python — which makes it easy to adopt across existing fleets.

Where Terraform provisions infrastructure (creates the servers), Ansible configures what's on it (installs packages, writes config, deploys apps). The two are complementary, and Ansible's core virtue is idempotency: running a playbook repeatedly converges to the same desired state without breaking things.

TL;DR

Quick Example

A task uses a module to declare desired state — installed and running — not imperative commands:

Core Concepts

Best Practices

Comparison: Ansible vs Terraform

See Terraform.

Common Mistakes

Non-idempotent shell tasks

Secrets committed to the repo

FAQ

Ansible or Terraform?

They do different jobs and pair well. Terraform provisions infrastructure (declares the servers, networks, and databases you want). Ansible configures systems (installs and sets up software on them). A common pattern is Terraform to create the machines, then Ansible to configure them.

What does "idempotent" mean here?

Running the same playbook multiple times produces the same end state without unintended side effects. Ansible modules check current state and act only if needed — so re-running is safe. Raw shell/command tasks break this unless you guard them.

Why is Ansible agentless an advantage?

You don't install or maintain an agent on every managed host — Ansible connects over SSH and runs modules using the target's Python. That lowers the barrier to adopting it on existing servers and reduces moving parts to keep secure and updated.

How do I manage secrets in Ansible?

Use Ansible Vault to encrypt sensitive variables/files in the repo, or pull secrets at runtime from an external manager (e.g. HashiCorp Vault). Never store credentials in plaintext playbooks or inventories. See Secrets Management.

Related Topics

References