Hi Felix, Thanks for the information. I used the create_resources and fixed the issue. Further I started using the individual host files as you suggested to make it more manageable. Thanks again for the tips.
This is what I finally implemented. (Note: I came across another issue with this implementation and workaround is available in https://groups.google.com/forum/#!topic/puppet-users/aoGQQlND8Kw) class foundation::network { # Defaults for network configuration $nic_default = { 'ensure' => 'up' } # Extract Data from Hiera for the host in concern $nics = hiera("networks",{}) # Configure networks based on the parameters create_resources(network::if::static, $nics, $nic_default) } /etc/puppet/hieradata/viradamin2.json { "networks":{ "viradmin2-admin":{ "interface":"eth0", "ipaddress":"10.10.1.2", "netmask":"255.255.255.0" } } } On Wednesday, January 15, 2014 3:56:57 AM UTC+10, Felix.Frank wrote: > > On 01/12/2014 09:15 AM, CD wrote: > > 1. hiera($variable) returns a hash but for resource to iterate it > > requires and array. Any idea how to convert it to an array > > Hiera returns whatever it reads from your data file. If your json > deserialized to an array, that is what Hiera will return to you. > > > 2. How to specify ip so that it get the corresponding value from eth0 or > > eth1. > > You might want to hand the whole respective data structure into your > define (all code untested): > > $nic_list = keys($nics) > network_config { $nic_list: data => $nics } > > define network_config($data) { > $ip = $data[$name]["ip"] > ... > [ your implementation here ] > } > > Depending on where else you need this specific data, you may > alternatively tailor it in a way that will enable you to just > > create_resources("network_config", $nics) > > As an aside, this design looks rather cumbersome and limiting you. I > found that hiera is most powerful and intuitive if it can itself figure > out which dataset to return (e.g. <hostname>.json) and splitting things > out into many keys. > > Of course, it's not a one-size-fits-all issue, if your mileage is better > this way, feel free to stick to it, of course. > > HTH, > Felix > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d3c4295c-0ab7-4289-a63b-791588a0fdb3%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
