AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

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: Complete Getting Started Guide (2026)

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?

  1. Agentless — No software to install on managed nodes (uses SSH)
  2. Simple YAML syntax — Human-readable, no programming required
  3. Idempotent — Run playbooks multiple times safely
  4. Extensible — 30,000+ modules in Ansible Galaxy
  5. Free and open source — Backed by Red Hat

How 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.

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

See also: Ansible Playbook Examples: 10 Real-World Playbooks for Beginners

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.

Your First Playbook

  1. Create an inventory file:
# inventory.ini
[local]
localhost ansible_connection=local
  1. 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 }}"
  1. Run it:
ansible-playbook -i inventory.ini first-playbook.yml

See also: Ansible for Windows: Complete Guide to Windows Automation (2026)

Ansible vs Other Tools

FeatureAnsibleTerraformPuppetChef
LanguageYAMLHCLPuppet DSLRuby
AgentNoNoYesYes
FocusConfig mgmtInfrastructureConfig mgmtConfig mgmt
Learning curveLowMediumHighHigh

Next Steps

Once you're comfortable with the basics:

  1. Learn about Ansible roles for reusable automation
  2. Explore Ansible Vault for managing secrets
  3. Try Ansible Galaxy for community roles
  4. 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

ConceptDescription
InventoryList of managed hosts
PlaybookYAML file with automation tasks
TaskSingle action (install, copy, restart)
ModuleBuilt-in function (apt, copy, service)
RoleReusable bundle of tasks/files/templates
HandlerTask triggered by changes (restart on config change)
FactsAuto-gathered system info (OS, IP, CPU)
VariableDynamic 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?

  1. Learn roles for reusable automation
  2. Explore Ansible Galaxy for community roles
  3. Try Ansible Vault for secrets management
  4. Set up AWX for a web UI

What 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

ConceptWhat It Is
InventoryList of servers to manage
PlaybookYAML file with automation tasks
TaskSingle action (install, copy, restart)
ModuleCode that performs a task (apt, copy, service)
RoleReusable bundle of tasks, files, templates
HandlerTask that runs only when notified
FactsSystem info gathered from hosts
VariableDynamic 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.

See also

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home