Ansible for Beginners: Complete Getting Started Guide (2026)
By Luca Berton · Published 2024-01-01 · Category: installation
Complete beginner's guide to Ansible. Learn installation, inventory, playbooks, modules, roles, and automation basics with step-by-step examples.

Ansible for Beginners: Your Complete Guide
Ansible is the most popular open-source automation tool in the world. If you're new to Ansible, this guide will take you from zero to writing your first playbooks.
I'm Luca Berton, and I've helped thousands of engineers learn Ansible through AnsiblePilot. Let me guide you through everything you need to get started.
See also: Configuring Ansible for VMware: Complete Setup Guide & Playbook
What Is Ansible?
Ansible is an open-source IT automation engine that automates: • Configuration management — Keep servers in a desired state • Application deployment — Deploy apps consistently • Cloud provisioning — Create cloud resources • Orchestration — Coordinate multi-tier deployments
Why Choose Ansible?
Agentless — No software to install on managed nodes (uses SSH) Simple YAML syntax — Human-readable, no programming required Idempotent — Run playbooks multiple times safely Extensible — 30,000+ modules in Ansible Galaxy Free and open source — Backed by Red HatHow Ansible Works
┌─────────────┐ SSH ┌──────────────┐
│ Control │────────────▶│ Managed │
│ Node │ │ Node 1 │
│ (Ansible) │────────────▶│ Managed │
│ │ │ Node 2 │
└─────────────┘ └──────────────┘
Ansible runs on a control node (your workstation or a dedicated server) and connects to managed nodes via SSH. No agents needed.
See also: Ansible for Windows: Complete Guide to Windows Automation (2026)
Installing Ansible
On Ubuntu/Debian
sudo apt update
sudo apt install ansible -y
ansible --version
On RHEL/CentOS/Fedora
sudo dnf install ansible-core -y
ansible --version
Using pip (any OS)
pip3 install ansible
ansible --version
Key Concepts
Inventory
An inventory defines your target hosts:# inventory.ini
[webservers]
web1.example.com
web2.example.com
[databases]
db1.example.com
Modules
Modules are the units of work. Common modules: •ansible.builtin.apt — Manage apt packages
• ansible.builtin.copy — Copy files
• ansible.builtin.service — Manage services
• ansible.builtin.file — Manage files/directories
• ansible.builtin.template — Deploy Jinja2 templates
• ansible.builtin.user — Manage users
Playbooks
Playbooks are YAML files containing tasks:---
- name: Configure web servers
hosts: webservers
become: true
tasks:
- name: Install nginx
ansible.builtin.apt:
name: nginx
state: present
Roles
Roles organize playbooks into reusable components with a standard directory structure.See also: The Ultimate Automation Guide Books to Master Ansible
Your First Playbook
Create an inventory file:# inventory.ini
[local]
localhost ansible_connection=local
Create your playbook:
# first-playbook.yml
---
- name: My first playbook
hosts: local
tasks:
- name: Print a message
ansible.builtin.debug:
msg: "Hello from Ansible!"
- name: Gather system info
ansible.builtin.debug:
msg: "Running on {{ ansible_distribution }} {{ ansible_distribution_version }}"
Run it:
ansible-playbook -i inventory.ini first-playbook.yml
Ansible vs Other Tools
| Feature | Ansible | Terraform | Puppet | Chef | |---------|---------|-----------|--------|------| | Language | YAML | HCL | Puppet DSL | Ruby | | Agent | No | No | Yes | Yes | | Focus | Config mgmt | Infrastructure | Config mgmt | Config mgmt | | Learning curve | Low | Medium | High | High |
Next Steps
Once you're comfortable with the basics: Learn about Ansible roles for reusable automation Explore Ansible Vault for managing secrets Try Ansible Galaxy for community roles Practice with real-world playbook examples
FAQ
Is Ansible free?
Yes. Ansible (ansible-core) is free and open source. Red Hat offers a commercial product called Ansible Automation Platform for enterprise features.Do I need to know Python to use Ansible?
No. Ansible playbooks use YAML syntax. Python knowledge helps for writing custom modules but is not required for daily use.What is the difference between Ansible and Ansible Automation Platform?
Ansible is the free open-source CLI tool. Ansible Automation Platform (AAP) is Red Hat's enterprise product that adds a web UI, RBAC, analytics, and support.How does Ansible connect to remote hosts?
Ansible uses SSH for Linux/Unix hosts and WinRM for Windows hosts. No agent installation is needed on managed nodes.Conclusion
Ansible's simplicity is its greatest strength. You can start automating in minutes with just YAML knowledge and SSH access. Begin with the examples above and gradually explore more advanced features.
Visit AnsiblePilot for 800+ free tutorials covering every Ansible topic.
What is Ansible?
Ansible is an agentless automation tool that configures servers, deploys applications, and orchestrates workflows using simple YAML files called playbooks.
Install Ansible
# Ubuntu/Debian
sudo apt update && sudo apt install -y ansible
# macOS
brew install ansible
# pip (any OS)
pip install ansible
Your First Command
# Ping localhost
ansible localhost -m ping
# Run command on remote host
ansible all -i "192.168.1.10," -m command -a "uptime" -u deploy
Inventory (Define Your Hosts)
# inventory.yml
webservers:
hosts:
web1:
ansible_host: 192.168.1.10
web2:
ansible_host: 192.168.1.11
dbservers:
hosts:
db1:
ansible_host: 192.168.1.20
all:
vars:
ansible_user: deploy
ansible_python_interpreter: /usr/bin/python3
Your First Playbook
# site.yml
---
- name: Configure web servers
hosts: webservers
become: true
tasks:
- name: Install nginx
ansible.builtin.apt:
name: nginx
state: present
update_cache: true
- name: Start nginx
ansible.builtin.service:
name: nginx
state: started
enabled: true
- name: Deploy index page
ansible.builtin.copy:
content: "<h1>Hello from {{ inventory_hostname }}</h1>"
dest: /var/www/html/index.html
ansible-playbook -i inventory.yml site.yml
Key Concepts
| Concept | Description | |---------|-------------| | Inventory | List of managed hosts | | Playbook | YAML file with automation tasks | | Task | Single action (install, copy, restart) | | Module | Built-in function (apt, copy, service) | | Role | Reusable bundle of tasks/files/templates | | Handler | Task triggered by changes (restart on config change) | | Facts | Auto-gathered system info (OS, IP, CPU) | | Variable | Dynamic values for templates and logic |
Variables and Templates
# group_vars/webservers.yml
http_port: 80
app_name: myapp
{# templates/nginx.conf.j2 #}
server {
listen {{ http_port }};
server_name {{ inventory_hostname }};
}
- template:
src: nginx.conf.j2
dest: /etc/nginx/sites-available/default
notify: restart nginx
Handlers
handlers:
- name: restart nginx
service: name=nginx state=restarted
Conditionals and Loops
# Conditional
- apt: name=nginx
when: ansible_os_family == "Debian"
# Loop
- user:
name: "{{ item }}"
state: present
loop: [alice, bob, charlie]
Project Structure
my-project/
inventory.yml
site.yml
group_vars/
webservers.yml
host_vars/
web1.yml
roles/
nginx/
tasks/main.yml
templates/nginx.conf.j2
handlers/main.yml
defaults/main.yml
FAQ
Do I need to install anything on managed hosts?
Just Python 3 and SSH access. Ansible is agentless — nothing to install on remote hosts.
YAML vs INI inventory?
Both work. YAML is recommended for complex setups with groups and variables.
What's the difference between command and shell?
command runs without a shell (safer). shell supports pipes, redirects, and environment variables.
Where do I go from here?
Learn roles for reusable automation Explore Ansible Galaxy for community roles Try Ansible Vault for secrets management Set up AWX for a web UIWhat is Ansible?
Ansible is an open-source automation tool that manages servers, deploys applications, and orchestrates workflows — all using simple YAML files over SSH. No agents to install.
Install Ansible
# Ubuntu/Debian
sudo apt update && sudo apt install ansible -y
# RHEL/CentOS/Fedora
sudo dnf install ansible -y
# pip (any OS)
pip install ansible
# Verify
ansible --version
Your First Command
# Ping a server
ansible all -i "web1.example.com," -m ping
# Run a command
ansible all -i "web1.example.com," -m command -a "uptime"
Create an Inventory
# inventory.ini
[webservers]
web1 ansible_host=10.0.1.10
web2 ansible_host=10.0.1.11
[dbservers]
db1 ansible_host=10.0.2.10
[all:vars]
ansible_user=deploy
ansible_python_interpreter=/usr/bin/python3
Your First Playbook
# site.yml
---
- hosts: webservers
become: true
tasks:
- name: Install nginx
apt:
name: nginx
state: present
update_cache: true
- name: Start nginx
service:
name: nginx
state: started
enabled: true
- name: Deploy index page
copy:
content: "<h1>Hello from {{ inventory_hostname }}</h1>"
dest: /var/www/html/index.html
ansible-playbook -i inventory.ini site.yml
Key Concepts
| Concept | What It Is | |---------|-----------| | Inventory | List of servers to manage | | Playbook | YAML file with automation tasks | | Task | Single action (install, copy, restart) | | Module | Code that performs a task (apt, copy, service) | | Role | Reusable bundle of tasks, files, templates | | Handler | Task that runs only when notified | | Facts | System info gathered from hosts | | Variable | Dynamic values in playbooks |
Variables
- hosts: webservers
vars:
app_port: 8080
app_name: myapp
tasks:
- debug:
msg: "{{ app_name }} on port {{ app_port }}"
Conditionals
- apt: { name: nginx }
when: ansible_os_family == "Debian"
- yum: { name: nginx }
when: ansible_os_family == "RedHat"
Loops
- apt:
name: "{{ item }}"
state: present
loop:
- nginx
- redis-server
- postgresql
Handlers
tasks:
- template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: restart nginx
handlers:
- name: restart nginx
service: { name: nginx, state: restarted }
Project Structure
my-project/
├── inventory.ini
├── site.yml
├── group_vars/
│ └── webservers.yml
├── roles/
│ └── webserver/
│ ├── tasks/main.yml
│ ├── templates/
│ ├── handlers/main.yml
│ └── defaults/main.yml
FAQ
Do I need to install agents on servers?
No — Ansible is agentless. It connects via SSH (Linux) or WinRM (Windows).
What's the difference between Ansible and Ansible Core?
ansible-core is the minimal engine. ansible is the full package including community collections.
Where to learn more?
Start with the official documentation, practice with simple playbooks, and explore Ansible Galaxy for community roles.
Related Articles
• using Ansible Galaxy for collections • rendering files with Ansible template • configuring Windows services via Ansible • secrets management with Ansible Vault • become_user and become_method in Ansible • Getting Started with Ansible: First Playbook in 10 Minutes • Ansible Cheat Sheet: Quick Reference • Top 50 Ansible Interview Questions (2026) • Mastering Conditionals in Ansible Playbooks • Ansible extra-vars: Pass Variables from CLI • Common Interview Questions and Troubleshooting Tips • Mastering RHCE: Guide to EX294 ExamSee also
• Learn Ansible: Complete Beginner to Advanced Roadmap (2026)Category: installation