我是puppet新手,想要在puppet的Windows代理中解压缩一个zip文件。
class ziptest {
exec {"test" :
command =>'unzip Test.zip',
cwd => 'D:\',
path => 'D:\',
}
}
执行时出现错误:
COULD NOT FIND COMMAND UNZIP
我无法使用counsyl/windows模块在Win7上解压缩存档。相反,我有另一个有效的解决方案。问题是,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
}
}
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,
}
}
我也是刚接触 Puppet,遇到了同样的问题。:) 可以使用 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 机器上使用解压缩,在 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和unzip工具。此外,将bin文件夹添加到PATH中不起作用,因此您需要完整的路径(如果您知道如何解决此问题,请告诉我):
exec { 'unzip package':
command => "c:/cygwin64/bin/unzip.exe -o -d $destination $source",
logoutput => true,
}