当文件不存在时,傀儡唯一的exec

当文件(/ usr / local / bin / papply)不存在时,我只想执行下面的命令。 不知道该放什么。

exec { 'git add url': command =>'git remote add origin https://github.com/testing/puppet.git', require => Exec['git init'], cwd => '/home/vagrant/django', user => 'vagrant', onlyif => "not sure what to put here" } 

你尝试过吗?

 onlyif => "test ! -f /usr/local/bin/papply" 

不确定Puppet是否可以使用“!” 字符

也许更好的永恒:

 creates => '/usr/local/bin/papply' 

即使我不喜欢这个命令并不真正创build文件的事实

如果你在Linux上只是做

 unless => 'ls /somefile' 

如果文件不存在,ls将返回一个非零的返回码,除非只有当它的testing返回一个非零的返回码时才会执行exec。

在linux和puppet> 3.8上试试:

 exec { 'test': command => '/bin/echo HI', unless => 'test -f /a/file.txt', } 

如果/a/file.txt存在,exec将不会运行。

您可能要考虑使用创build ,这是为此目的而存在的:

 exec { 'git add url': command => 'git remote add origin https://github.com/testing/puppet.git', creates => '/usr/local/bin/papply' }