I would like to add debug logging to my custom Ansible module such that when the -vvv option is supplied to the ansible-playbook command I see the log messages but otherwise do not. I don't want the results of the module to be affected by this logging. In other words, I don't want to write the log messages to stdout or stderr directly.
Modules normally are executed remotely, so there actually is no way to directly output anything.
You can return additional data in your module in the exit_json
call.
if module._verbosity >= 3:
module.exit_json(changed=True, debug="wooha!")
else:
module.exit_json(changed=True)
module._verbosity
corresponds to the verbosity level (-v = 1, -vvv = 3) and is available since Ansible 2.1.
Source: Ansible Devel-list and github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With