Thank you so much for your timely help.
As you might know, most of my cookbooks are downloaded from internet, the
initial data of each cookbook are defined at the attribute files.
Now what I am trying to do is replace the initial data with mine and don’t
change the cookbook recipes. That is why I import data form my databag at
the file attributes/server.rb, then replace the default variables with the
data from my databag. Unfortunately, this way doesn’t work.
On Sun, Sep 8, 2013 at 8:51 AM, Daniel Condomitti email@example.com:
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 iPhone
On Sep 7, 2013, at 5:42 PM, Sam Su firstname.lastname@example.org wrote:
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
I added several lines at the top of the attributes file
attributes/server.rb like this:
the databag ‘website’ was defined, there is a default databag item
‘env_default’, if users have defined their own databag item,
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’])
item = data_bag_item(‘website’,‘env_default’)
when I run the mysql cookbook at a chef client, it prompt
Undefined node attribute or method
When move these code into the file recipes/server.rb, then the error is
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.