Search code examples
puppet

Puppet iterating over a given number range with the each funciton


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?


Solution

  • 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| { ... }