FAQ
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 [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Nan Liu at Aug 24, 2012 at 5:32 pm

    On Fri, Aug 24, 2012 at 8:22 AM, tom s 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 [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedAug 24, '12 at 3:22p
activeAug 24, '12 at 5:32p
posts2
users2
websitepuppetlabs.com

2 users in discussion

Tom s: 1 post Nan Liu: 1 post

People

Translate

site design / logo © 2023 Grokbase