Access node attributes in a library

Can we access node attributes in a library? In the sample below, I get an error

NoMethodError: undefined method `[]’ for nil:NilClass on the stomp_server
variable assignment line

class Chef::Recipe::LOG def self.logEvent(s) stomp_server = @node[:stomp_server] Chef::Log.info ("#{stomp_server}");

end
end

You can access node attributes within a library if you do one of two things:

  1. If your library is a module you can include it into Chef::Recipe which will give you access to the node by the node function
  2. You can pass the node into your function and access it within the scope of that function.

--
Jamie Winsor
@resetexistence

On Thursday, August 2, 2012 at 11:58 AM, vin4gud@gmail.com wrote:

Can we access node attributes in a library? In the sample below, I get an error

NoMethodError: undefined method `' for nil:NilClass on the stomp_server
variable assignment line

class Chef::Recipe::LOG def self.logEvent(s) stomp_server = @node[:stomp_server] Chef::Log.info (http://Log.info) ("#{stomp_server}");

end
end