Back to Blog
Tutorial

Ansible Complete Tutorial 2026 - Configuration Management

Firoz Ahmed
Jan 2026
10 min read

Ansible Complete Tutorial 2026: Configuration Management

Imagine you need to install Nginx, create users, copy configuration files, and start services on 200 servers. Doing this manually would take days and be riddled with inconsistencies. Ansible does it in minutes — and it is idempotent, meaning you can run it 10 times and the result is always the same, no duplicate entries or errors.

Ansible's killer feature: it is agentless. Unlike Puppet or Chef, Ansible requires no software on the managed servers — it uses SSH, which is already running everywhere. This makes it far easier to set up and maintain.

Installing Ansible

# On Ubuntu/Debian (control node - your machine)
sudo apt update
sudo apt install -y ansible

# Verify installation
ansible --version

# Or install via pip for the latest version
pip3 install ansible

Inventory: Defining Your Servers

Create an inventory.ini file listing the servers you want to manage:

[webservers]
web1.example.com
web2.example.com
web3.example.com

[databases]
db1.example.com ansible_user=ubuntu
db2.example.com ansible_user=ubuntu

[production:children]
webservers
databases

[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_ssh_private_key_file=~/.ssh/id_rsa

Test connectivity:

ansible all -i inventory.ini -m ping
ansible webservers -i inventory.ini -m command -a "uptime"

Your First Playbook

A playbook is a YAML file that defines what tasks to run on which hosts. Create install-nginx.yml:

---
- name: Install and configure Nginx web servers
  hosts: webservers
  become: true    # run as sudo
  vars:
    nginx_port: 80
    app_user: www-data

  tasks:
    - name: Update apt cache
      apt:
        update_cache: yes
        cache_valid_time: 3600

    - name: Install Nginx
      apt:
        name: nginx
        state: present

    - name: Copy Nginx configuration
      template:
        src: templates/nginx.conf.j2
        dest: /etc/nginx/nginx.conf
        owner: root
        group: root
        mode: '0644'
      notify: Restart Nginx

    - name: Create web root directory
      file:
        path: /var/www/html
        state: directory
        owner: "{{ app_user }}"
        mode: '0755'

    - name: Start and enable Nginx
      systemd:
        name: nginx
        state: started
        enabled: yes

  handlers:
    - name: Restart Nginx
      systemd:
        name: nginx
        state: restarted

Run the playbook:

# Dry run (check mode - no changes made)
ansible-playbook -i inventory.ini install-nginx.yml --check

# Run the playbook
ansible-playbook -i inventory.ini install-nginx.yml

# Run with verbose output
ansible-playbook -i inventory.ini install-nginx.yml -v

Ansible Roles: Organising Large Playbooks

As playbooks grow, roles keep things organised. A role is a directory structure with a standard layout:

roles/
  nginx/
    tasks/
      main.yml         # main task list
    handlers/
      main.yml         # handlers (restart, reload)
    templates/
      nginx.conf.j2    # Jinja2 templates
    files/
      index.html       # static files
    vars/
      main.yml         # role variables
    defaults/
      main.yml         # default values (overridable)
    meta/
      main.yml         # role metadata, dependencies

Create a playbook that uses roles:

---
- name: Configure production web servers
  hosts: webservers
  become: true
  roles:
    - common        # basic setup, security hardening
    - nginx         # web server
    - nodejs        # application runtime
    - monitoring    # node_exporter for Prometheus

Ansible Vault: Managing Secrets

Never store passwords or API keys in plain text. Use Ansible Vault to encrypt sensitive data:

# Create an encrypted variables file
ansible-vault create secrets.yml

# Edit an encrypted file
ansible-vault edit secrets.yml

# Encrypt an existing file
ansible-vault encrypt vars/database.yml

# Run playbook with vault password
ansible-playbook site.yml --ask-vault-pass

# Or use a vault password file (for CI/CD)
ansible-playbook site.yml --vault-password-file .vault_pass

Your secrets.yml might look like:

db_password: "super_secret_password_123"
api_key: "sk-abc123xyz789"
ssl_cert_passphrase: "cert_pass_456"

Useful Ansible Modules

Module Purpose Example
apt / yum Package management Install Docker, Nginx
copy / template File management Deploy config files
systemd / service Service management Start/stop/enable services
user / group User management Create app users
docker_container Manage Docker containers Deploy containerised apps
aws_ec2 / aws_s3 AWS resource management Provision cloud resources

Ansible is a practical, high-value skill for any DevOps engineer. Our training program includes real Ansible labs where you configure multi-tier application environments, automate server hardening, and integrate Ansible into CI/CD pipelines. Explore the curriculum →

Share this article:TwitterLinkedInFacebook

Ready to Start Your DevOps Career?

Join our comprehensive DevOps course and get job-ready in 56 days

Enroll Now - Limited Seats

What Our Students Say

Real stories from real alumni — watch their journey

"मतलब जीरो से एक तरीके से उठाया है। तो हर एक चीज़ के लिए"

I spent over two years leading information security work at Samsung Display in Noida before moving into DevOps. The Kubernetes, Terraform and AWS modules were the ones that mattered most — I now work as a DevOps Engineer at Birlasoft in Noida on CI/CD, cloud infrastructure and automation.

Harshit WadhwaVerify on LinkedIn

Information Security Lead · Samsung Display  ·  Noida, Delhi NCR

Before

Infosec Lead, Samsung Display

Now

DevOps Engineer, Birlasoft

"Best decision I made for my career. The training completely transformed my skills."

Coming from a non-IT background, I was nervous about joining a DevOps course in Bangalore. The small batch of 10 students meant I could ask every question — the trainer explained Docker and CI/CD pipelines from absolute scratch. I am now working as a DevOps Engineer in Whitefield at ₹10.5 LPA.

Deepak

Customer Support · Non-IT  ·  Bangalore

Before

Non-IT Background

Now

DevOps Engineer

₹10.5 LPA

"Shifttotech gave me the confidence and skills to land my dream job in tech."

As a PHP developer for 4 years I was stuck at ₹8 LPA. The Shifttotech DevOps certification course in Bangalore covered Terraform and Kubernetes through real production projects — exactly what MNCs test in interviews. Got an offer from an MNC at Manyata Tech Park at ₹13 LPA — a 62% salary jump in 4 months.

Himani

PHP Developer · 4 yrs  ·  Bangalore

Before

PHP Developer · ₹8 LPA

Now

Cloud DevOps Engineer

₹13 LPA

4.5 on Google · Verified student outcomes

Enroll Now

Check Your Eligibility for 12-18 LPA Jobs

FREE Career Counselling (Takes 30 Seconds)

100+
Placed
₹15L
Avg CTC
₹28L
Highest
100+ Students Placed at Top Companies
Average Salary: ₹12-18 LPA
100% Job Assistance
Weekend Classes - Keep Your Job

Our Students Work At:

TCS
Infosys
Wipro
Accenture
Cognizant
HCL

Complete DevOps & AWS Cloud Certification Training

Docker, Kubernetes, Jenkins, Terraform, Ansible, Git, AWS, CI/CD, Prometheus, Grafana & more

₹35,000
Limited Seats — Batch Capped at 10

Book FREE Demo Class

No Credit Card

Free Counselling

WhatsApp Confirm

Free Curriculum