Ansible Debug Module with Examples

0 Comment

Ansible Debug Module with Examples

Ansible debug module is used to print the message in the log output. The message is nothing but any variable values or output of any task. In the following examples I will show how to use debug module to print variable values, and print variables values with by adding some extra strings and printing variable with stdout.

Syntax1: Printing Variable Value

To print any variable value we use this syntax.

Syntax 2:  Printing Variable Value With Adding Some Extra Message

Here you can see I added “HI This Is ”  so to add any extra strings or message to variables you have to use the above syntax.

Ansible Debug Msg With Examples:

playbook:

Here I used the register module to capture the output of echo command. So the output of echo command will be stored in variable “abcd”. To print this variable value we use the debug module. We can use the debug module in two ways. One is directly print the variable with var tag and Second one print the variable with adding some extra strings or massage for this we use msg tag.

Output Log:

 

you can put any variables in debug module like defined by you or you can use ansible defined variables.

defined by you is like {{ abcd }} in the previous example.

ansible defined variable like any variable in gather facts.

Debug Module with Gather Facts

In the following example, I will print the IP address of my target machine. Here my target machine is localhost. So it will print my system IP address.

Output Log:

 

 

  • ansible debug msg
  • ansible debug module
  • ansible debug msg stdout
  • ansible debug msg example
  • ansible debug module example
  • ansible debug module command line
[top]

Leave a Reply

Your email address will not be published. Required fields are marked *