Dan
2013-Mar-19 09:45 UTC
[Puppet Users] How to loop through entries in nodes definition for puppet
Could someone please help me understand how I could loop through the following nodes definition in my templates file? ip::addr{ "as2s67v": ip0 => "192.168.30.0", pre0 => "/24", ip1 => "172.45.35.0", pre1 => "/16", ip2 => "145.88.88.0", pre2 => "/24", } I''d like to print out the above using my template file, however I can''t be certain of how many entries will exist, I want to end up with a file like so: server: as2s67v ipaddress0 = "192.168.30.0" prefix0 = "24" ipaddress1 = "172.45.35.0" prefix1 = "16" ipaddress2 = "145.88.88.0" prefix2 = "24" How could I go about achieving this? thanks Dan -- 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.
Peter Meier
2013-Mar-19 10:39 UTC
Re: [Puppet Users] How to loop through entries in nodes definition for puppet
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> I''d like to print out the above using my template file, however I > can''t be certain of how many entries will exist, I want to end up > with a file like so:pass a hash to your ip::addr define and loop over keys/values as indication which interfaces to you have with which values: ip::addr{''bla'': interfaces => { ''eth0'' => { ip => 0.0.0.0, prefix => ''/24'' } ''eth1'' => { ip => 1.0.0.0, prefix => ''/24'' } } } template: server: <%= name %> <% interfaces.keys.sort.each_with_index do |k,i| -%> ipaddress<%= i %> = "<%= interfaces[k][''ip'']" prefix<%= i %> = "<%= interfaces[k][''prefix'']" <% end -%> ~pete -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlFIQFsACgkQbwltcAfKi3+7HgCgnJ/ldEJRmQdSMq77SMFOAh2m kLMAnjFYTpenMyfFz+zOlhqXoFe6yjR3 =CVkW -----END PGP SIGNATURE----- -- 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.