[chef] How to import data from my databag into cookbook attributes


Chronological Thread 
  • From: Sam Su < >
  • To:
  • Subject: [chef] How to import data from my databag into cookbook attributes
  • Date: Sun, 8 Sep 2013 08:42:05 +0800

Hi,

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:
# 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'])
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.

§