1

I am implementing a new module for specific needs in my environment. I would like to print certain outputs (such as some variables) by this module, similar as debug module prints with msg parameter, but in a more customized way.

AnsibleModule class has fail_json() method which accepts msg argument to print on a failure, but I cannot find a way to print a message on success with exit_json()

I also don't know how builtin debug module works, found almost nothing except DOCUMENTATION and EXAMPLES in the module script.

Akif
  • 6,018
  • 3
  • 41
  • 44

1 Answers1

1

Everything you want to be done on Ansible controller is done by action plugins (they are module's companions).

Take a look at some very simple plugin/module here. You want to execute module, inspect it's result for your custom message, use display.v or display.warning or anything else to display this message and then return module's result back to Ansible core.

For this very reason debug is an action plugin, and it's module only contains documentation, because all the work is done by plugin itself.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193