Thanks for your suggestions guys. I did consider using create_resource, but don't see how I can when I'm trying to apply this Hiera data to a single file. To expand on my initial post, what I need to do is create multiple config blocks within one file resource. So this Hiera data:
haproxy_listeners : "cluster1" : ip : '192.168.0.2' port : '80' servers : "server1" : ip : '192.168.0.3' port : '8080' "server2" : ip : '192.168.0.4' port : '8080' "cluster2" : ip : '192.168.0.5' port : '80' servers : "server3" ip : '192.168.0.6' port : '8080' "server4" ip : '192.168.0.7' port : '8080' will result in this being generated in the haproxy config file: listen cluster1 192.168.0.2:80 server server1 192.168.0.3:8080 server server2 192.168.0.4:8080 listen cluster2 192.168.0.5:80 server server3 192.168.0.6:8080 server server4 192.168.0.7:8080 So I don't see how create_resources can handle this, as that's for creating multiple Puppet resources, as opposed to multiple blocks within a single file. The only alternative I can think of at the moment is using create_resources with a define which utilizes Augeas, but I don't know how well that will work. Thanks, Andy On Friday, 4 January 2013 16:47:13 UTC, Gavin Williams wrote: > > I'm with Andy on this one... I'm doing something very similar with my > NetApp volume provider (https://github.com/fatmcgav/fatmcgav-netapp/). > > I've created a define with the following contents: > define util::netapp::volume ( > $ensure = present, > $size, > $aggr = 'aggr1', > $snapresv = 0, > $autoincrement = true, > $snapschedule = {"minutes" => 0, "hours" => 0, "days" => 0, > "weeks" => 0} > ) { > > netapp_notify {"volume_define_${name}": > message => "Processing Volume ${name}", > } > -> > netapp_volume { "v_${name}": > ensure => $ensure, > initsize => $size, > aggregate => $aggr, > spaceres => "none", > snapreserve => $snapresv, > autoincrement => $autoincrement, > options => {'convert_ucode' => 'on', 'no_atime_update' => > 'on', 'try_first' => 'volume_grow'}, > snapschedule => $snapschedule > } > -> > netapp_qtree { "q_${name}": > ensure => $ensure, > volume => "v_${name}" > } > -> > netapp_export { "/vol/v_${name}/q_${name}": > ensure => $ensure, > persistent => true > } > > } > > I've added a default hash to 'snapschedule' in the options list, but that > can be over-ridden from the Hiera data. > > Then use the following to pull the data from hiera and call the define: > create_resources( util::netapp::volume, hiera('volumes') ) > > 'Volumes' in hiera yaml looks like: > volumes: > vol1: > ensure: present > size: '500m' > vol2: > ensure: present > size: '20g' > snapschedule: > minutes: 0 > hours: 36 > days: 0 > weeks: 0 > > You can also use the 'hiera' command to test your yaml structure: > $ hiera -c hiera.yaml volumes clientcert=act-star-nactl01 > {"vol1"=>{"ensure"=>"present", "size"=>"500m"}, > "vol2"=>{"ensure"=>"present", "size"=>"20g", "snapschedule"=>{"days"=>0, > "weeks"=>0, "hours"=>36, "minutes"=>0}}} > > As you can see from the above output, *snapschedule* for *vol2* is a > nested hash. This assumes that your resource provider can support hashes on > the relevant param/property ;) > > HTH > > Gav > > On Friday, 4 January 2013 15:37:25 UTC, llowder wrote: >> >> >> >> On Friday, January 4, 2013 9:11:28 AM UTC-6, Andy Taylor wrote: >>> >>> Hi, >>> >>> I'm trying to build a module for haproxy which fetches all the >>> configuration data from Hiera to populate the haproxy config file. I've run >>> into a number of issues though when I try to use hashes. Ideally, I want to >>> use something like this: >>> >>> haproxy_listeners : >>> "cluster1" : >>> ip : '192.168.0.2' >>> port : '80' >>> servers : >>> "server1" : >>> ip : '192.168.0.3' >>> port : '8080' >>> >>> So a hash of clusters with each cluster containing a nested hash of >>> servers. Is this possible with Hiera/ERB? It's easy enough to iterate over >>> the first hash, but I can't work out how to extract the contents of the >>> nested hash. Or I might just be approaching this in entirely the wrong >>> way... Any help would be much appreciated. >>> >>> >> I haven't used the function myself, but this looks like it would be a >> good case for a define + create_resources(), which I think is part of >> stdlib. You might need to restructure the hashes slightly, but I think that >> will be the best approach. >> >> >> >>> Thanks, >>> >>> Andy >>> >> -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/W3UBJBXuT24J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.