0/1 Lessons

Course Introduction

• 19min

0 / 2 lessons complete

IT Lab Setup

• 31min

0 / 3 lessons complete

Installing Ansible

• 57min

0 / 4 lessons complete

Managing your Ansible Inventory

• 2hr 45min

0 / 8 lessons complete

Ansible Basics

• 2hr 54min

0 / 9 lessons complete

Ansible Roles

• 2hr 38min

0 / 8 lessons complete

Ansible Galaxy

• 2hr 28min

0 / 6 lessons complete

Ansible Facts, Variables, Passwords and Templates

• 3hr 20min

0 / 9 lessons complete

Advanced Ansible Playbook Creation

• 2hr 23min

0 / 8 lessons complete

Course Conclusion

• 11min

0 / 1 lessons complete

Ansible Debug Messages


Q&A (0)

Notes (0)

Resources (0)

Saving Progress...


There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, you'll learn about Ansible's Debug Module, a powerful tool for displaying debug messages and gathering information while executing playbooks.

By the end of this lesson, you will understand how to use the debug module in Ansible, view its help documentation, and implement it in your playbooks to display custom messages and gather variable information.

Understanding Debug Messages in Ansible

Debug messages in Ansible are a way to output custom messages or variable values during the execution of a playbook. They are instrumental in troubleshooting and verifying the data being passed through your playbooks. The Debug Module is the primary means of accomplishing this in Ansible.

For example, here is a task that displays a custom message:

TASK [Display a Custom Debug Message] *****************************************************************************
ok: [managed-node-1] => {
    "msg": "This is a test debug message."
ok: [managed-node-2] => {
    "msg": "This is a test debug message."
ok: [ansible-controller] => {
    "msg": "This is a test debug message."

Viewing Help for the Debug Module

Before we dive into writing our playbook, it's beneficial to know how to access the help documentation for the debug module. This can be done using the ansible-doc command, which provides detailed information about modules, including usage, parameters, and examples. To view the help for the debug module, execute the following command:

ansible-doc debug

This command will display comprehensive information about the debug module, which will help you understand its capabilities and how to use it effectively.

Creating a New Playbook

Let's create a new playbook named debug_messages_test.yml. This playbook will include tasks that utilize the debug module. Start by creating the file using your favorite text editor, for instance:

nano debug_messages_test.yml

Now, add the following content to your playbook:

- name: Debug Messages Test
  hosts: all
    - name: Display a Custom Debug Message
        msg: "This is a test debug message."

    - name: Display a Variable Value
        var: ansible_facts.hostname

    - name: Display Environment Variables
        var: ansible_facts.env

In the playbook above, the first task displays a custom message, while the second task shows the value of the ansible_facts.hostname variable, which contains the hostname of the managed node. The final task will output all the environment variables present on the managed node, which can be incredibly useful for troubleshooting and understanding the node's environment.

If you wanted to take a look at all ansible facts, you could debug message all the host facts with a task like so:

    - name: Display all host facts
        var: ansible_facts

Executing the Playbook

With our debug_messages_test.yml playbook ready, it's time to execute it. Run the following command to apply the playbook to your managed nodes:

ansible-playbook debug_messages_test.yml

This will execute the playbook. You should see output like the following:

Ansible Debug Module
Ansible Debug Module

Ansible will display the debug messages as defined in our tasks. You should see the custom debug message, the hostname of your managed nodes, and a list of environment variables from the nodes. This output confirms that your debug tasks are functioning correctly.


Great job on completing the Ansible Debug Messages lesson! You've learned how to use the debug module to display custom messages and variable values, which is important for troubleshooting and understanding the data flow in your playbooks. See you in the next lesson!

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Notify of
profile avatar
Inline Feedbacks
View all comments