Hi All,
My application trigger the playbook using the python api. Now since there are many tasks and each might take a long time, i need to keep the user informed of what is going on. So i have create a Job and Tasks table and idea is to create the Job before initiating the playbook.run() . Now for me to keep updating the state of the tasks i need to implement the callback plugin and here i can insert the tasks to the database and keep updating the states. Now problem is how do i get the data(my_custom_job_id) i defined in the calling code where i ran playbook.run()
class CallbackModule(object):
“”"
logs playbook results, per host, in /var/log/ansible/hosts
“”"
def init(self):
self.stats = {}
self.task_id = None
def on_any(self, *args, **kwargs):
pass
def runner_on_failed(self, host, res, ignore_errors=False):
if type(self.task_id) is str:
print "Task name "+ self.task.name
print "Task id "+self.task_id
log(host, ‘FAILED’, res)
def runner_on_ok(self, host, res):
if type(self.task_id) is str:
print "Task name "+ self.task.name
print "Task id "+self.task_id
log(host, ‘OK’, res)
def playbook_on_task_start(self, name, is_conditional):
“”"
Logs the start of each task
“”"
HOW DO I GET THE my_custom_job_id WHICH I DEFINED IN MY PYTHON API WHERE TO DID A playbook.run()
jobapi.createjob(my_custom_job_id )
task_id=str(randint(2,9))
jobapi.addTask(my_custom_job_id, task_id,name)
self.task_id = task_id