检查文件是否存在,如果存在则将其删除

时间:2016-11-04 22:49:56

标签: puppet

我的问题是:我想检查/tmp文件夹中是否存在文件,并在重新开始下载之前将其删除。

这是我的代码(Puppet):

exec { 'Download mediawiki to temp':
  cwd     => '/tmp',
  command => '/usr/bin/wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.1.tar.gz',    
}

1 个答案:

答案 0 :(得分:0)

你可能想要这样做......

# local vars for readability
$theurl       = 'https://releases.wikimedia.org/mediawiki/1.27'
$tarball      = 'mediawiki-1.27.1.tar.gz'
$wget_command = "/usr/bin/wget $theurl/$tarball"
$rm_command   = "/bin/rm -f /tmp/$tarball"

exec { 'Delete mediawiki from temp':
    cwd     => '/tmp',
    command => $rm_command,
}-> 
exec { 'Download mediawiki to temp':
    cwd     => '/tmp',
    command => $wget_command,
    creates => "/tmp/$tarball",
}

请参阅https://docs.puppet.com/puppet/latest/reference/types/exec.htmlhttps://docs.puppet.com/puppet/latest/reference/lang_relationships.html