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. Put raise 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.