I have a variable $IP = [ "91" , "92" ]and $IPPriveeInstance = "10.248.33.$IP".

You guessed it, I want to use this variable 2 times,but when I print IPPriveeInstance, I got the output as 10.248.33.9192.

link|improve this question
This should be asked on stackoverflow.com. I have put in a request for it to be transferred there. – Caleb Apr 12 '11 at 14:28
2  
@Caleb: Puppet is a programming language, but it's a very specific very limited programming language for system administration. It's totally on topic here, even if it is also on-topic on StackOverflow. – freiheit Apr 12 '11 at 15:06
1  
What are you expecting to print? If you set the IPPriveeInstance variable to one address or the other, you'll only have... one address. Give us more information on what you're trying to accomplish (populating a config file? passing those in to a module?), and we'll be able to help. – Shane Madden Apr 12 '11 at 19:46
Hi im trying to test if files (named with IPPriveeInstance exist in client) so the need of an array as you see.Thanks – bazic Apr 13 '11 at 7:53
feedback

2 Answers

Puppet does not iterate array items. The example below demonstrates with inline_template, but you should use a custom function to perform this task.

$ip      = ['91', '92']
$address = '10.248.33.'
$array   = inline_template("<%= ip.collect{|x| address+x.to_s} %>")

You can also write this via the Ruby DSL: http://projects.puppetlabs.com/projects/1/wiki/Ruby_Dsl

link|improve this answer
feedback

You're trying to reference the full array at once when you want the individual parts of the arrays separately. Try this:

$IPPriveeInstance = "10.248.33.$IP[0]"
$IPPriveeInstance = "10.248.33.$IP[1]"

The first index in an array is always zero.

link|improve this answer
Sorry,but that doesn't seem to be working.Thanks anyway – bazic Apr 12 '11 at 16:11
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.