An example callback for logging per-host activity in /var/log/ansible

1,175 views
Skip to first unread message

Michael DeHaan

unread,
Aug 21, 2012, 6:45:29 PM8/21/12
to ansible...@googlegroups.com
Recently someone (believe it was Lorin, can't remember) was asking
about whether we could log activity on a per host basis on the server
-- given, we already log things remotely on the client.

Now, everyone is going to want different kind of logs, so I didn't
want to work this into core, but I made a callback plugin.

This may be exactly what you want, it may not be, but the niceness is,
you can tweak it however you want, and it's not part of core, so you
don't have to fork ansible and maintain a different implementation.

I hope this is useful in showing what callback plugins can do, and
helps people write other plugins:

https://github.com/ansible/ansible-plugins/blob/master/callbacks/log_plays.py

--Michael

Lorin Hochstein

unread,
Aug 22, 2012, 10:31:56 PM8/22/12
to ansible...@googlegroups.com
I don't know if it was me that mentioned this, but the next time I do ansible-related stuff, I'm definitely going to use the new callback hooks to generate some log files with the returned error strings properly formatted (e.g.,. no inline "\n" stuff)


Take care,

Lorin
--
Lorin Hochstein
Lead Architect - Cloud Services
Nimbis Services, Inc.

Michael DeHaan

unread,
Aug 22, 2012, 11:07:32 PM8/22/12
to ansible...@googlegroups.com
We didn't really have log files before, so I'm kind of confused as to what you were not happy about.

The logging callback here is very much a proof of concept, I'll take upgrades to it.

--Michael


On Wednesday, August 22, 2012 at 10:31 PM, Lorin Hochstein wrote:
> www.nimbisservices.com (https://www.nimbisservices.com/)



Lorin Hochstein

unread,
Aug 22, 2012, 11:14:51 PM8/22/12
to ansible...@googlegroups.com
I was just referring to the console output that gets generated by ansible-playbook when a task fails not he client. So, for example, if I'm installing a bunch of packages with the pip module, and something fails, a lot of output gets dumped back, but it's not really readable unless the "\n"'s are turned into proper newlines.

I'll try out these callbacks once I start hitting this stuff again.

Michael DeHaan

unread,
Aug 23, 2012, 8:21:47 AM8/23/12
to ansible...@googlegroups.com
That's actually not user-pluggable and would need to go in core,
though all it would require is writing a custom JSON pretty-printer.

I've been thinking about that -- there's really no reason that output
even needs to be json, so one key per line, or equivalent, would be
reasonable for playbook output.
Reply all
Reply to author
Forward
0 new messages