Arrays from templates

1,126 views
Skip to first unread message

pablo

unread,
Mar 27, 2012, 10:55:05 AM3/27/12
to puppet...@googlegroups.com
Hi,

I am having an issue trying to use the inline_template function to
return an array. This is what I do:

$array = inline_template ("<%= a=['a1','b2','c3']; a %>")
notify {"array: ${array}":}

And that works, showing the typical comma-less string:
notice: /Stage[main]//Notify[array: a1b2c3]/message: defined 'message'
as 'array: a1b2c3'

But when I try to access just one element of the array, it breaks:
notify {"array: ${array[1]}":}

And I get:
err: Could not retrieve catalog from remote server: Error 400 on SERVER:
array is not an hash or array when accessing it with 1 at
/home/pablof/puppet-tree/manifests/groups.pp:27 on node

I have been trying, and it seems like the inline_template recognizes
external array declared this way (as arrays) but Puppet doesn't... am I
missing something? Do I have to convert the output to some type Puppet
understands?

Thanks!!
Pablo

R.I.Pienaar

unread,
Mar 27, 2012, 10:56:29 AM3/27/12
to puppet...@googlegroups.com

----- Original Message -----
> From: "pablo" <pablo.f...@cscs.ch>
> To: puppet...@googlegroups.com
> Sent: Tuesday, March 27, 2012 3:55:05 PM
> Subject: [Puppet Users] Arrays from templates
>
> Hi,
>
> I am having an issue trying to use the inline_template function to
> return an array. This is what I do:
>
> $array = inline_template ("<%= a=['a1','b2','c3']; a %>")
> notify {"array: ${array}":}

inline_template can only return strings, not arrays or hashes.

You'll need to write a parser function

Reply all
Reply to author
Forward
0 new messages