![](/img/trans.png)
[英]How can you zip or unzip from the script using ONLY Windows' built-in capabilities?
[英]How can I unzip a zip file in windows using puppet script
我是木偶的新手我想解压缩一个保存在木偶窗口代理中的zip文件。
class ziptest {
exec {"test" :
command =>'unzip Test.zip',
cwd => 'D:\',
path => 'D:\',
}
}
执行时我收到错误:
COULD NOT FIND COMMAND UNZIP
这是一个用于Windows配置的木偶模块 ,包括解压缩类型。
我无法使用Win7上的模块counsyl / windows解压缩存档。 相反,我有另一个有效的解决方案。 问题是,Windows没有内置的命令行工具来解压缩档案。
解决方案:1。在代理上复制7za.exe( 在此处下载:www.7-zip.org )2。运行exec以解压缩文件
如何复制7za:
class sevenzip {
$location = '\\SERVER\path\7za920\7za.exe'
$local_file = 'C:\Windows\System32\7za.exe'
file { $local_file:
ensure => file,
source => $location,
source_permissions => ignore
}
}
如何运行7za:
class install_updates_win {
$location = '\\SERVER\path\PSWindowsUpdate.zip'
$local_file = 'C:\PSWindowsUpdate.zip'
$destination = 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate'
file { $local_file:
ensure => file,
source => $location,
source_permissions => ignore,
}
exec { 'extract-pswindowsupdate':
command => "C:\Windows\System32\cmd.exe /c C:/Windows/System32/7za.exe e $local_file -o$destination -y",
cwd => 'C:/',
logoutput => true,
}
}
我也是傀儡的新手,也有同样的问题。 :)可以使用ps模块从puppet调用powershell: https : //forge.puppet.com/puppetlabs/powershell
exec { "unzip" :
command => "Expand-Archive -Path $source -DestinationPath $destination -Force",
provider => powershell,
logoutput => true,
}
或者没有模块只调用ps.exe
exec { "unzip":
command => "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -command Expand-Archive -Path $source -DestinationPath $destination -Force",
logoutput => true,
}
我正在使用需要PS 4的扩展存档,所以我必须做一些版本检查以确保安全。
我想你可以编写一个在Linux机器上使用unzip和在Windows机器上使用PS的类。
define zip::expandarchive($source, $destination) {
if $::kernel == 'windows' {
exec { "unzip with ps ($source, $destination)":
command => "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -command Expand-Archive -Path $source -DestinationPath $destination -Force",
logoutput => true,
}
}
else {
exec { "unzip ($source, $destination)":
command => "unzip -o -d $destination $source",
logoutput => true,
}
}
}
用法:
zip::expandarchive { 'ziptest' :
source => 'D:/Test.zip',
destination => 'D:',
}
使用cygwin似乎也可以正常工作,但是在安装时需要选择zip和解压缩工具。 另外将bin文件夹添加到PATH不起作用,因此您需要完整路径(如果您知道如何解决此问题,请告诉我):
exec { 'unzip package':
command => "c:/cygwin64/bin/unzip.exe -o -d $destination $source",
logoutput => true,
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.