Wagner Sartori Junior
2011-Dec-13 14:07 UTC
[Puppet Users] File keeps changing on each puppet run using a hash variable and a template
Hi, I have a hash variable defined on a node: $vips = { wha => { ''vip1.mycompany.net'' => { name => ''wha.mycompany.net'', vip => ''10.4.229.132'', certificate_name => ''wha.mycompany.net'', }, ''vip2.mycompany.net'' => { name => ''wha.mycompany.com'', vip => ''10.4.229.136'', certificate_name => ''wha.mycompany.com'', }, ... # I have around 15 VIP''s on each node }, On my template I have: <% vips.each_pair do |system, system_values| -%> <% if system == "wha" then -%> <% system_values.each_pair do |server_name, server_name_values| -%> #<%= server_name_values[''name''] %> <% if server_name_values.has_key?("certificate_name") -%> Listen <%= server_name_values[''vip''] %>:80 Listen <%= server_name_values[''vip''] %>:443 <% else -%> Listen <%= server_name_values[''vip''] %>:80 <% end -%><% end -%><% end -%><% end -%> My file on the servers keeps changing on each puppet run. The HASH variable order is what changes from one run to another(first run it defines wha.mycompany.net first on second run it defines wha.mycompany.com first). Is this a bug or I''m doing something stupid here? Thanks, Wagner Sartori Junior -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Christopher Wood
2011-Dec-13 18:51 UTC
Re: [Puppet Users] File keeps changing on each puppet run using a hash variable and a template
On Tue, Dec 13, 2011 at 12:07:46PM -0200, Wagner Sartori Junior wrote:> Hi, > I have a hash variable defined on a node: > � � � � $vips = { > � � � � � � � � wha => { > � � � � � � � � � � � � ''[1]vip1.mycompany.net'' => { > � � � � � � � � � � � � � � � � name => ''[2]wha.mycompany.net'', > � � � � � � � � � � � � � � � � vip => ''10.4.229.132'', > � � � � � � � � � � � � � � � � certificate_name => > ''[3]wha.mycompany.net'', > � � � � � � � � � � � � }, > � � � � � � � � � � � � ''[4]vip2.mycompany.net'' => { > � � � � � � � � � � � � � � � � name => ''[5]wha.mycompany.com'', > � � � � � � � � � � � � � � � � vip => ''10.4.229.136'', > � � � � � � � � � � � � � � � � certificate_name => > ''[6]wha.mycompany.com'', > � � � � � � � � � � � � }, > � � � � � � � � � � � � ... # I have around 15 VIP''s on each node > � � � � � � � }, > On my template I have: > <% vips.each_pair do |system, system_values| -%> > <% if system == "wha" then -%> > <% system_values.each_pair do |server_name, server_name_values| -%> > #<%= server_name_values[''name''] %> > <% if server_name_values.has_key?("certificate_name") -%> > Listen <%= server_name_values[''vip''] %>:80 > Listen <%= server_name_values[''vip''] %>:443 > <% else -%> > Listen <%= server_name_values[''vip''] %>:80 > <% end -%><% end -%><% end -%><% end -%> > My file on the servers keeps changing on each puppet run. The HASH > variable order is what changes from one run to another(first run it > defines [7]wha.mycompany.net first on second run it defines > [8]wha.mycompany.com first). > Is this a bug or I''m doing something stupid here?Sort every time you loop over hash keys (I use this solution). Alternatively, consider storing a list of lists.> Thanks, > Wagner Sartori Junior > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > References > > Visible links > 1. http://vip1.mycompany.net/ > 2. http://wha.mycompany.net/ > 3. http://wha.mycompany.net/ > 4. http://vip2.mycompany.net/ > 5. http://wha.mycompany.com/ > 6. http://wha.mycompany.com/ > 7. http://wha.mycompany.net/ > 8. http://wha.mycompany.com/-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.