jtimberman's Code Blog

Chef, Ops, Ruby, Linux/Unix. Opinions are mine, not my employer's (CHEF).

A Simple Report Handler

Exception and report handlers are a pretty cool feature of Chef. They have been around for several versions (first appearing in 0.9.0), but haven’t received a lot of attention. In the Chef Advanced training class, we go into greater detail about writing handlers, so I had a play with them a bit recently. Also, the default logging output for a chef-client run is a bit more verbose in Chef 0.10 than it was in previous versions. I’ve been convinced this is for the better overall, though all the “Processing…” lines can get in the way of things that are actually being configured. To make it clearer of what resources were actually configured in the Chef run, I wrote a very simple handler:

To use this in my chef-client, I drop it off as a file, say “/var/lib/chef/handler/updated_resources.rb” and then configure /etc/chef/client.rb:

Then when I run chef-client, after the run is complete it will display something like this:

[Sun, 24 Apr 2011 22:50:58 -0600] INFO: Chef Run complete in 15.297228 seconds
[Sun, 24 Apr 2011 22:50:58 -0600] INFO: Running report handlers
[Sun, 24 Apr 2011 22:50:58 -0600] INFO: Resources updated this run:
[Sun, 24 Apr 2011 22:50:58 -0600] INFO:   execute[apt-get update]
[Sun, 24 Apr 2011 22:50:58 -0600] INFO:   execute[index-gem-repository]
[Sun, 24 Apr 2011 22:50:58 -0600] INFO:   remote_directory[/srv/gems/gems]
[Sun, 24 Apr 2011 22:50:58 -0600] INFO: Report handlers complete

Update: I released a gem for this handler. You can now install the gem and then use require 'chef/handler/updated_resources' in /etc/chef/client.rb