[chef] Fwd: help with erb templates


Chronological Thread 
  • From: Azul < >
  • To:
  • Subject: [chef] Fwd: help with erb templates
  • Date: Wed, 29 May 2013 20:10:12 +0100



It has been a long day,

How can I pass an array as symbol in chef ?
I want to build a list of all the FQDNs containing my role 'web', and pass that list to my erb template.

Tried to do it directly from the template, but it looks it only supports ruby code and not exactly chef code.


my recipe,

 44 template "#{node[:apache][:dir]}/httpd.conf" do
 45   source "httpd.erb"
 49   variables({
 50       :list_of_nodes => [],
 51       :list_of_nodes => search(:node, "role:web" )
 52   })
 53   notifies :restart, resources(:service =>"httpd")
 54 end


my httpd.erb template

 60 <% count=0 %>
 61 <% @list_of_nodes.each do |result| %>
 62    <% puts "hostname#{count} = #{result['fqdn']}"%>
 67    <% count = count + 1  %>
 68 <% end  %>
 

the result should be:
hostname0 = asdfsdf.sdfdsf.com
hostname1 = asdfkjew.com
.
.
.


Right now I simply get a no method .each for you,
[2013-05-29T18:54:18+00:00] FATAL: Chef::Mixin::Template::TemplateError: undefined method `each' for nil:NilClass




Archive powered by MHonArc 2.6.16.

§