keeer
keeer

Reputation: 863

Iteration a set number of times with puppet

Is there any method in puppet which will iterate a set number of times? e.g if I give the number "5" I'd like it to create a file called 1,2,3,4,5 (this is just an example, hopefully it explains the use case).

This is not the same as an each function which will iterate over every element within an array as the array needs to contain 5 elements. In ruby there's a function called times but I can't find anything similar in puppet.

Thanks

Upvotes: 1

Views: 589

Answers (1)

Jon
Jon

Reputation: 3671

According to the documentation for the range function, the correct idiom for iterating a set number of times is

# notices 0, 1, 2, ... 9
Integer[0, 9].each |$x| {
  notice($x)
}

The range function is for generating an array of consecutive integers or strings, rather than iterating. For example, if you wanted to create a set of 10 files, file0 to file9, you could use

include stdlib

file { range('/tmp/file0', '/tmp/file9'):
  ensure => file,
}

Upvotes: 3

Related Questions