Reputation: 18649
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?
Upvotes: 1
Views: 2339
Reputation: 6818
Modern Puppet you can simply use the data type directly:
Integer[1,10].each |$i| { notice($i) }
Upvotes: 1
Reputation: 1
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)
Upvotes: 0
Reputation: 8223
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| { ... }
Upvotes: 4