apparent unwanted conversion of arrays to strings with parameterized class

24 views
Skip to first unread message

tom s

unread,
Aug 24, 2012, 11:22:42 AM8/24/12
to puppet...@googlegroups.com
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.

Nan Liu

unread,
Aug 24, 2012, 1:31:47 PM8/24/12
to puppet...@googlegroups.com
On Fri, Aug 24, 2012 at 8:22 AM, tom s <puppe...@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
Reply all
Reply to author
Forward
0 new messages