David Kerr
2013-Feb-05 01:41 UTC
[Puppet Users] How do I generate a sequence number in a template
I''m trying to puppetize my PgPool install. PgPool uses the convention: backend_hostname0 = backend_port0 = backend_weight0 = backend_data_directory0 = backend_flag0 = I''m using exported resources and concat to auto-detect postgres instances. My template for this chunk looks like: <% Array(ipaddress).zip(Array(pgport)).each do |ipaddress,port| -%> <% backend = 0 %> backend_hostname<%= backend -%> = <%= ipaddress %> backend_port<%= backend -%> = <%= port %> backend_weight<%= backend -%> = 1 backend_data_directory<%= backend -%> = ''/db/pg'' backend_flag<%= backend -%> = ''ALLOW_TO_FAILOVER'' <% backend += 1 %> <% end %> I assumed that the backend = 0 / backend += 1 would work like a counter as this .each loop was iterated over. However what I end up with is two stanza''s with backend_hostname0 ...etc... backend_hostname0 ...etc... any ideas on how to make this happen? Thanks -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Aaron Russo
2013-Feb-05 05:05 UTC
Re: [Puppet Users] How do I generate a sequence number in a template
On Mon, Feb 4, 2013 at 5:41 PM, David Kerr <kerr23@gmail.com> wrote:> My template for this chunk looks like: > <% Array(ipaddress).zip(Array(pgport)).each do |ipaddress,port| -%> > <% backend = 0 %> > backend_hostname<%= backend -%> = <%= ipaddress %> > backend_port<%= backend -%> = <%= port %> > backend_weight<%= backend -%> = 1 > backend_data_directory<%= backend -%> = ''/db/pg'' > backend_flag<%= backend -%> = ''ALLOW_TO_FAILOVER'' > <% backend += 1 %> > <% end %> >I think your problem is you are re-initializing the ''backend'' variable each iteration of the loop. Try: <% backend = 0 -%> <% Array(ipaddress).zip(Array(pgport)).each do |ipaddress,port| -%> backend_hostname<%= backend -%> = <%= ipaddress %> backend_port<%= backend -%> = <%= port %> backend_weight<%= backend -%> = 1 backend_data_directory<%= backend -%> = ''/db/pg'' backend_flag<%= backend -%> = ''ALLOW_TO_FAILOVER'' <% backend += 1 -%> <% end %> Cheers, Aaron Russo IST Infrastructure Services, Unix Group UC Berkeley --- Desk: 510-643-5550Mobile: 510-206-1532 IM: arusso@berkeley.edu (XMPP/Jabber) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
David Kerr
2013-Feb-05 06:13 UTC
Re: [Puppet Users] How do I generate a sequence number in a template
yeah, i saw that, and fixed it, but still no good. i had thought/hoped that i deleted this post and posted my next one which you also kindly answered. On Monday, February 4, 2013 9:05:24 PM UTC-8, Aaron Russo wrote:> > > On Mon, Feb 4, 2013 at 5:41 PM, David Kerr <ker...@gmail.com <javascript:> > > wrote: > >> My template for this chunk looks like: >> <% Array(ipaddress).zip(Array(pgport)).each do |ipaddress,port| -%> >> <% backend = 0 %> >> backend_hostname<%= backend -%> = <%= ipaddress %> >> backend_port<%= backend -%> = <%= port %> >> backend_weight<%= backend -%> = 1 >> backend_data_directory<%= backend -%> = ''/db/pg'' >> backend_flag<%= backend -%> = ''ALLOW_TO_FAILOVER'' >> <% backend += 1 %> >> <% end %> >> > > I think your problem is you are re-initializing the ''backend'' variable > each iteration of the loop. Try: > > <% backend = 0 -%> > <% Array(ipaddress).zip(Array(pgport)).each do |ipaddress,port| -%> > backend_hostname<%= backend -%> = <%= ipaddress %> > backend_port<%= backend -%> = <%= port %> > backend_weight<%= backend -%> = 1 > backend_data_directory<%= backend -%> = ''/db/pg'' > backend_flag<%= backend -%> = ''ALLOW_TO_FAILOVER'' > <% backend += 1 -%> > <% end %> > > Cheers, > > Aaron Russo > IST Infrastructure Services, Unix Group > UC Berkeley > --- > Desk: 510-643-5550Mobile: 510-206-1532 > IM: aru...@berkeley.edu <javascript:> (XMPP/Jabber) > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.