- From: Zac Stevens <
>
- To:
- Subject: [chef] Installing handlers with chef_handler
- Date: Thu, 21 Jul 2011 15:38:08 +0100
Hiya,
I would like to write a simple chef report handler, to distribute it
to my chef clients, and to get chef-client to use it.
The documentation
(
http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers)
points out the chef_handler cookbook, which exists to distribute and
install handlers. That's exactly what I want to do, but I can't get
it to work.
jtimberman blogged a very simple report handler example:
http://jtimberman.posterous.com/a-simple-report-handler
I added this to my fork of the chef_handler repo
(
https://github.com/zts/chef_handler/) and made sure that
recipe[chef_handler] would distribute the file - which it did. I then
configured /etc/chef/client.rb per the blog, and confirmed that the
handler worked:
<--snip-->
[Thu, 21 Jul 2011 15:14:52 +0100] INFO: Running report handlers
[Thu, 21 Jul 2011 15:14:52 +0100] INFO: Resources updated this run:
[Thu, 21 Jul 2011 15:14:52 +0100] INFO: remote_directory[/var/chef/handlers]
[Thu, 21 Jul 2011 15:14:52 +0100] INFO: Report handlers complete
However, I'd prefer not to be editing client.rb when the chef_handler
cookbook has a provider for this purpose.
I reverted the changes to client.rb, and added a recipe -
chef_handler::updated_resources. It looks like this:
chef_handler "SimpleReport::UpdatedResources" do
Chef::Log.info "Loading handler from:
#{node['chef_handler']['handler_path']}/updated_resources.rb"
source "#{node['chef_handler']['handler_path']}/updated_resources.rb"
action :nothing
end.run_action(:enable)
Then set it as my run_list:
$ knife node show kakistos.local -a run_list
run_list: recipe[chef_handler::updated_resources]
Unfortunately, it blows up:
[Thu, 21 Jul 2011 15:19:24 +0100] INFO: Loading handler from:
/var/chef/handlers/updated_resources.rb
[Thu, 21 Jul 2011 15:19:24 +0100] INFO: Processing
chef_handler[SimpleReport::UpdatedResources] action enable
(chef_handler::updated_resources line 4)
[Thu, 21 Jul 2011 15:19:24 +0100] ERROR:
chef_handler[SimpleReport::UpdatedResources]
(chef_handler::updated_resources line 4) has had an error
And the stacktrace:
NameError: chef_handler[SimpleReport::UpdatedResources]
(chef_handler::updated_resources line 4) had an error: uninitialized
constant Kernel::SimpleReport
/var/chef/cache/cookbooks/chef_handler/providers/default.rb:22:in `const_get'
/var/chef/cache/cookbooks/chef_handler/providers/default.rb:22:in
`block (2 levels) in class_from_file'
/var/chef/cache/cookbooks/chef_handler/providers/default.rb:22:in `each'
/var/chef/cache/cookbooks/chef_handler/providers/default.rb:22:in `inject'
/var/chef/cache/cookbooks/chef_handler/providers/default.rb:22:in
`block in class_from_file'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/provider.rb:104:in
`instance_eval'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/provider.rb:104:in
`block in action'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/resource.rb:417:in
`run_action'
/var/chef/cache/cookbooks/chef_handler/recipes/updated_resources.rb:8:in
`from_file'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/mixin/from_file.rb:30:in
`instance_eval'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/mixin/from_file.rb:30:in
`from_file'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/cookbook_version.rb:578:in
`load_recipe'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/mixin/language_include_recipe.rb:40:in
`block in include_recipe'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/mixin/language_include_recipe.rb:27:in
`each'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/mixin/language_include_recipe.rb:27:in
`include_recipe'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/run_context.rb:72:in
`block in load'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/run_context.rb:69:in
`each'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/run_context.rb:69:in
`load'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/client.rb:195:in
`setup_run_context'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/client.rb:159:in
`run'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/application/client.rb:239:in
`block in run_application'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/application/client.rb:229:in
`loop'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/application/client.rb:229:in
`run_application'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/lib/chef/application.rb:66:in
`run'
/Users/zts/.rvm/gems/
/gems/chef-0.10.2/bin/chef-client:26:in
`<top (required)>'
/Users/zts/.rvm/gems/
/bin/chef-client:19:in
`load'
/Users/zts/.rvm/gems/
/bin/chef-client:19:in
`<main>'
Questions:
* Have I made a mistake, or am I hitting a bug?
* Am I going about this the right way?
Undeterred, and assuming that perhaps that would be an obvious fault
to someone more familiar with ruby, I changed tack and tried the
chef_handler::json_file recipe. This is documented as enabling the
JsonFile report handler which is bundled with chef. While it doesn't
explode, it doesn't appear to do anything either:
[Thu, 21 Jul 2011 14:55:35 +0100] INFO: Run List expands to
[chef_handler::json_file]
[Thu, 21 Jul 2011 14:55:35 +0100] INFO: Starting Chef Run for kakistos.local
[Thu, 21 Jul 2011 14:55:37 +0100] INFO: Loading cookbooks [chef_handler]
[Thu, 21 Jul 2011 14:55:37 +0100] INFO: Processing
chef_handler[Chef::Handler::JsonFile] action enable
(chef_handler::json_file line 24)
[Thu, 21 Jul 2011 14:55:37 +0100] INFO: Processing
chef_handler[Chef::Handler::JsonFile] action nothing
(chef_handler::json_file line 24)
[Thu, 21 Jul 2011 14:55:40 +0100] INFO: Chef Run complete in 4.402447 seconds
[Thu, 21 Jul 2011 14:55:40 +0100] INFO: Running report handlers
[Thu, 21 Jul 2011 14:55:40 +0100] INFO: Report handlers complete
The relevant chunk of the debug output:
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Loading cookbook
chef_handler's providers from
/var/chef/cache/cookbooks/chef_handler/providers/default.rb
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Loaded contents of
/var/chef/cache/cookbooks/chef_handler/providers/default.rb into a
provider named chef_handler defined in Chef::Provider::ChefHandler
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Loading cookbook
chef_handler's resources from
/var/chef/cache/cookbooks/chef_handler/resources/default.rb
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Loaded contents of
/var/chef/cache/cookbooks/chef_handler/resources/default.rb into a
resource named chef_handler defined in Chef::Resource::ChefHandler
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Node kakistos.local loading
cookbook chef_handler's attribute file
/var/chef/cache/cookbooks/chef_handler/attributes/default.rb
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Loading Recipe
chef_handler::json_file via include_recipe
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Found recipe json_file in
cookbook chef_handler
[Thu, 21 Jul 2011 14:58:46 +0100] INFO: Processing
chef_handler[Chef::Handler::JsonFile] action enable
(chef_handler::json_file line 24)
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Chef::Handler::JsonFile has
not been loaded
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Converging node kakistos.local
[Thu, 21 Jul 2011 14:58:46 +0100] INFO: Processing
chef_handler[Chef::Handler::JsonFile] action nothing
(chef_handler::json_file line 24)
[Thu, 21 Jul 2011 14:58:46 +0100] DEBUG: Doing nothing for
chef_handler[Chef::Handler::JsonFile]
Questions:
* Should this have done something?
* How should I approach debugging this issue? (I'm really not sure
where to start)
All examples above are 0.10.2, on OS X, installed from gems. I've
also tried to get this working on an ubuntu VM, but met with exactly
the same results.
Thanks,
Zac
- [chef] Installing handlers with chef_handler, Zac Stevens, 07/21/2011
Archive powered by MHonArc 2.6.16.