如果“exec”成功,木偶“要求”忽略

exec { "check_presence": command => "/bin/true", onlyif => '/usr/bin/test -e /path', } file {"/home/user/test.txt": ensure => file, require => Exec["check_presence"] } 

我无法弄清楚我的脚本有什么问题。 我用puppet apply test.pp来运行这个脚本。 但不pipe是否存在,文件test.txt都已创build。

我正在使用木偶3.4.3。 任何帮助表示赞赏。

相关的答案: https : //serverfault.com/a/516919/428218

要做到这一点的唯一方法(即只有在其他条件为真或假时才pipe理目标文件)是为该条件/testing创build一个自定义事实,然后用它来将资源包装在一个条件块中,或者使用它影响资源的属性/参数。 例如:

 if $::mycustomfact { file { '/home/user/test.txt': ensure => file, ... } } 

要么:

 file { '/home/user/test.txt': ensure => $::mycustomfact ? { true => file, default => absent, }, ... } 

在使用Puppet进行pipe理之前,您不需要检查文件是否已经存在,如果文件已经存在,Puppet会强制configuration状态。 如果它不存在,Puppet会用你configuration的状态创build它。

如果你不指定内容/所有者/组/模式,Puppet只会确保文件存在,如果不存在,将会创build一个空文件。