How can we send parametrs to handler?


#1

Hello!

We are writing handler(message.rb).

require
"rubygems"
require “amqp”

require “chef”

class Test <
Chef::Handler

def initialize(ipad)
@ipad = ipad
end

puts @ipad


end

We have recipe where we call this
handler:


include_recipe “chef_handler"
chef_handler
"Chef::Handler::Test” do
arguments [‘something’]
source
"/var/chef/handlers/message.rb"
action :enable
end

We can’t
send parameters from recipe to handler, the result of running recipe is:
@ipad = nil
How can we send parametrs to handler?


Best
Regards,
Ilya Maltsev


#2

On Fri, Apr 13, 2012 at 11:03 AM, Ilya Maltsev ilya@notarikon.net wrote:

Hello!

We are writing handler(message.rb).

require "rubygems"
require “amqp”

require “chef”

class Test < Chef::Handler

def initialize(ipad)
  @ipad = ipad
end

puts  @ipad


end

We have recipe where we call this handler:


include_recipe "chef_handler"
chef_handler “Chef::Handler::Test” do
arguments [‘something’]
source "/var/chef/handlers/message.rb"
action :enable
end

We can’t send parameters from recipe to handler, the result of running
recipe is: @ipad = nil
How can we send parametrs to handler?

Is “puts @ipad” really at class scope, outside any method?
That’s not what you want.

Try:

class Test < Chef::Handler
def initialize(ipad)
@ipad = ipad
end

def report
puts @ipad
end
end


#3

Thank you!) it helps us


Best Regards,
Ilya Maltsev

Andrea
Campi писал 13.04.2012 13:07:

On Fri, Apr 13, 2012 at 11:03 AM, Ilya
Maltsev wrote:

Hello! We are writing handler(message.rb). require
"rubygems" require “amqp” require “chef” … class Test <
Chef::Handler def initialize(ipad) @ipad = ipad end puts @ipad
… end We have recipe where we call this handler: …
include_recipe “chef_handler” chef_handler “Chef::Handler::Test” do
arguments [‘something’] source “/var/chef/handlers/message.rb” action
:enable end … We can’t send parameters from recipe to handler,
the result of running recipe is: @ipad = nil How can we send parametrs
to handler?

Is “puts @ipad” really at class scope, outside any
method?
That’s not what you want.

Try:

class Test <
Chef::Handler
def initialize(ipad)
@ipad = ipad
end

def
report
puts @ipad
end
end

Links:

[1]
mailto:ilya@notarikon.net