Skip to main content
Welcome to the Ansible Advanced Course. In this lesson, we demonstrate how the Ansible hands-on labs operate on KodeKloud. These labs run directly in your browser and can be accessed repeatedly until you achieve confidence. After each lecture, you are directed to a lab interface that includes both practical tasks and quiz questions.
The image shows a KodeKloud interface with a terminal setting up a test environment and a Katacoda panel connected to port 8080.

Lab Interface Overview

The lab interface is divided into two sections:
  • Left Panel: A terminal connected to an Ansible control node. This live environment allows you to run commands, create files, and experiment freely.
  • Right Panel: A quiz portal that displays questions along with a timer and the total question count. For a larger terminal view, simply click the quiz portal button at the top to open it in a separate window. In this demonstration, we are using the split interface.
In the terminal, you might see an initial output similar to the following:
The quiz portal shows your current question, the total number of questions, and a countdown timer. The lab environment is active for one hour, but you can always reload to restart if necessary.
Each lab typically begins with multiple-choice questions to gauge your existing knowledge, followed by more challenging hands-on tasks. In this demo, we introduce the fundamentals of Ansible Playbooks.

Lab Questions and Tasks

1. Playbook Format Question

The first question asks: In what format are Ansible playbooks typically expressed?
The available choices are Python, Jinja2, YAML, or XML. The correct answer is YAML.

2. Understanding a Playbook

Next, you are asked to define what a playbook is. A playbook is a file containing plays and tasks that specify operations to be executed on managed nodes.

3. Multiple Plays in a Playbook

Another query confirms that a playbook can include multiple plays. For example, a playbook might target different groups of hosts using separate plays. Consider the following example from the file file.yml:
In this playbook, there are two plays—one targeting web1 and another targeting web2.

4. Hands-On Task – Creating a Playbook

Your task is to create a playbook named web1.yml that creates a blank file called myfile.txt in the root home directory on the web1 node. If you need help, click the hint button in the lab interface. A sample playbook might look like this:
After saving the file, execute it using the following command:
To verify the file creation, SSH into the web1 node:
On the web1 node, confirm that /root/myfile.txt now exists. Once you run your playbook, the quiz portal will re-run it after resetting the environment to ensure that your solution is both correct and repeatable.

5. Fixing a Faulty Playbook – httpd.yml

Another lab task involves troubleshooting a playbook named httpd.yml, which initially contains errors. When you open and run this playbook, you might encounter the following error:
The error is caused by using the incorrect attribute host instead of hosts. Correct that mistake (and ensure proper indentation), and the playbook should run successfully. A similar error may occur if the YAML indentation isn’t correct:

6. Important Reminder

Avoid refreshing your browser tab during the lab session. Refreshing will cause the lab environment to expire after one hour. If the quiz portal appears stuck, refresh only that window. Remember, this action will restart the particular lab you are working on.
The image shows a quiz question asking in which format Ansible playbooks are expressed, with options: python, jinja2, yaml, and xml.

Final Steps and Feedback

After completing all tasks and questions, be sure to provide feedback using the designated form. For example, when testing the playbook web2.yml, you might encounter an error like this:
Providing feedback helps us enhance the labs, ensuring you have a comprehensive learning experience. Once completed, you’ll have full access to the entire course along with all labs and practice tests at KodeKloud.

Watch Video

Practice Lab