Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard/prefered method for debug logging in a custom Ansible module.

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.

like image 505
justinrknowles Avatar asked Oct 19 '25 12:10

justinrknowles


1 Answers

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

like image 167
udondan Avatar answered Oct 21 '25 03:10

udondan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!