tom s
2012-Aug-24 15:22 UTC
[Puppet Users] apparent unwanted conversion of arrays to strings with parameterized class
I''m sure I''m doing something silly here, but I''m
struggling to pass an
array variable to a parameterized class and have it stay as an array:
# cat modules/testmodule/manifests/init.pp
class testmodule($array1) {
file {''/tmp/testmodule'' :
content => template(''testmodule/testmodule.erb''),
}
}
# cat manifests/nodes/site.pp
node ''testclient'' {
$myarray = [''aaa'',''bbb'']
class { "testmodule":
array1 => [$myarray],
}
}
# cat modules/testmodule/templates/testmodule.erb
<% array1.each do |val| -%>
array1 val: <%= val %>
<% end -%>
<puppet run>
# cat /tmp/testmodule
array1 val: aaabbb
i.e. the class does not think $array1 is an array any more. However if I
change the node config to set the parameter as an array explicitly:
# cat manifests/nodes/site.pp
node ''testclient'' {
class { "testmodule":
array1 => [''aaa'',''bbb''],
}
}
<puppet run>
# cat /tmp/testmodule
array1 val: aaa
array1 val: bbb
Its not unreasonable to try and pass an array as a variable is it?
Cheers,
Tom.
--
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/-/TjLIZvQPSd8J.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Nan Liu
2012-Aug-24 17:31 UTC
Re: [Puppet Users] apparent unwanted conversion of arrays to strings with parameterized class
On Fri, Aug 24, 2012 at 8:22 AM, tom s <puppetlabs@tomseeley.co.uk> wrote:> I''m sure I''m doing something silly here, but I''m struggling to pass an array > variable to a parameterized class and have it stay as an array: > > # cat modules/testmodule/manifests/init.pp > class testmodule($array1) { > file {''/tmp/testmodule'' : > content => template(''testmodule/testmodule.erb''), > } > } > > # cat manifests/nodes/site.pp > node ''testclient'' { > $myarray = [''aaa'',''bbb''] > class { "testmodule": > array1 => [$myarray],I don''t think you want to add [ ] around $myarray which turns it into [[''aaa'',''bbb'']]. Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.