Ansible – Debug Module

Debug module is used to display the message. The debug module works only on the host nodes and not the remote ones.

Syntax, for debug module using msg attribute.

ansible localhost –m debug –a "msg='this is a test message'"

Syntax, for debug module using var attribute. We are using the ansible default variableinventory_hostname” in the below example.

ansible localhost -m debug -a "var=inventory_hostname"

Ansible allows us to join the variable and string in attribute “msg“. We will need to pass the variable name in double braces {{}}.

The same double braces {{}} will be used to display variables under the message “msg” attribute.

Syntax

ansible localhost -m debug -a "msg='you are using hostname '{{inventory_hostname}}"