You can access node attributes in recipes usingnode["apache"] # preferrednode[:apache] # as a symbol, deprecatednode.apache # as a method, deprecatedwhich works for sub-keys too:node["apache"]["dir"]node[:apache][:dir]node.apache.dirand test if there is such a attribute usingnode.attribute?("apache")andnode.apache.attribute?("dir")QUESTION: I suppose that one is a bit deprecated (despite being from the wiki) - should really be:node["apache"].attribute?("dir")Ruby note:In ruby predicate methods (which test whether something is true or not) often (by convention) end in '?' (like File.exists?() for example))You might want to check out:andAnother valuable page is http://wiki.opscode.com/display/chef/Just+Enough+Ruby+for+ChefTimOn Mon, Jun 27, 2011 at 9:29 AM, ItsMikeE < " target="_blank"> > wrote:Thanks for the response
That helps, but still leaves me with some questions
Looking at the wiki page on setting attributes
Default in ../cookbooks/../attributes/default.rb
Example Precedence #1
default["apache"]["dir"] = "/etc/apache2"
Override in .../roles/rolename.rb
Example Precedence #8
override_attributes({ "apache" => {"dir" => "/etc/apache2"}})
How do I reference the attribute inside a recipe?
I don't mind if it is in a case statement, and if statement or an only_if. I am
just trying to choose between one of two source files to overwrite one
destination file.
Again going back to the wiki I can see
if node.chef.attribute?("webui_enabled")
# set up webui stuff
end
How does that equate to the attributes that were set above?
Is it:
if node.apache.dir?
or
if node.chef.attribute?("apache""dir")
or
something else completely?
I don't really mind if it is in an only_if, or a case statement or an if test.
Archive powered by MHonArc 2.6.16.