Reporting "changed" state by email

Hello ansible folk,

We’re running ansible mainly in the “pull” mode, and using the “local” connection type to run playbooks on our servers. It’s configured to log to /var/log/ansible.log, and this file is rotated periodically by logrotate.

Are any of you using nay clever tricks to parse the log file and email output of just changed tasks back to a defined address? Id’ love to be able to know when ansible has fixed something on one or more of my boxes.

Regards,

Anand

Are any of you using nay clever tricks to parse the log file and email
output of just changed tasks back to a defined address? Id' love to be able
to know when ansible has fixed something on one or more of my boxes.

I think a callback plugin may be what you want, as you can 'trigger' on
all sorts of events.

Dag Wieers has written something which sounds to me as though it's just
what you need [1] and there are more examples at [2].

        -JP

[1] https://github.com/ansible/ansible/blob/devel/plugins/callbacks/mail.py
[2] https://github.com/sfromm/ansible-plugins

Thanks for these pointers JP. The mail plugin looks interesting, and is probably what I need. How do I call it from a playbook though?

Thanks for these pointers JP. The mail plugin looks interesting, and is
probably what I need. How do I call it from a playbook though?

You don't -- that's the magic. :slight_smile:

You configure Ansible to use that callback plugin by dropping into the
directory you configure for callback plugins [1]. From that point on,
Ansible always invokes it automatically.

Forgive me for linking to my own blurb [2], but that's what I wrote at
the time. (I hope it's still more or less current.)

Good luck,

        -JP

[1] http://docs.ansible.com/developing_plugins.html
[2] http://jpmens.net/2012/09/11/watching-ansible-at-work-callbacks/

​It's not magic, it's Cow Power.​

It would be nice if ansible-galaxy had support for distributing these sort of plugins.

​+1​

It doesn’t make sense to include in Galaxy as callbacks are not role based.

Effectively it would just make it an index of useful things on GitHub where already this is included in the main project.

Alternatively, what might be nice is shipping example plugins in a directory, such that they get installed alongside Ansible.