我正在尝试使用以下代码,只有在某个文件不存在时才会执行某些操作。如果文件存在,则应跳过该任务。我无法让它发挥作用。
exec {"is_file_there":
command => "true",
path => ["/usr/bin","/usr/sbin","/bin"],
unless => "test -e /tmp/some_file",
}
somecommand {
..
..
require => Exec['is_file_there'],
}
作为一个例子,我尝试使用文件,但即使这样也行不通。这仅仅是为了证明这个问题的一个例子。
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。关于文件的例子只是一个例子
答案 0 :(得分:1)
根据https://puppet.com/docs/puppet/7/types/exec.html#exec-attribute-creates,如果文件不存在,“exec”中的“creates”选项只会运行“command”:
exec {"is_file_there":
command => "some_action_command",
path => ["/usr/bin","/usr/sbin","/bin"],
creates => "/tmp/some_file",
}
答案 1 :(得分:0)
您可以尝试这样的事情:
exec {"Some title":
command => "Your command",
path => ["/usr/bin","/usr/sbin","/bin"],
unless => "test -e /tmp/some_file",
}
因此,您的命令将执行,除非 test -e /tmp/some_file
的结果成功(退出代码0),即文件存在。