Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Puppet语法:如何将对象数组包含到排序中->;链条_Puppet - Fatal编程技术网

Puppet语法:如何将对象数组包含到排序中->;链条

Puppet语法:如何将对象数组包含到排序中->;链条,puppet,Puppet,假设我有: $files = ["file1", "file2"] exec { "exec1" : command => "mycommand"; } file { $files : ensure => present; } 我想使用->和~>构造来控制notify/require的执行顺序,如下所示: Exec["exec1"] -> File[$files] 我该怎么做 如果我执行上述操作,我将无法找到资源“File[file1]File[file2]

假设我有:

$files = ["file1", "file2"]
exec { "exec1" :
    command => "mycommand";
}
file { $files :
    ensure => present;
}
我想使用
->
~>
构造来控制notify/require的执行顺序,如下所示:

Exec["exec1"] -> File[$files]
我该怎么做

如果我执行上述操作,我将无法找到资源“File[file1]File[file2]”(当然是真正的文件路径)。我用引号和{}来包装
$files
变量,但没有用


将资源名称的数组变量放入排序链的语法是什么?

为什么不使用require

$files = ["file1", "file2"]
exec { "exec1" :
    command => "mycommand";
}
file { $files :
    ensure => present;
    require => Exec["exec1"]
}
还是就这么做

Exec["exec1"] -> [File["file1"], File["file2"]]

您可以从以下位置使用“数组中的内容”提示:

首先定义一个处理链接的函数,然后将数组传递给该函数。
该函数将为数组中的每个项调用一次

代码采样时间:

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上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

因为实际的应用程序要大得多,具有更大的文件数组、更多的资源链,并且由更多的人处理。如果我愿意在每个对象中使用requires,我有很多方法可以让它工作,但是人们最终会犯错误。