I am trying to install a chef handler via the chef_handler lwrp. This handler (chef-handler-email) comes bundled in a gem. I am trying to install the gem then turn on the handler from within a single recipe that looks like:
chef_gem "chef-handler-mail"
chef_handler "MailHandler" do
source 'chef/handler/mail'
arguments :to_address => "root"
action :nothing
supports :exception => true, :report => false
end.run_action(:enable)
This works fine if the gem is already installed. However, if the Gem is not already installed I receive this error:
[2012-12-09T20:47:56-05:00] FATAL: LoadError: chef_handler[MailHandler] (chef_handler::email line 13) had an error: LoadError: no such file to load -- chef/handler/mail.rb
It appears as though the chef_handler resource is trying to load the handler before chef_gem has executed and installed the gem for the handler. I can obviously do this in a two step manual process where I have a separate recipe for installing the gem, then flip over to another recipe that configures the handler, but I'm hoping to avoid multi-step manual processes. Can it be done via single recipe?
I have a similar recipe for chef minitest-chef-handler:
chef_gem 'minitest'
chef_gem 'minitest-chef-handler'
require 'rubygems'
require 'minitest-chef-handler'
[... some unrelated code ...]
chef_handler "MiniTest::Chef::Handler" do
source "minitest-chef-handler"
arguments :verbose => true
action :nothing
end.run_action( :enable )
Try requiring your gem before creating chef_handler resource, or may be source should be different...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With