๐Ÿš€ Nkechi Ahanonye โ€” Cloud & DevOps Engineer | I turn manual, 3 AM-breaking deployments into 1-min automated pipelines with AWS + Ansible + Terraform
๐Ÿ“ฆ Live: ansible_practical โ€“ 17 Green Runs โœ… | ๐Ÿ“– 15-Module Guide | ๐Ÿงช You are here (Lab) | ๐Ÿ’ผ LinkedIn
Free Ansible Student Lab โ€” Open Source

Master Ansible.
Automate Everything.

A complete, hands-on Ansible lab guide for DevOps students. Learn infrastructure automation from zero to production-ready โ€” with real exercises, code examples, and best practices.

Start Learning โ†’ GitHub Repo
5
Core Modules
4
Hands-on Labs
3
Ansible Roles
100%
Free & Open Source

What You'll Learn

A structured learning path from Ansible fundamentals to production-grade infrastructure automation.

Module 01
Ansible Fundamentals
Understand the control node, managed nodes, SSH authentication, and the agentless architecture that makes Ansible unique.
Control NodeSSHInventory
Module 02
Playbooks & Variables
Write declarative YAML playbooks, use Jinja2 templating for dynamic values, and manage variables across playbooks, files, and inventory.
YAMLJinja2Variables
Module 03
Roles & Project Structure
Organise playbooks into reusable roles with dedicated tasks, handlers, templates, and variable directories following best practices.
RolesHandlersTemplates
Module 04
Ansible Vault & Security
Encrypt sensitive credentials using Ansible Vault with AES-256. Learn the golden rule: never commit plain text passwords to version control.
VaultAES-256Security
Module 05
Galaxy & Dynamic Inventory
Leverage Ansible Galaxy for community roles and configure dynamic inventory for cloud environments where servers scale automatically.
GalaxyAWSDynamic Inventory
Bonus
Idempotency Deep Dive
Understand why "desired state" thinking is the superpower that separates Ansible from bash scripts. Run playbooks 100 times safely.
IdempotencyBest Practices

Real-World Exercises

Work through these lab exercises in GitHub Codespaces or any Linux environment. Each lab builds on the last.

๐Ÿ–ฅ
Lab 1 โ€” Your First Playbook
Install and manage Nginx on a local host
Beginner
Objective: Write a playbook that installs Nginx, ensures it's running, and demonstrates idempotency by running it twice.
yaml
---
- name: Install and start Nginx
  hosts: localhost
  become: yes
  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
    - name: Start nginx service
      service:
        name: nginx
        state: started
        enabled: yes
Steps
1
Create a file called webserver.yml and paste the playbook above
2
Run: ansible-playbook webserver.yml โ€” note changed=1
3
Run it again โ€” what does changed=0 tell you? That's idempotency!
๐Ÿ“
Lab 2 โ€” Multi-Role Project
Build a webserver + mysql + app role structure
Intermediate
Objective: Create a full project with three separate roles โ€” webserver (Nginx), mysql (database), and app (deployment) โ€” each with its own tasks directory.
bash
# Create the role structure
mkdir -p roles/{webserver,mysql,app}/tasks
mkdir -p roles/mysql/vars

# Create the main playbook
touch playbook.yml inventory.ini

# Verify structure
tree roles/
Steps
1
Create the directory structure using the commands above
2
Write tasks in each role's main.yml
3
Reference all three roles in your playbook.yml
4
Run the playbook and verify all tasks complete successfully
๐Ÿ”
Lab 3 โ€” Ansible Vault
Encrypt database credentials with AES-256
Intermediate
Objective: Create a secrets file with database credentials, encrypt it with Ansible Vault, and configure your MySQL role to load it securely using include_vars.
bash
# Create secrets file
cat > roles/mysql/vars/secrets.yml << EOF
db_name: appdb
db_user: appuser
db_password: SuperSecret123!
EOF

# Encrypt it
ansible-vault encrypt roles/mysql/vars/secrets.yml

# Run playbook with vault
ansible-playbook -i inventory.ini playbook.yml \
  --ask-vault-pass
Steps
1
Create secrets.yml with plain text credentials
2
Run ansible-vault encrypt on the file
3
Add include_vars: vars/secrets.yml to your MySQL tasks
4
Run with --ask-vault-pass and confirm it works
๐ŸŒ
Lab 4 โ€” Ansible Galaxy
Use community roles for production-grade setup
Advanced
Objective: Create a requirements.yml file, install a Galaxy role from Jeff Geerling, and use it in your playbook instead of your custom Nginx role.
yaml
# requirements.yml
roles:
  - name: geerlingguy.nginx
  - name: geerlingguy.mysql
bash
# Install all roles at once
ansible-galaxy install -r requirements.yml
Steps
1
Create requirements.yml with the roles above
2
Install with ansible-galaxy install -r requirements.yml
3
Update your playbook to reference the Galaxy roles
4
Compare the Galaxy role with your custom one โ€” what extra features does it have?

Quick Reference

The most important Ansible commands you'll use every day.

โ–ถ Running Playbooks
ansible-playbook playbook.yml
Run a playbook against inventory
ansible-playbook playbook.yml --check
Dry run โ€” no changes made
ansible-playbook playbook.yml -v
Verbose output for debugging
ansible-playbook playbook.yml --ask-vault-pass
Run with encrypted vault files
๐Ÿ” Ansible Vault
ansible-vault encrypt file.yml
Encrypt a file
ansible-vault decrypt file.yml
Decrypt a file (use carefully!)
ansible-vault edit file.yml
Edit an encrypted file safely
ansible-vault view file.yml
View encrypted content
๐ŸŒ Ansible Galaxy
ansible-galaxy install role.name
Install a single role
ansible-galaxy install -r requirements.yml
Install all roles from file
ansible-galaxy list
List installed roles
ansible-galaxy init my_role
Scaffold a new role structure
๐Ÿ—ƒ Inventory & Hosts
ansible all -i inventory.ini -m ping
Ping all hosts
ansible-inventory --list
List all inventory hosts
ansible webservers -m command -a "uptime"
Run ad-hoc command on group
ansible all -m setup
Gather facts from all hosts

Core Concepts Explained

๐Ÿ”„
Idempotency
Running the same playbook multiple times produces the same result. Ansible checks "what should the state be?" not "what should I do?" โ€” changed=0 is the goal.
๐Ÿ“ฆ
Roles
Reusable units of automation. Each role owns a specific part of your infrastructure โ€” webserver, database, app โ€” with its own tasks, vars, handlers and templates.
๐Ÿ—‚
Inventory
The list of servers Ansible manages. Can be static (.ini files) for fixed infrastructure or dynamic (cloud APIs) for auto-scaling environments.
๐Ÿ“
Playbooks
YAML files that declare the desired state of your infrastructure. They define which tasks run on which hosts โ€” the heart of all Ansible automation.
๐Ÿ””
Handlers
Tasks that only run when notified by another task. Perfect for restarting services only when a config file actually changed โ€” not on every run.
๐Ÿ”
Ansible Vault
AES-256 encryption for sensitive data. Passwords, API keys, and tokens are encrypted at rest โ€” the golden rule: never commit plain text secrets to Git.
๐ŸŒ
Ansible Galaxy
The public marketplace for Ansible roles. Like npm for Node.js โ€” download battle-tested roles for Nginx, MySQL, Docker instead of writing them from scratch.
โš™
Modules
The building blocks of Ansible tasks. apt, yum, service, copy, file, template โ€” each module handles one specific operation on the managed node.

Meet Your Teacher

N
Nkechi Anna Ahanonye
Cloud & DevOps Engineer | I turn manual, 3 AM-breaking deployments into 1-min automated pipelines
DevOps practitioner passionate about infrastructure automation and making complex engineering concepts accessible to everyone. Completed a full Ansible Masterclass covering playbooks, roles, vault, galaxy, and dynamic inventory โ€” and now teaching the next generation of DevOps engineers across Africa.