# How do i send data to the callback

**URL:** <https://forum.ansible.com/t/how-do-i-send-data-to-the-callback/16899>\
**Category:** Ansible Project\
**Created:** [November 26, 2014, 8:33pm UTC](https://forum.ansible.com/t/how-do-i-send-data-to-the-callback/16899 "2014-11-26T20:33:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [November 26, 2014, 8:33pm UTC](https://forum.ansible.com/t/how-do-i-send-data-to-the-callback/16899/1 "2014-11-26T20:33:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 1, 2014, 9:06pm UTC](https://forum.ansible.com/t/how-do-i-send-data-to-the-callback/16899/2 "2014-12-01T21:06:20Z")

</div>

Hi Ritesh,

Sorry for the late response. As this is a development question, can you please post this on ansible-devel?

Thanks!
