Puppet仅在文件不存在时执行命令

Puppet仅在文件不存在时执行命令,puppet,Puppet,我正在尝试使用以下代码,只有当某个文件不存在时,这些代码才应该执行某些操作。如果文件存在,则应跳过该任务。我不能让它工作 exec {"is_file_there": command => "true", path => ["/usr/bin","/usr/sbin","/bin"], unless => "test -e /tmp/some_file", } somecommand { .. .. require => Exec['is

我正在尝试使用以下代码,只有当某个文件不存在时,这些代码才应该执行某些操作。如果文件存在,则应跳过该任务。我不能让它工作

exec {"is_file_there":
  command => "true",
  path    => ["/usr/bin","/usr/sbin","/bin"],
  unless  => "test -e /tmp/some_file",
}

somecommand {
  ..
  ..
  require => Exec['is_file_there'],
}
例如,我尝试使用file,但即使这样也不起作用。这只是一个例子,目的是说明这个问题

exec {"is_file_there":
  command => "true",
  path    => ["/usr/bin","/usr/sbin","/bin"],
  unless  => "test -e /tmp/some_file",
}

file {'/tmp/success'
  ensure => present,
  require => Exec['is_file_there'],
}

编辑:我试图在另一个资源和exec之间创建依赖关系。其他资源不允许onlyif。关于文件的示例只是一个示例

您可以尝试以下内容:

exec {"Some title":
  command => "Your command",
  path    => ["/usr/bin","/usr/sbin","/bin"],
  unless  => "test -e /tmp/some_file",
}

因此,您的命令将执行,除非
test-e/tmp/some_file
的结果是成功(退出代码0),即文件存在。

可能与Not really@Matt重复。在本例中,我试图在另一个资源(不允许onlyf)和exec之间创建依赖关系。关于file的例子就是一个example.Puppet不是这样工作的-早期的exec将仅在条件被评估时才使用它的,而不是执行命令,并且文件资源将发生在exec之后,不管它是否执行命令。如果您希望根据文件的存在有条件地应用puppet代码,则该代码必须存在或不存在pre-factor run,并具有自定义事实以将有关文件存在的信息发送给puppet master。