Ansible Labs¶


Getting Started Tip
Choose the preferred way to run the labs. If you encounter any issues, please contact your instructor.
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
READMEthat 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
AnsibleandLinuxskills. - 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:
Ansiblebasics (inventory,playbooks,modules)
Usage¶
- There are several ways to run the Ansible Labs.
- Choose the method that works best for you.
Killercoda (Recommended)- π³ Docker
- π From Source
Using Google Cloud Shell
- The easiest way to get started with the labs
- Learn Ansible 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
Using Docker is the easiest way to get started locally with the labs:
# Change to the Labs directory
cd Labs/000-setup
# Run the setup lab using Docker Compose
docker-compose up -d
Prerequisites:
- Docker and Docker Compose installed on your system
- No additional setup required
For those who prefer to run it directly on their machine:
# Clone the repository
git clone https://github.com/nirgeier/AnsibleLabs.git
# 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
- Ansible installed on your system
- 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 Shellbutton below:
- 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
Lab Breakdown
- If you choose to run the labs locally using Docker or From Source, follow the steps below to set up your environment.
- Make sure you have the necessary tools installed.
- Follow the instructions in the README of each lab.
- Review the Dockerfile(s) and docker-compose.yml for container configurations.
02. Build From Source¶
- Clone the git repo:
git clone https://github.com/nirgeier/AnsibleLabs.git - Navigate to the Labs directory:
cd AnsibleLabs/Labs/000-setup - The lab contains the
docker-composefile along with the Dockerfile(s) The containers are based upon ubuntu and are published to DockerHub as well. - Build the demo containers
- The docker-compose will create
ansible-controllerwhich will server as our controller to execute ansible playbooks on our demo servers defined by the nameslinux-server-X
Labs containers
| Container | Content |
|---|---|
π³ ansible-controller | Linux container with ansible installed |
π³ linux-server-1 | Linux container with ssh only (no ansible installed) |
π³ linux-server-2 | Linux container with ssh only (no ansible installed) |
π³ linux-server-3 | Linux container with ssh only (no ansible installed) |
- For the demo we will also need a shared folder(s) where the certificates and the configuration will be stored
- The shared folder(s) will be mounted into the containers
- The containers will have access to the shared folder(s) for reading and writing files
- The shared folder(s) will be used to store the Ansible playbooks and inventory files
- The shared folder(s) will be mounted at
/labs-scriptsin the containers
- 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?¶
Ansibleis an open-source automation tool for IT tasks such as configuration management, application deployment, and task automation.AnsibleisConfiguration Managementtool which manage thestateof our servers, install the required packages and tools.- Other optional use cases can be
deployments,Provisioning new servers - The most powerful feature of
Ansibleis the ability to manage huge scale of servers regardless of their infrastructure (on prem, cloud, vm etc) Ansibleuses SSH to connect to servers and execute tasks defined in YAML playbooks, making it agentless and easy to use.Ansibleis widely used for managing infrastructure, ensuring consistency, and automating repetitive processes across various environments (on-premises, cloud, VMs, etc.).
How Ansible Works¶

- Ansible is an
agentless tool. - Ansible uses
sshforpulling modulesand for managing the nodes - Ansible is based upon
YAML - An
Ansible playbookis a file that contains a set of instructions that Ansible can use to automate tasks on remote hosts. Playbooksare written inYAML, a human-readable markup language. A playbook typically consists of one or moreplays, a collection of tasks run in sequence.
How Ansible Playbooks Work¶
- Hereβs a brief overview of how
Ansible playbookswork:
-
Playbook Structure¶
-
A
playbookis composed of one or moreplaysin an ordered list. -
Each
playexecutes part of the overall goal of theplaybook, running one or more tasks. - Each task calls an
Ansiblemodule.
-
-
Playbook Execution¶
-
A
playbookruns in order from top to bottom. -
Within each
play, tasks also run in order from top to bottom. -
Playbooks with multiple
playscan orchestrate multi-machine deployments.
-
-
Task Execution¶
-
Tasksare executed bymodules, each of which performs a specific task in a playbook. -
There are thousands of
Ansible modulesthat perform all kinds of IT tasks.
-
-
Reusability¶
-
Playbooksoffer a repeatable, reusable, simple configuration management and multi-machine deployment system. -
If you need to execute a
taskwithAnsiblemore than once, write aplaybookand 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.
