Ansible β Configuration Management & Automation
Before you start: basic Linux command-line comfort and a rough understanding of SSH (logging into a remote server) are assumed. No prior automation-tool experience is needed.
Ansible is the most widely used configuration management and automation tool in enterprise DevOps. It is agentless β no software needs to be installed on managed nodes. Everything runs over SSH using Python modules pushed temporarily to the target.
Analogy β Think of Ansible like a substitute teacher who brings their own instructions and leaves nothing behind, versus a full-time teacher who needs a permanent desk in every classroom. Tools that require an agent (Chef, Puppet) are like stationing a full-time teacher (a running background process) in every single classroom (server) permanently. Ansible instead walks into a classroom (SSHs into a server), delivers the lesson (runs a Python module), and leaves β no permanent presence, nothing installed, nothing left running. That's what "agentless" means concretely: the managed node needs nothing but SSH and Python already sitting there, not a dedicated Ansible process running at all times.
What is Ansible?
Ansible is an open-source automation platform that handles:
Why Ansible Over Other Tools?
| Tool | Agent Required | Language | Learning Curve | Best For |
|---|
|------|---------------|----------|----------------|----------|
| **Ansible** | No (agentless) | YAML | Low | General automation, existing infrastructure |
|---|---|---|---|---|
| Chef | Yes (chef-client) | Ruby DSL | High | Large enterprises, complex logic |
| Puppet | Yes (puppet agent) | Puppet DSL | High | Compliance-heavy environments |
| SaltStack | Yes (minion) | YAML/Python | Medium | High-scale, event-driven |
Why Ansible wins for most teams:
Architecture
No daemon on managed nodes. Ansible SSHs in, copies a Python module, executes it, returns result, and cleans up. Completely stateless from the target perspective.
Key Concepts
Inventory β The list of hosts Ansible manages. Can be static (INI/YAML file) or dynamic (AWS, Azure, GCP plugins that query APIs in real time).
Playbook β YAML file containing plays. A play maps hosts to tasks. Tasks call modules. Modules do the actual work.
Module β The unit of work. apt, yum, copy, template, service, shell, aws_ec2, k8s β 5000+ built-in modules.
Role β A reusable, structured way to organize playbooks. Has tasks/, handlers/, vars/, templates/, files/ directories.
Handler β A task that only runs when notified. Classic use: restart nginx only when its config changes.
Vault β Encrypts sensitive data (passwords, API keys) inside YAML files. Decrypted at runtime.
Idempotency β The most important Ansible concept. Running apt: name=nginx state=present 100 times installs nginx once β subsequent runs do nothing because the desired state already exists. This means you can safely run playbooks repeatedly.
Real-World Use Cases
Try It (2 Minutes)
You don't need multiple servers to see idempotency for yourself β a single machine (even your own laptop, if it has SSH enabled locally) demonstrates it:
pip3 install ansible), then run: ansible localhost -m file -a "path=/tmp/demo.txt state=touch". It reports changed: true β the file didn't exist, so Ansible created it.changed: false β Ansible checked, found /tmp/demo.txt already exists in the desired state, and did nothing. That's idempotency: running the same instruction repeatedly is always safe, because Ansible only acts when reality doesn't already match what you asked for.
