# on\_task\_stop callback in CallbackBase ?

**URL:** <https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747>\
**Category:** Ansible Developer\
**Created:** [June 16, 2017, 12:46pm UTC](https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747 "2017-06-16T12:46:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rey\_Remi](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@Rey\_Remi](https://forum.ansible.com/u/Rey_Remi)\
**Post date:** [June 16, 2017, 12:46pm UTC](https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747/1 "2017-06-16T12:46:04Z")

</div>

Hi all,

I recently found the strength to start trying to contribute the Ansible project, please excuse my knowledge.

I was looking at the profile\_tasks callback and saw that the time displayed after each tasks is in fact the time spent in the previous one.  
I saw that it comes from the fact that there are not stop callback in the CallbackBase class.

Could someone explain or redirect me to a site/blog/paper explaining why we don’t have any stop callback like v2\_playbook\_on\_task\_stop ?

Thank you very much.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 19, 2017, 10:22am UTC](https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747/2 "2017-06-19T10:22:11Z")

</div>

I don’t know of a site/blog/paper explaining the callback events.

I guess there wasn’t much need for it when callback plugins were created, given that straight after one task has completed the next task will start (usually, possibly not if you are using the debug strategy), until you run out of tasks. So perhaps there was not much need to generate an event for the task stop.

I think the intention of callback plugins was mostly for changing what ansible outputs.

Jon

---

<div class="post-metadata">

**Author:** ![Rey\_Remi](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@Rey\_Remi](https://forum.ansible.com/u/Rey_Remi)\
**Post date:** [June 19, 2017, 11:58am UTC](https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747/3 "2017-06-19T11:58:30Z")

</div>

Hi Jon,

Thanks for the feedback.  
My issue with the current callback is that if you want to publish stats on execution time, you are able to publish something only in the start callback, which is kind of broken because you 'll publish a value which is out of context because you want to publish a task/play duration at the end of it, not at the start of the next one. (because in the next one, the task/play name is not the good one anymore).

Can someone orient me in the code where the callback are fired ? maybe it isn’t difficult to add the stop callbacks ?

Thank you.  
Regards

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 20, 2017, 7:26am UTC](https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747/4 "2017-06-20T07:26:21Z")

</div>

If I recall, the other profiling plugins just capture execution time and then report in the on\_stats event at the end of the playbook run.

I don’t know the code well enough to tell what it would take to add more events, sorry.

Jon

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 20, 2017, 2:24pm UTC](https://forum.ansible.com/t/on-task-stop-callback-in-callbackbase/24747/5 "2017-06-20T14:24:59Z")

</div>

There are existing profile plugins, which just use the task start and  
play stats. This is because the 'stop' cannot really be determined  
with the task as there is no 'hard stop' as we don't keep track of  
draining of hosts for specific tasks.

The iterator just returns task/host tuples. In linear strategy we can  
detect in 'task start event' if the task has changed and that is what  
profilers use to detect the 'previous task end', with play stats being  
the place where the 'last task ends'.
