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 <mailto:fran.clas...@gmail.com>
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+unsubscr...@googlegroups.com
<mailto:puppet-users+unsubscr...@googlegroups.com>.
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/5400B9DF.2090606%40gmail.com.
For more options, visit https://groups.google.com/d/optout.