Conditional attribute with data_bag_item in chef?
I need to set the default attribute (from cookbook dependency) to the value that I have included in the database. I want the attribute to be set to data_bag_item or nil if it doesn't exist. In attribute.rb
:
if defined?(data_bag_item('databag', 'item'))
default["something"]["item"] = data_bag_item('databag', 'item')
else
default["something"]["item"] = nil
end
Later, in my own recipe, I check to see if a variable is set to zero, but it seems that her error as an error (this is similar to the condition is not satisfied, therefore, default["something"]["item"]
is not created) No resource, method, or local variable named 'default' for 'Chef::Recipe "something"'
.
What am I doing wrong here?
( EDIT I study chef the way I study Ruby here. I could be totally wrong about using the in-case conventions. I'm open to all critics here!)
source to share
I'm not sure about the full context of your recipe, but it looks like you should change default
to node
. What for? default
is used to set values that can be changed for each deployed node, but when you use a script, you can get the value with node
. So just change default["something"]["item"]
to node["something"]["item"]
where you are checking the variable.
source to share