How do i send data to the callback

57 views
Skip to first unread message

Ritesh Shetty

unread,
Nov 26, 2014, 3:33:37 PM11/26/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Dec 1, 2014, 4:06:24 PM12/1/14
to ansible...@googlegroups.com
Hi Ritesh,

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

Thanks!



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a6455abe-5c2e-42ba-919a-d7a99b1181b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages