up:如果存在一个文件,则复制另一个文件
我试图弄清楚如何使我的人偶模块正常工作,因此我需要测试客户端上是否存在文件(如果存在),然后复制另一个文件。如果该文件不存在,则不执行任何操作。我似乎无法正常工作。这是我的模块:
I am trying to figure out how to make my puppet module work such I need to test if file exists on the client, if it does, then copy another file over. If the file does not exist then do nothing. I can't seem to get it working. Here is my module:
类网络日志:: config {
class web-logs::config {
# PATH TO LOG FILES
$passenger='/var/tmp/puppet_test/passenger'
# PATH TO LOGROTATE CONFIGS
$passenger_logrotate='/var/tmp/puppet_test/logrotate.d/passenger'
exec { 'test1':
onlyif => "test -f $passenger",
path => ['/usr/bin','/usr/sbin','/bin','/sbin'],
refreshonly => true,
} ~>
exec { 'test2':
require => Class['web-logs::passenger']
}
和Class [' web-logs :: passenger']看起来像这样:
And the Class['web-logs::passenger'] looks like this:
class web-logs::passenger {
file { 'passenger':
path => '/var/tmp/puppet_test/logrotate.d/passenger',
owner => 'root',
group => 'root',
mode => '0644',
source => "puppet://${puppetserver}/modules/web-logs/passenger.conf",
}
}
任何帮助将不胜感激!
执行程序由于您失踪而失败要执行的命令。现在,由于文件资源中的exec要求失败,一切都失败了。这应该可以解决问题:
The exec is failing since you are missing the command to execute. Right now everything fails because of the failing exec requirement in the file resource. This one should do the trick:
exec { 'test1':
command => "/bin/true",
onlyif => "test -f $passenger",
path => ['/usr/bin','/usr/sbin','/bin','/sbin'],
}
# Check if passenger file exists then push logrotate module for passenger
file { 'passenger':
path => '/var/tmp/puppet_test/logrotate.d/passenger',
owner => 'root',
group => 'root',
mode => '0644',
source => "puppet://${puppetserver}/modules/web-logs/passenger.conf",
require => Exec["test1"],
}
如果您对以下消息感到不安,命令已在每次运行中成功执行,您可以尝试修改exec
If you get disturbed by the message that the command has been successfully executed on each run you could try to modify the exec like this
exec { 'test1':
command => "/bin/false",
unless => "test -f $passenger",
path => ['/usr/bin','/usr/sbin','/bin','/sbin'],
}