[chef] RE: Re: Data-Bag how to use in templates


Chronological Thread 
  • From: WEINHAPL Andreas < >
  • To: " " < >
  • Subject: [chef] RE: Re: Data-Bag how to use in templates
  • Date: Wed, 23 Mar 2011 10:20:54 +0100
  • Accept-language: en-US, fr-FR
  • Acceptlanguage: en-US, fr-FR

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: [ ">mailto: ] On Behalf Of Jonathan Matthews
Sent: Mittwoch, 23. März 2011 09:22
To:
Subject: [chef] Re: Data-Bag how to use in templates
 
On 23 March 2011 07:21, WEINHAPL Andreas
< > 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
 



Archive powered by MHonArc 2.6.16.

§