data_bag_item isn't available within the context of attribute files. You can load the data bag in your recipe (rescuing a missing one) and then fall back to default attributes using the OR operator. Otherwise, you can load the data bag and set node attributes based on the contents of it early on in the recipe and then use the attributes normally later in the run.Either way, you may be able to accomplish your goals in a cleaner way. Can you explain further why you're using data bags over just setting node attributes explicitly as part of the bootstrap or within environment files?Sent from my iPhoneHi,# the databag 'website' was defined, there is a default databag item 'env_default', if users have defined their own databag item,
hi, I am just using chef and trying to import data from my databag into the mysql cookbook attribute server.rb.
I downloaded the mysql cookbook from https://github.com/opscode-cookbooks/mysql and uploaded to my open source chef server.
I added several lines at the top of the attributes file attributes/server.rb like this:
# here is node[mycluster], then the following code will use the users' specific databag item.if defined? node['mycluster']
item = data_bag_item('website',node['mycluster'])
else
item = data_bag_item('website','env_default')
end
when I run the mysql cookbook at a chef client, it prompt
NoMethodError
-------------
Undefined node attribute or method `data_bag_item' on `node'
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/mysql/attributes/server.rb:21:in `from_file'
When move these code into the file recipes/server.rb, then the error is gone.
I am wondering can I import data from databag at attributes files?
If someone can give a hint or example, it will be much appreciated.Thanks,Sam
Archive powered by MHonArc 2.6.16.