1

I get two integer's passed into a puppet class and I want to loop over resources based on the range of integers between the two. I can't quite figure out the syntax to do so. The best I have is similar to the following:

e.g.
$start_int=4
$end_int=15

$end_int.each |$number| { if $number >= $start_int {...} }

Is there a better way to loop over a given integer range?

3 Answers 3

4

You can create an actual array and iterate that. Sadly, the stdlib range function will not yet accept actual numbers (at the time of writing this) so you will need to convert to String.

range("$start_int", "$end_int").each |$number| { ... }
1
  • Both start and end are inclusive in range function. ex: range("0", "3") will return: [0,1,2,3]
    – VanagaS
    May 19, 2020 at 15:16
1

Modern Puppet you can simply use the data type directly:

Integer[1,10].each |$i| { notice($i) }
0

Today Puppet accepts integers as arguments for range, so the accepted answer could be rephrased to:

range($start_int, $end_int).each |$number| { ... }

(so the quotes around $start_int and $end_ind are no longer necessary)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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