Problem with usage of arrays

285 views
Skip to first unread message

Roband

unread,
Jun 16, 2011, 5:36:10 AM6/16/11
to Puppet Users
Hi there,

i can't use array in puppet. Here is my codesnipplet:

$callapidata = [ 'wert1','wert2']
notice $callapidata[1]

A puppetrun results in:

Could not retrieve catalog from remote server: Error 400 on SERVER:
can't convert String into Integer at /etc/puppet/myenv/modules/
uc4client/manifests/init.pp:41 on node testnode


Thanks for your help.


Greetings
Roband

Gabriel Filion

unread,
Jun 16, 2011, 1:57:04 PM6/16/11
to puppet...@googlegroups.com, Roband
Talking a bit through my hat here.. but:

On 11-06-16 05:36 AM, Roband wrote:
> i can't use array in puppet. Here is my codesnipplet:
>
> $callapidata = [ 'wert1','wert2']
> notice $callapidata[1]

try something like the following instead of the second line:

notice { $callapidata[1]: }

--
Gabriel Filion

Ken Barber

unread,
Jun 16, 2011, 3:47:59 PM6/16/11
to puppet...@googlegroups.com
What version of puppet are you using?

kbarber:~ ken$ puppet --version
2.6.8
kbarber:~ ken$ puppet -e '$callapidata = [ 'wert1','wert2'] notice
$callapidata[1]'
notice: Scope(Class[main]): wert2
notice: Finished catalog run in 0.01 seconds
kbarber:~ ken$

ken.

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
>

Roband

unread,
Jun 17, 2011, 5:28:17 AM6/17/11
to puppet...@googlegroups.com, Roband
Hi,

I tried

notice { $callapidata[1]: }

=> Same Error:

Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert String into Integer at /etc/puppet/myenv/modules/uc4client/manifests/init.pp:41 on node testnode

I use version 2.6.1

Roband

unread,
Jun 17, 2011, 7:43:42 AM6/17/11
to puppet...@googlegroups.com, Roband
http://projects.puppetlabs.com/issues/5127


Addressing array by index is not possible with Version 2.6.1

Unfortunately we can't update our puppet :-(


Tahnk you all for your help.

elderdakkar

unread,
Jun 22, 2011, 4:48:57 AM6/22/11
to puppet...@googlegroups.com
same problem here:

puppet version is 2.6.1. That's the most recent version available in Ubuntu Maverick (10.10). Any chance, that a more recent version will be available in ubuntu maverick?

greetings

Bob

unread,
Jul 18, 2011, 8:11:50 PM7/18/11
to Puppet Users
I know it's a ugly hack, but this saved me:

$myarray = ['1', '2', '3']

$var0 = inline_template("<%=myarray.split(',')[0]%>")
$var1 = inline_template("<%=myarray.split(',')[1]%>")

--
Bob

Nan Liu

unread,
Jul 18, 2011, 8:32:32 PM7/18/11
to puppet...@googlegroups.com

Should this be:
$var0 = inline_template("<%=myarray[0]%>")

If this type of feature is needed it can be provided via puppet
function. The examples here
https://github.com/puppetlabs/puppetlabs-functions can provide a jump
start for converting any quick hacks via inline_template to something
that's much more maintainable.

Thanks,

Nan

Reply all
Reply to author
Forward
0 new messages