Master agentless automation for configuration management, application deployment, and infrastructure orchestration across any environment.
Ansible is an open-source automation platform that simplifies configuration management, application deployment, and task automation. Using a simple, human-readable language (YAML), Ansible enables you to describe your infrastructure as code and automate complex IT workflows without requiring agents on managed nodes.
Understanding Ansible's architecture and core concepts is essential for effective automation.
Inventories define the hosts and groups that Ansible manages, supporting both static and dynamic inventory sources.
# inventory.yml - Dynamic inventory example
all:
children:
webservers:
hosts:
web1.example.com:
http_port: 80
web2.example.com:
http_port: 8080
vars:
ansible_user: deploy
databases:
hosts:
db1.example.com:
db2.example.com:
vars:
ansible_user: dbadmin
production:
children:
webservers:
databases:
Playbooks are Ansible's configuration, deployment, and orchestration language, allowing you to describe desired state and automate complex workflows.
# webserver-playbook.yml
---
- name: Configure web servers
hosts: webservers
become: yes
vars:
http_port: 80
app_name: myapp
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
update_cache: yes
notify: Restart Nginx
- name: Copy Nginx configuration
template:
src: templates/nginx.conf.j2
dest: /etc/nginx/sites-available/{{ app_name }}
owner: root
group: root
mode: '0644'
notify: Restart Nginx
- name: Enable site configuration
file:
src: /etc/nginx/sites-available/{{ app_name }}
dest: /etc/nginx/sites-enabled/{{ app_name }}
state: link
notify: Restart Nginx
- name: Ensure Nginx is running
service:
name: nginx
state: started
enabled: yes
handlers:
- name: Restart Nginx
service:
name: nginx
state: restarted
Roles provide a way to organize playbooks into reusable components with a standardized file structure.
# Role directory structure
roles/
└── webserver/
├── tasks/
│ ├── main.yml
│ ├── install.yml
│ └── configure.yml
├── handlers/
│ └── main.yml
├── templates/
│ └── nginx.conf.j2
├── files/
│ └── index.html
├── vars/
│ └── main.yml
├── defaults/
│ └── main.yml
└── meta/
└── main.yml
Variables and Jinja2 templates enable dynamic and flexible automation across different environments.
Ansible Vault provides encryption for sensitive data like passwords, keys, and credentials within your automation code.
AWX (open-source) and Ansible Tower (enterprise) provide web-based UI, REST API, and enterprise features for Ansible automation.
Follow these best practices for maintainable and scalable Ansible automation.