Ansible Configuration Management¶
Ansible is an agentless automation tool for orchestration, configuration management, provisioning, and deployment. It connects via SSH and describes desired state in YAML playbooks.
Key Advantages¶
- Agentless - no software to install on targets, only SSH access needed
- Declarative - describe desired state, Ansible ensures it
- Idempotent - running multiple times produces same result
- Simple YAML - playbooks are human-readable, version-controllable
- Large ecosystem - Ansible Galaxy for community roles
Architecture¶
Control node pushes "modules" to managed nodes via SSH. Modules execute, report results, and are removed.
Inventory¶
Ad-Hoc Commands¶
Playbooks¶
- hosts: webservers
become: yes
vars:
http_port: 80
tasks:
- name: Install nginx
apt:
name: nginx
state: present
- name: Start nginx
service:
name: nginx
state: started
enabled: yes
handlers:
- name: restart nginx
service:
name: nginx
state: restarted
Roles¶
Reusable automation units with standardized structure:
Structure: defaults/, vars/, tasks/, files/, templates/, meta/
Install from requirements:
Debugging¶
Verbosity levels: -v to -vvvv. Higher = more detail.
Idempotency¶
Modules check current state before changes. shell/command modules need guards (creates, removes, when) to be idempotent.
Gotchas¶
shell/commandmodules are not idempotent by default - usecreates/removesparameters- YAML indentation errors are the most common issue
become: yesneeded for privilege escalation (sudo)
See Also¶
- terraform iac - infrastructure provisioning (complementary)
- sre automation and toil - automation philosophy
- cicd pipelines - Ansible in CI/CD