Skip to content

Ansible Labs



Intro

  • This tutorial is for teaching Ansible through hands-on labs designed as practical exercises.
  • Each lab is packaged in its own folder and includes the files, playbooks, and assets required to complete the lab.
  • Every lab folder includes a README that describes the lab’s objectives, tasks, and how to verify the solution.
  • The Ansible Labs are a series of Ansible automation exercises designed to teach players Ansible skills & features.
  • The inspiration for this project is to provide practical learning experiences for Ansible.

Pre-Requirements

  • This tutorial will test your Ansible and Linux skills.
  • You should be familiar with the following topics:
  • Basic Linux commands
  • Linux File system navigation
  • Basic knowledge of Docker (if you choose to run it with Docker)
  • Basic knowledge of YAML
  • For advanced Labs:
  • Ansible basics (inventory, playbooks, modules)

Usage

  • There are several ways to run the AnsibleLabs Labs.
  • Choose the method that works best for you.

Using Docker is the easiest way to get started locally with the labs:

# GitHub Container Registry
docker run -it --pull=always -p 3000:3000 ghcr.io/nirgeier/ansiblelabs

Prerequisites:

  • Docker and Docker Compose installed on your system
  • No additional setup required
  • The easiest way to get started with the labs
  • Learn in your browser without any local installation

๐ŸŒ Launch on Killercoda

Benefits:

  • No installation required
  • Pre-configured environment
  • Works on any device with a web browser
  • All tools pre-installed

For those who prefer to run it directly on their machine:

# Clone the repository
git clone https://github.com/nirgeier/AnsibleLabs
# Change to the Labs directory
cd AnsibleLabs/Labs
# Start with the setup lab
cd 000-setup
# Follow the instructions in the README of each lab
cat README.md

Prerequisites:

  • A Unix-like operating system (Linux, macOS, or Windows with WSL)
  • Basic command-line tools
  • Google Cloud Shell provides a free, browser-based environment with all necessary tools pre-installed.
  • Click on the Open in Google Cloud Shell button below:

Open in Cloud Shell

  • The repository will automatically be cloned into a free Cloud instance.
  • Use CTRL + click to open it in a new window.
  • Follow the instructions in the README of each lab.

Benefits:

  • No local installation required
  • Pre-configured environment
  • Works on any device with a web browser
  • All tools pre-installed
  • Free tier available

  • Ensure you have the necessary permissions to run Docker commands or Ansible playbooks on your system.
  • Enjoy, and don’t forget to star the project on GitHub!

Preface

What is Ansible?

  • Ansible is an open-source automation tool for IT tasks such as configuration management, application deployment, and task automation.
  • Ansible is Configuration Management tool which manage the state of our servers, install the required packages and tools.
  • Other optional use cases can be deployments, Provisioning new servers
  • The most powerful feature of Ansible is the ability to manage huge scale of servers regardless of their infrastructure (on prem, cloud, vm etc)
  • Ansible uses SSH to connect to servers and execute tasks defined in YAML playbooks, making it agentless and easy to use.
  • Ansible is widely used for managing infrastructure, ensuring consistency, and automating repetitive processes across various environments (on-premises, cloud, VMs, etc.).

How Ansible Works

Ansible Architecture Diagram

  • Ansible is an agentless tool.
  • Ansible uses ssh for pulling modules and for managing the nodes
  • Ansible is based upon YAML
  • An Ansible playbook is a file that contains a set of instructions that Ansible can use to automate tasks on remote hosts.
  • Playbooks are written in YAML, a human-readable markup language. A playbook typically consists of one or more plays, a collection of tasks run in sequence.

How Ansible Playbooks Work

  • Hereโ€™s a brief overview of how Ansible playbooks work:
  • Playbook Structure

    • A playbook is composed of one or more plays in an ordered list.
    • Each play executes part of the overall goal of the playbook, running one or more tasks.
    • Each task calls an Ansible module.
  • Playbook Execution

    • A playbook runs in order from top to bottom.

    • Within each play, tasks also run in order from top to bottom.

    • Playbooks with multiple plays can orchestrate multi-machine deployments.

  • Task Execution

    • Tasks are executed by modules, each of which performs a specific task in a playbook.

    • There are thousands of Ansible modules that perform all kinds of IT tasks.

  • Reusability

    • Playbooks offer a repeatable, reusable, simple configuration management and multi-machine deployment system.

    • If you need to execute a task with Ansible more than once, write a playbook and put it under source control.

  • Playbooks are one of the core features of Ansible and tell Ansible what to execute.
  • They are used in complex scenarios.
  • They serve as frameworks of pre-written code that developers can use ad-hoc or as a starting template.
  • They can be saved, shared, or reused indefinitely, making it easier for IT teams to codify operational knowledge and ensure that the same actions are performed consistently.