This article demonstrates the operation of Ansible hands-on labs on KodeKloud, including lab interface, tasks, and quiz questions.
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.
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.
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.
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.
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:
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:
Copy
Ask AI
- name: Create myfile on web1 hosts: web1 tasks: - name: Create myfile.txt in root home directory file: path: /root/myfile.txt state: touch
After saving the file, execute it using the following command:
To verify the file creation, SSH into the web1 node:
Copy
Ask AI
root@ansible-controller ~/playbooks# ssh web1The authenticity of host 'web1 (172.20.1.100)' can't be established.ECDSA key fingerprint is SHA256:uNTmVyWMA6Wxlp4vFGIRAsQeLwcEBO7/ThU7LexNbC.ECDSA key fingerprint is MD5:83:49:cd:9f:e7:e1:c8:73:ef:c0:76:7b:ba:48:d7Are you sure you want to continue connecting (yes/no)? yes
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.
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:
Copy
Ask AI
root@ansible-controller ~/playbooks# vi httpd.ymlroot@ansible-controller ~/playbooks# ansible-playbook -i inventory httpd.ymlERROR! 'host' is not a valid attribute for a PlayThe error appears to have been in '/root/playbooks/httpd.yml': line 2, column 3, but maybe elsewhere in the file depending on the exact syntax problem.The offending line appears to be:---- host: web ^ hereroot@ansible-controller ~/playbooks#
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:
Copy
Ask AI
root@ansible-controller ~/playbooks# vi httpd.ymlroot@ansible-controller ~/playbooks# ansible-playbook -i inventory httpd.ymlERROR! 'host' is not a valid attribute for a PlayThe error appears to have been in '/root/playbooks/httpd.yml': line 2, column 3, but maybe elsewhere in the file depending on the exact syntax problem.The offending line appears to be:---- host: web ^hereroot@ansible-controller ~/playbooks# vi httpd.ymlroot@ansible-controller ~/playbooks#
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.
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:
Copy
Ask AI
root@ansible-controller ~/playbooks# ansible-playbook -i inventory web2.ymlERROR! Syntax Error while loading YAML. did not find expected '---' indicatorThe error appears to be in '/root/playbooks/web2.yml': line 4, column 2, but maybe elsewhere in the file depending on the exact syntax problem.The offending line appears to be: tasks: - name: echo Welcome! ^ here!root@ansible-controller ~/playbooks# vi web2.ymlroot@ansible-controller ~/playbooks#
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.