Hi Jonathan & Charles,
Thanks for the great hint. I really made a mistake in using the data-bag information directly in a template. Here is the code which will work:
DataBag:
intChef:~/chef-repo$ knife data bag show GLOBAL NTP
{
"id": "NTP",
"ntp_1_for_testing": "xxx.xxx.xxx.xxx",
}
Recipe:
GLOBAL = data_bag_item('GLOBAL','NTP')
node[:ntp1] = "#{GLOBAL['ntp_1_for_testing']}"
Template:
NTP1 for DOMAIN <%= node[:ntp1] %>
Maybe it's not the correct way to do that but it works!
Regards
Andreas
-----Original Message-----
From: jonathan@jpluscplusm.com [mailto:jonathan@jpluscplusm.com] On Behalf Of Jonathan Matthews
Sent: Mittwoch, 23. März 2011 09:22
To: chef@lists.opscode.com
Subject: [chef] Re: Data-Bag how to use in templates
On 23 March 2011 07:21, WEINHAPL Andreas
andreas.weinhapl@thalesgroup.com wrote:
HI,
Yesterday I tested the Data-Bag! But I’m not able to use the Information
from the DataBag in Templates.
My recipe is:
GLOBAL = data_bag_item('GLOBAL', 'NTP') and just use a template-function
(create a file from file.erb)
In my file.erb:
<%= node[:GLOBAL][:ntp_2_thalesgroup.at] %>
Irrespective of your problem, already addressed by Charles, take a
look at the Resources wiki page Template section. I believe the
canonical way to reference data in a template, especially when it's
global/data-bag driven and not node-specific, is to use the fact that
it shows up as instance variables inside your template when it's been
passed in correctly. Not node[:blah] values.
I may be wrong, but it WFM
Jonathan
Jonathan Matthews
London, UK
http://www.jpluscplusm.com/contact.html