RIPienaarのヒントのこのすばらしいリストから、「配列の内容」ヒントを使用できます。
最初に連鎖を処理する関数を定義してから、配列を関数に渡します。
関数は、配列内のアイテムごとに1回呼び出されます。
コードサンプル時間:
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: }
Ubuntu12.04のpuppet2.7.11での「puppetapplytest.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