Usman Ismail
Usman Ismail

Reputation: 18649

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?

Upvotes: 1

Views: 2339

Answers (3)

h0tw1r3
h0tw1r3

Reputation: 6818

Modern Puppet you can simply use the data type directly:

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

Upvotes: 1

Marc Ihm
Marc Ihm

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

Felix Frank
Felix Frank

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

Related Questions