Puppet清单解压缩Windows主机上的压缩文件

时间:2015-10-05 12:33:08

标签: windows puppet-enterprise

我一直收到错误'无法找到命令'C:\ puppetfolder \ unzip.exe'或'找不到命令'C:\ puppetfolder \ 7-Zip.exe'无论我尝试哪一个...基本上我都是尝试将压缩文件(server.zip)解压缩到目录C:\ puppetfolder中。 Puppet能够在C:\ puppetfolder \目录中下载7z1507.exe和unzip.exe,因此执行是他们的。但是我应该在命令属性中使用extract,unpack,unzip或7zip来获取此server.zip文件以解压缩到同一目录中吗?或者我的论点对于这个用例是错误的吗?

- >   file {'C:\ puppetfolder \ 7z1507.exe':

Invoke-Command -computerName:$machine -argumentList: $file, $context –scriptblock {
    param (
        [String]$file,
        [string]$context
    )

    $sb = [ScriptBlock]::Create((Get-Content $file -Raw))
    & $sb -context:$context

} -credential:$credential -authentication:CredSSP –asJob -jobName:$machine > $null

}

- >   file {'C:\ puppetfolder \ unzip.exe':

ensure   => 'present',
provider => 'windows',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',

}

- >

file {'C:\ puppetfolder \ server.zip':

ensure  => 'present',
mode    => '0775',
owner   => 'Administrator',
group   => 'Administrator',

}

- >   exec {'unzip_c:\ puppetfolder \ server.zip':

ensure   => 'file',
source   => 'puppet:///modules/downloadscript/server.zip',
checksum => 'mtime',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',

}

- >   exec {'install_c:\ puppetfolder \ downloadtest.ps1':

 path         => 'c:\\puppetfolder\\unzip.exe',
command      => "C:\\puppetfolder\\unzip.exe /c C:\\puppetfolder\\server.zip C:\\puppetfolder -y",
provider     =>  'windows',

} }

1 个答案:

答案 0 :(得分:0)

forge reidmv-unzip上有一个模块,它将提供解压缩类型。

puppet module install reidmv-unzip

然后您可以定义zip内容的来源和目的地。源必须是Windows系统上的本地文件。

使用该类型,您的清单将被重写为以下内容:

file { 'C:/puppetfolder/server.zip':
  ensure   => 'file',
  source   => 'puppet:///modules/downloadscript/server.zip',
  checksum => 'mtime',
  mode     => '0775',
  owner    => 'Administrator',
  group    => 'Administrator',
}
->
unzip { 'server-file':                            
  source  => 'C:/puppetfolder/server.zip',               
  creates => 'C:/puppetfolder/downloadtest.bat',                                                                            
}
->
exec { 'install_c:/puppetfolder/downloadtest.ps1':
  command     => 'C:/puppetfolder/downloadtest.bat',
  logoutput   => 'true',
  provider    => 'windows',
}