puppet:如果存在一个文件,则复制另一个文件

时间:2015-07-16 20:02:52

标签: file copy exec puppet

我正在试图弄清楚如何使我的木偶模块工作,我需要测试客户端上是否存在文件,如果存在,则复制另一个文件。如果文件不存在则不执行任何操作。我似乎无法让它发挥作用。这是我的模块:

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']
  }

班级[' web-logs :: passenger']看起来像这样:

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",
  }
}

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

exec失败,因为您缺少要执行的命令。现在一切都因为文件资源中的exec要求失败而失败。这个应该做的伎俩:

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

exec { 'test1':
  command => "/bin/false",                                             
  unless  => "test -f $passenger",                            
  path    => ['/usr/bin','/usr/sbin','/bin','/sbin'],
}

答案 1 :(得分:0)

删除exec test2。没有必要。您需要require exec test1file passenger 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", require => Exec["test1"], } } 。像这样:

glVertexAttribPointer(mvPositionHandle, 3, GL_FLOAT, GL_FALSE, 0, quadverts);