On Tuesday, September 15, 2015 at 3:48:02 AM UTC-5, Sergiu Cornea wrote: > > Good morning guys, > > I am trying to template the OMD rules file and for this I am using 2 > arrays one which holds the IPs and the other one the Services. > > In my ERB template I have this: > >
This bit is surely wrong, or at least deceptive: > <% for @omd_service in @omd_service -%> > You must want to use a different variable for the individual services than the one containing the overall array of services. You should not in any case be trying to assign to a variable that corresponds to a DSL variable, as DSL variables' values do not change once set. > <% var1 = @omd_service %> > Moreover, nesting this next loop inside the other will not produce the output you want. It iterates through every element of array @server2 for each element of @omd_service, just as you observe. > <% @server2.each do |omd_ip| -%> > <% end -%> > <%= var1 %> <%= omd_ip %> > <% end -%> > > However, the output isn't what I am expecting: > > Perhaps not, but it's what you *should* expect. Instead of a nested iteration of the two array, you want a single correlated iteration of both arrays together. There is any number of ways to achieve that, but this one is fairly idiomatic: <% @omd_service.zip(@server2).each do |service, server| -%> <%= service %> <%= server %> <% end -%> The key here is probably the Array.zip() method. It constructs a new array of arrays by zipping together the each set of corresponding (by index) elements of the array on which it is invoked and each of the arguments. Each set of corresponding elements of the component arrays forms one element (an array) of the zipped result. Iterating (singly) over that yields your pairs of corresponding elements. John -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d9783aae-5c4d-4824-b9d5-4192d90f1eda%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.