Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install dependencies for a chef handler?

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?

like image 303
Mark Roddy Avatar asked Nov 12 '22 15:11

Mark Roddy


1 Answers

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...

like image 82
Draco Ater Avatar answered Nov 15 '22 04:11

Draco Ater