0

私が持っているとしましょう:

$files = ["file1", "file2"]
exec { "exec1" :
    command => "mycommand";
}
file { $files :
    ensure => present;
}

->そして、次のように、 and~>構文を使用して、実行の通知/要求の順序を制御したいと思います。

Exec["exec1"] -> File[$files]

どうすればいいのですか?

上記を実行すると、次のようになりますCould not find resource 'File[file1]File[file2]'(もちろん、実際のファイルパスの場合)。$files変数を引用符と{}でラップして遊んだことがありますが、役に立ちません。

リソース名の配列変数を順序付けチェーンに入れるための構文は何ですか?

4

2 に答える 2

2

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
于 2012-06-21T17:46:40.980 に答える
0

代わりにrequireを使用しないのはなぜですか?

$files = ["file1", "file2"]
exec { "exec1" :
    command => "mycommand";
}
file { $files :
    ensure => present;
    require => Exec["exec1"]
}

または単にする

Exec["exec1"] -> [File["file1"], File["file2"]]
于 2012-06-20T18:05:06.590 に答える