Skip to content
Tutorials Center
My learning

Topics

Ansible Tutorial

Learn Ansible step by step: 29 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Ansible? Learn what Ansible is, how its agentless push model works over SSH, why idempotence and desired state matter, and when to pick it over shell scripts.
  2. 2 Installing Ansible and Your First Ping Install Ansible with pip, pipx or a package manager, learn ansible-core versus ansible, set up a lab host, and run your first ping against localhost and SSH.
  3. 3 Inventory: Hosts and Groups Learn Ansible inventory files in INI and YAML: groups, children, ranges, host patterns, ansible-inventory, group_vars and host_vars, and dynamic inventory.

Core Concepts

  1. 4 Ad-Hoc Commands Run one-off tasks on many servers with Ansible ad-hoc commands: ping, command, shell, copy, apt and service, plus -b, -l, -i and forks, and when to use them.
  2. 5 Playbooks and YAML Essentials Write your first Ansible playbook: YAML rules and traps, plays, tasks, ansible-playbook, --check and --diff, and how to read the output and the play recap.
  3. 6 Modules and Idempotence Understand why Ansible modules beat shell commands: ok, changed and failed states, command vs shell vs raw, creates and removes, changed_when, failed_when and check mode.

Variables and Logic

  1. 7 Variables, Facts and Precedence Learn how Ansible variables work: vars, group_vars, host_vars, extra vars, gathered facts, set_fact, register, debug and the precedence rules that decide which value wins.
  2. 8 Conditionals and Loops Control which Ansible tasks run with when, repeat tasks over lists with loop, retry with until, and avoid the truthiness and registered-result pitfalls that trip up beginners.
  3. 9 Jinja2 Templates and Filters Use Jinja2 in Ansible: {{ }} expressions, {% %} blocks, filters like default, join, map and selectattr, the template module, lookups, whitespace control and YAML quoting rules.

Structuring Automation

  1. 10 Handlers, Tags and Task Control Run Ansible actions only when something changed with handlers, select tasks with tags, handle failures with block/rescue/always, and control execution with delegate_to, run_once and serial.
  2. 11 Roles and Project Layout Organize Ansible automation with roles: the role directory structure, defaults versus vars, handlers and templates, import_role versus include_role, ansible-galaxy init and a repo layout.
  3. 12 Collections, Galaxy and Reusable Content Understand Ansible collections and fully qualified names (FQCN), install content with ansible-galaxy and requirements.yml, pin versions, and package a minimal role for sharing.

Everyday Modules

  1. 13 Files, Users and Packages Manage files, users and packages with Ansible: copy, template, file, lineinfile, blockinfile, user, group, apt/dnf, get_url, unarchive and authorized_key, with idempotent examples.
  2. 14 Services, Commands and Scheduling Control services with service and systemd, schedule jobs with cron, run commands safely, wait for ports, check health with uri, reboot hosts and restart through handlers.
  3. 15 Windows, Network Devices and Cloud Modules Automate Windows over WinRM or SSH, network devices with network_cli and resource modules, and cloud APIs from localhost. Learn connection types and collections.

Secrets and Security

  1. 16 Ansible Vault and Secrets Keep passwords and keys safe in Ansible: ansible-vault create, encrypt and edit, encrypt_string, vault IDs, password files, no_log, secret lookups and git hygiene.
  2. 17 SSH, Privilege Escalation and Hardening Secure Ansible access: SSH keys and agents, ansible.cfg connection settings, become and become_user, least privilege, host key checking and a server hardening playbook.

Real-World Practice

  1. 18 Testing, Linting and Debugging Test Ansible automation: syntax-check, check and diff mode, ansible-lint, yamllint, Molecule with containers, assert and fail, verbosity levels, the debugger and a CI pipeline.
  2. 19 Performance, Dynamic Inventory and AWX Make Ansible faster and scale it to big fleets: forks, pipelining, strategies, async tasks, fact caching, dynamic inventory plugins, ansible-pull and AWX.
  3. 20 Ansible with Docker, Terraform and CI/CD Combine Ansible with Terraform, Docker and CI pipelines: provision then configure, community.docker modules, idempotent deploys and rolling updates with serial.

Projects

  1. 21 Project: Provision a Web Server Build a complete Ansible playbook that installs nginx, renders a site config from a template, opens the firewall, reloads safely with handlers and verifies the result.
  2. 22 Project: Deploy an Application with Rolling Updates Deploy an application with Ansible using release directories, an atomic symlink swap, a systemd unit template, serial rollout, health checks and automatic rollback.
  3. 23 Project: Security Baseline Role Write a reusable Ansible role that applies a security baseline: SSH settings, admin users and sudoers, unattended upgrades and auditing, with tags, check mode and defaults.
  4. 24 Project: Multi-Tier Stack with Roles and Vault Build a load balancer, app servers and a database with Ansible roles, separate dev and prod inventories, group_vars, Vault secrets, play ordering and delegate_to.
  5. 25 Project: Build a Mini Ansible in JavaScript Build a tiny Ansible in JavaScript: parse an inventory and a playbook, register modules, support check mode, notify handlers and print a play recap. Runs in your browser.

Practice and Review

  1. 26 Exercises with Solutions Practice Ansible with 12 graded exercises on inventory, host patterns, ad-hoc commands, playbooks, templates, handlers, roles, vault and rolling updates, with full solutions.
  2. 27 Common Mistakes and Troubleshooting Fix the Ansible problems everyone hits: YAML indentation and quoting errors, unreachable hosts, become failures, non-idempotent shell tasks, variable precedence surprises.
  3. 28 Interview Questions Prepare for an Ansible interview: concepts, idempotence, roles vs collections, vault, handlers, variable precedence, scenarios and troubleshooting questions with clear answers.
  4. 29 Ansible Cheat Sheet One-page Ansible cheat sheet: CLI flags, inventory patterns, playbook keywords, common modules, Jinja2 filters, project layout, magic variables and ansible-vault commands.