【问题标题】:Iteration a set number of times with puppet使用 puppet 迭代一定次数
【发布时间】:2020-01-29 22:28:24
【问题描述】:

puppet 中是否有任何方法可以迭代一定次数?例如,如果我给出数字“5”,我希望它创建一个名为 1,2,3,4,5 的文件(这只是一个示例,希望它能解释用例)。

这与 each 函数不同,它会遍历数组中的每个元素,因为数组需要包含 5 个元素。在 ruby​​ 中有一个名为 times 的函数,但我在 puppet 中找不到类似的东西。

谢谢

【问题讨论】:

  • 看起来 stdlib 中的 range 函数可能是一个可行的选择。

标签: puppet


【解决方案1】:

根据documentation for the range function,迭代一定次数的正确习语是

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

range 函数用于生成连续整数或字符串的数组,而不是迭代。例如,如果你想创建一组 10 个文件,file0file9,你可以使用

include stdlib

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 2018-06-10
    • 2021-05-22
    • 2011-04-10
    相关资源
    最近更新 更多