Thank you very much for the answer Nan, ive used your first option... ;), and works.
Cheers. On Friday, 29 August 2014 19:35:38 UTC+2, Nan Liu wrote: > > Puppet array expansion of resources titles doesn't perform any expansion > for resource properties. There might be another way in experimental parser, > but here's two options. > > 1. structure the data so you can pass it to create_resource: > $hash_of_resources = { 'name1' => { 'port' => 'port1'}, 'name2' => { > 'port' => 'port2' } } > create_resource('instance', $hash_of_resources) > > 2. Modify the define type to lookup the value within a hash with the > resource title as the key: > # change define type to look up port value via resource name as hash key > # do not specify $name as a variable, it's implicit > define instances ( $port ) { > $port_file = $port[$name] > file { "${name}": > ensure => present, > path => "/path/${port_file}" > } > } > > $array1 = ['name1', 'name2'] > $array2 = ['port1', 'port2'] > > # this makes it [ ['name1', 'port1'], ['name2', 'port2'] ] > $zip = zip($array1, $array2) > > # I can't find a to_hash function in stdlib, but essentially a hideous way > to generate: { 'name1' => 'port1', 'name2' => 'port2' } > $port = parseyaml(inline_template("<%= Hash[*@zip.flatten(1)].to_yaml %>")) > > instances { $array1: > port => $port, > } > > HTH, > > Nan > > Fran Rodríguez <javascript:> > August 29, 2014 at 4:40 AM > Hi group, > > Im trying to do something with to arrays: > > array1 = ['name1', 'name2'] > array2 = ['port1', 'port2'] > > The arrays has the same number of elements and what i want to do it is > passing to a define function: > > instances { $array1:; $array2:; } > > The instances define does something simple: > > define instances ( $name, $port ) { > file { "${name}": > ensure => present, > path => "/path/${port}" > } > } > > I thing im missing something about iteration with define function because > puppet say: > > Error 400 on SERVER: Must pass name to Instances[name1] > > Could somebody tell me what im doing wrong or point to me in the correct > direction?¿ > > Thanks and cheers > -- > 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...@googlegroups.com <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/1d39746a-dc24-4584-b640-35a96fe1e8af%40googlegroups.com > > <https://groups.google.com/d/msgid/puppet-users/1d39746a-dc24-4584-b640-35a96fe1e8af%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- 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/0940cfc2-d701-4e0d-8f68-ecef3b86bb95%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.