I have an Ansible Custom Module for performing a specific task in my playbook. I want to debug specific variables inside this module.
Is there a way we can print anything inside this custom module? In the example below, print "Hello".
Please check the following snippet from the Custom Module. I am passing a jobid as an argument to this module.
class dcsjob():
def __init__(self, arglist):
self.jobid = self.arglist[0]
def checkandwaitforjob(self):
print("Hello")
def run_module():
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
dcsjobobj = dcsjob([module.params['jobid']])
output = dcsjobobj.checkandwaitforjob()
Given an example module from Developing modules- Creating a module with modification
library/print.pyand called from an example playbook
print.ymlit will result into an output of
printing the
jobid, andHelloonly when inverbosemode.This could also be utilized with
check_modewhich would change the behavior if
--checkis applied or not.Further Documentation
Developing modules- Creating a module
Debugging modules - Simple debugging