[chef] Re: Re: Fwd: help with erb templates


Chronological Thread 
  • From: Matthew Moretti < >
  • To:
  • Subject: [chef] Re: Re: Fwd: help with erb templates
  • Date: Wed, 29 May 2013 16:26:05 -0400

I don't think that it's likely to be the problem, but you don't need line 50 of your recipe. That's essentially a hash with duplicate keys - I'm pretty sure that Ruby takes the second one, so it's not a problem, but it also doesn't do anything.

It's more likely that search(:node, "role:web") isn't returning what you expect. I'm not to well-versed in search, but it seems like your search might actually be returning nil

Joshua is correct, the haproxy cookbook has a good example. In particular, check out line 20 of the app_lb recipe. I note that the author appended || [] after their search to guard agains the problem of empty results.

Also, another minor nit-pick: you don't need puts in your template if you use the <%= %> notation. So line 62 can be

 <%= "hostname#{count} = #{result['fqdn']}" %>

Hope that helps

-Matt Moretti



On Wed, May 29, 2013 at 3:14 PM, Joshua Miller < " target="_blank"> > wrote:
Not in front of a computer right now but have a look at the haproxy cookbook.

 




On Wed, May 29, 2013 at 12:10 PM, Azul < ="mailto: ">> wrote:
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.

§