I have the following http://pastebin.com/dphfbV7z As outlined in the above I want to turn the data structure I have into what is outlined in a template. Not sure how to go about accessing and looping over the multiple levels in the data structure. 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.
Daniele Sluijters
2013-Apr-16 08:06 UTC
[Puppet Users] Re: Template with array and nested hash
Hi, So you have an array containing one or multiple hashes which in turn contains an array of rules which are hashes by themselves. In templates you use erb, so embedded ruby. Therefor you can use just about any construct from the Ruby language, including how you can do things with Arrays and Hashes. So, we start: <% @squid_acls.each do |acl| %> so now we have a loop for the outer part of the array # <%= acl[''comment''] =%> here we just outputted what comment contained <% acl[''rules'']. each do |rule| %> now we''re accessing the contents of the rules key. Since we know it''s an array you can loop over it acl <%= rule[''aclname''] =%> <%= rule[''acltype''] =%> <%= rule[''arg''] =%> <% end %> <% end %> This probably won''t work out of the box like this but it should give you an idea on how to get started. -- Daniele Sluijters On Tuesday, 16 April 2013 06:26:25 UTC+2, Matthew Ceroni wrote:> > I have the following > > http://pastebin.com/dphfbV7z > > As outlined in the above I want to turn the data structure I have into > what is outlined in a template. Not sure how to go about accessing and > looping over the multiple levels in the data structure. > > Thanks >On Tuesday, 16 April 2013 06:26:25 UTC+2, Matthew Ceroni wrote:> > I have the following > > http://pastebin.com/dphfbV7z > > As outlined in the above I want to turn the data structure I have into > what is outlined in a template. Not sure how to go about accessing and > looping over the multiple levels in the data structure. > > 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.