Introduction
Ansible is an open-source, agentless automation tool by Red Hat. It uses simple, human-readable YAML files called playbooks to automate configuration management, application deployment, task automation, and orchestration across many systems.
What You Can Do
- Automate configuration and deployments across many servers.
- Run ad-hoc commands for troubleshooting or on-the-fly fixes.
- Orchestrate complex workflows (deployments, rolling updates).
- Integrate with cloud providers, networking devices, and CI/CD pipelines.
Key Characteristics
- Agentless: No agents required on managed nodes — uses SSH (Linux/UNIX) and WinRM (Windows).
- Declarative Playbooks: Describe the desired state; Ansible figures out the steps.
- Idempotent Modules: Safe to run multiple times.
- Extensible: Custom modules, plugins, and roles allow flexible extension.
Architecture
- Control node: Machine where you run ansible or ansible-playbook (Linux/macOS with Python).
- Managed nodes (hosts): Servers, network devices, or virtual machines.
- Inventory: Lists your managed hosts and groups (INI or YAML).
- Modules: Reusable units for tasks (package, file, service).
- Playbooks & Tasks: Ordered list of plays (target hosts + tasks).
- Connection plugins: Control how Ansible connects (SSH, WinRM, local).
Common Module Categories
- System modules (user, group, package, service)
- File modules (copy, template, file)
- Command modules (command, shell)
- Networking modules (nxos, ios, eos, junos)
- Cloud modules (aws, azure, gcp)
- Application modules (docker, kubernetes)
Quick Commands
Run an ad-hoc command: ansible all -m ping -i inventory Run a playbook: ansible-playbook -i inventory site.yml Check host connectivity: ansible all -m ping -i inventory
Automation Types
- Push: Control node sends instructions to servers (e.g., Ansible, Terraform).
- Pull: Server fetches configs from a central server (e.g., Puppet, Chef).