'Get logs while developing an Ansible Collection
I'm wondering when developing an Ansible Collection, is it possible to get arbitrary logs written to a log file/console?
This being a random print() statement to help debugging, or is the only way just to concatenate your final return message?
Thank you
Solution 1:[1]
Question:
Is it possible to get arbitrary logs written to a log file/console?
Answer:
Your question for me looks similar to Is it possible to print out debugging logs while task is running in Ansible?.
According the answer there citing from documentation
Ansible executes each module, usually on the remote managed node, and collects return values. ... Ansible modules normally return a data structure that can be registered into a variable ...
so such live output is not implemented. There is an option for Debugging modules during development
To see what is actually happening in the module
but that might not fit all of your cases.
Question:
This being a random
print()statement to help debugging
Answer:
According the Developer Guide » Debugging modules » Simple debugging
Since
print()statements do not work inside modules, raising an exception is a good approach if you just want to see some specific data. Putraise Exception(some_value)somewhere in the module and run it normally. Ansible will handle this exception, pass the message back to the control node, and display it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | U880D |
