# Howto add a task from a callback

**URL:** <https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391>\
**Category:** Ansible Project\
**Created:** [June 3, 2015, 7:31am UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391 "2015-06-03T07:31:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Reter](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@Jeff\_Reter](https://forum.ansible.com/u/Jeff_Reter)\
**Post date:** [June 3, 2015, 7:31am UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/1 "2015-06-03T07:31:42Z")

</div>

what is the right way to add a task to the end of a playbook from a callback

i need to add a task based on an if in the callback “playbook\_on\_start”

can you give me an example of an simlpe command taks like echo “hello” (i dont need vars)

Thanks!

---

<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 3, 2015, 4:51pm UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/2 "2015-06-03T16:51:26Z")

</div>

callbacks have no influence on playbooks, they are to handle output  
from plays/tasks, information only goes in one direction.

if you need a conditional task, put it int the play

---

<div class="post-metadata">

**Author:** ![Jeff\_Reter](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@Jeff\_Reter](https://forum.ansible.com/u/Jeff_Reter)\
**Post date:** [June 9, 2015, 6:44am UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/3 "2015-06-09T06:44:14Z")

</div>

hmmm, code do no look “read only”

and how can add a task, without adding it to \>100 playbooks

write an own “ansible-playbook” wrapper?

is there any better docs than:  
**[http://docs.ansible.com/developing\_api.html](http://docs.ansible.com/developing_api.html)**

---

<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 9, 2015, 12:30pm UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/4 "2015-06-09T12:30:03Z")

</div>

what are you trying to accomplish? what is this task for?

---

<div class="post-metadata">

**Author:** ![Jeff\_Reter](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@Jeff\_Reter](https://forum.ansible.com/u/Jeff_Reter)\
**Post date:** [June 9, 2015, 2:53pm UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/5 "2015-06-09T14:53:02Z")

</div>

logging on server which user, ran which playbook, when

---

<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 9, 2015, 2:59pm UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/6 "2015-06-09T14:59:49Z")

</div>

Ansible already writes to syslog on the target machines also you can  
turn on a more detail ansible log on the 'master' in ansible.cfg, In  
general I would advice using a callback that writes to syslog (there  
is an example in the repo, but it does json/syslog). For your case, if  
you just want play name and user, it might be worth patching the  
existing logging to add that information.

---

<div class="post-metadata">

**Author:** ![Jeff\_Reter](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@Jeff\_Reter](https://forum.ansible.com/u/Jeff_Reter)\
**Post date:** [June 15, 2015, 2:36pm UTC](https://forum.ansible.com/t/howto-add-a-task-from-a-callback/18391/7 "2015-06-15T14:36:14Z")

</div>

thanks

sounds like patching “log” is the best way
