Run a logging task after Playbook ends?

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.

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

(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

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!

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

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.

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
  tasks:
     - hipchat: ....

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