# Run a logging task after Playbook ends?

**URL:** <https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785>\
**Category:** Ansible Project\
**Created:** [March 15, 2014, 10:15pm UTC](https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785 "2014-03-15T22:15:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Mahemoff](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Michael\_Mahemoff](https://forum.ansible.com/u/Michael_Mahemoff)\
**Post date:** [March 15, 2014, 10:15pm UTC](https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785/1 "2014-03-15T22:15:53Z")

</div>

Is there any way to run a command after the playbook has finished running, so it would run once no matter how many hosts were processed? Kind of a callback handler or “super-notifier”.

I have a Hipchat message generated after deploying and I’d rather see one summary message than a line for each deployed host.

---

<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:** [March 16, 2014, 12:19am UTC](https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785/2 "2014-03-16T00:19:56Z")

</div>

Yes, there’s a callback mechanism for this, where you can configure callback plugins in ansible.cfg (or the environment) and intercept arbitrary events.

This was an example:

[https://github.com/ansible/ansible/blob/devel/plugins/callbacks/log\_plays.py](https://github.com/ansible/ansible/blob/devel/plugins/callbacks/log_plays.py)

(Though the log\_plays setting in ansible.cfg basically does this now, making this above plugin mostly optional)

This one is more entertaining:

[https://github.com/ansible/ansible/blob/devel/plugins/callbacks/osx\_say.py](https://github.com/ansible/ansible/blob/devel/plugins/callbacks/osx_say.py)

So yes, you could definitely route this to hipchat instead of using the notification plugin.

Should you develop a cool script for hipchat, send us a pull request and we can ship it in the callbacks/ dir!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 16, 2014, 12:22am UTC](https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785/3 "2014-03-16T00:22:53Z")

</div>

I actually have a pull request submitted to supply a hipchat callback plugin:

[https://github.com/ansible/ansible/pull/6376](https://github.com/ansible/ansible/pull/6376)

The callback method of significance is `playbook_on_stats`

This is the callback method I use to send a hipchat notification that provides statistics about results at the end of the playbook run.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [March 16, 2014, 12:24am UTC](https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785/4 "2014-03-16T00:24:39Z")

</div>

you can also have a task or play at the end of your playbook that uses the  
existing hipchat notification module.

\<your current playbook\>

- hosts: localhost  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hipchat: ....

---

<div class="post-metadata">

**Author:** ![Michael\_Mahemoff](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Michael\_Mahemoff](https://forum.ansible.com/u/Michael_Mahemoff)\
**Post date:** [March 16, 2014, 10:29am UTC](https://forum.ansible.com/t/run-a-logging-task-after-playbook-ends/14785/5 "2014-03-16T10:29:54Z")

</div>

Thanks everyone, I’m glad there’s a mechanism for this and I’ll definitely test-run Matt’s new plugin.
