您可以使用来自 RIPienaar 的大量提示中的“数组中的内容”提示:
首先定义一个处理链接的函数,然后将数组传递给该函数。
该函数将为数组中的每个项目调用一次。
代码示例时间:
exec { "exec1":
command => "/bin/echo 'i am the very model of a modern major general'";
}
file {
"/var/tmp/file1":
ensure => present;
"/var/tmp/file2":
ensure => present;
}
define chaintest() {
notify{"Calling chaintest with ${name}": }
Exec["exec1"] -> File["${name}"]
}
$files = ["/var/tmp/file1","/var/tmp/file2"]
chaintest{$files: }
Ubuntu 12.04 上 puppet 2.7.11 上的“puppet apply test.pp”的输出给出:
notice: Calling chaintest with /var/tmp/file1
notice: /Stage[main]//Chaintest[/var/tmp/file1]/Notify[Calling chaintest with /var/tmp/file1]/message: defined 'message' as 'Calling chaintest with /var/tmp/file1'
notice: /Stage[main]//Exec[exec1]/returns: executed successfully
notice: Calling chaintest with /var/tmp/file2
notice: /Stage[main]//Chaintest[/var/tmp/file2]/Notify[Calling chaintest with /var/tmp/file2]/message: defined 'message' as 'Calling chaintest with /var/tmp/file2'
notice: Finished catalog run in 0.11 seconds