简体   繁体   English

仅在未安装Windows MSI软件包的情况下,才需要通过p复制文件

[英]Need to copy a file via puppet only if a Windows MSI package is not installed

I'm new using puppet on Windows. 我是在Windows上使用up的新手。 I'm trying to install a MSI package from a shared folder on our network, but do to permissions, the shared folder is "read" only, it does not have "execute" permissions so when the puppet agent runs and tries to install the MS, it fails. 我正在尝试从我们网络上的共享文件夹安装MSI软件包,但是要获得权限,共享文件夹是“只读”的,它没有“执行”权限,因此当木偶代理运行并尝试安装时, MS,它失败。

What I want to do is to copy the MSI installer to a local directory ONLY if the package needs to be installed. 我要做的是仅在需要安装软件包的情况下才将MSI安装程序复制到本地目录。

This is how I'm installing the package and copying to a local dir: 这就是我安装软件包并将其复制到本地目录的方式:

class app_install {
    package { '7-Zip 9.38 (x64 edition)':
        provider => windows,
        ensure   => installed,
        source => 'c:\\temp\7zip_testInstall.msi',
        install_options => ['INSTALLDIR=C:\apps64\7-Zip'],
    }
    file { 'c:/temp/7zip_testInstall.msi':
        ensure => 'file',
        mode   => '0660',
        group  => 'Domain Users',
        source => 'c:\\temp\7zip_testInstall.msi',
     }

} }

When I run puppet and it finds that the package is not installed, it copies the file to ac:\\temp, then proceeds to install the package. 当我运行puppet并发现未安装该软件包时,它将文件复制到ac:\\ temp,然后继续安装该软件包。 This is the expected behavior. 这是预期的行为。 On subsequent runs of the puppet agent, it finds that the package is already installed, so it skips the installation, but then proceeds to copy the installer to c:\\temp again if the installer is missing from c:\\temp - given the fact that this is a temp folder, it gets purged every so often. 在随后运行puppet代理时,它会发现该软件包已安装,因此跳过安装,但是如果c:\\ temp中缺少安装程序,则会继续将安装程序再次复制到c:\\ temp-鉴于事实这是一个临时文件夹,它经常被清除。

What I'm trying to avoid is to copy the installer if the package is already installed. 我要避免的是如果软件包已安装,则复制安装程序。

I'm not sure how to go about it. 我不确定该怎么做。

Please advise and thanks! 请指教,谢谢!

Fr3edom21. Fr3edom21。

I was able to answer my on question. 我能够回答我的问题。

Instead of using the "file resource" to copy the MSI from the network share to c:\\temp, I ended up executing a file copy via the "exec resource" only if the Uninstall registry key version value for said program is missing. 我没有使用“文件资源”将MSI从网络共享复制到c:\\ temp,仅在缺少该程序的卸载注册表项版本值的情况下,才通过“ exec资源”执行文件副本。 Like this: 像这样:

exec { 'copy MSI to c:\temp':
command => 'C:\\windows\system32\cmd.exe /c "copy \\server\repo\7zip_testinstall.msi c:\\temp"',
unless => 'C:\Windows\System32\reg.exe query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{23170F69-40C1-2702-0938-00000100000 /f 9.38.00.0',
}

I hope this helps anyone with similar problem. 希望这对有类似问题的人有所帮助。

A couple of things to consider if you go this route: 如果您选择这条路线,请注意以下几点:

  • If you are on the 32-bit version of Puppet on a 64-bit machine, C:\\Windows\\System32 is actually redirected (by Windows' File System Redirector ) to C:\\Windows\\SystemWOW64 where the 32-bit system32 binaries live. 如果您在64位计算机上使用Puppet的32位版本,则C:\\Windows\\System32实际上(通过Windows的File System Redirector重定向C:\\Windows\\SystemWOW64位system32二进制文件C:\\Windows\\SystemWOW64其中。 If you want the 64-bit system32 binaries, you should consider using c:\\Windows\\sysnative . 如果要使用64位system32二进制文件,则应考虑使用c:\\Windows\\sysnative If you are on the 64-bit version of Puppet, you don't fall subject to this issue and should not use sysnative as it doesn't exist. 如果您使用的是64位版本的Puppet,则不会受到此问题的影响,并且不应使用sysnative,因为它不存在。 If you are on Puppet 3.7.3+, you can use the $system32 fact to handle mixed environments. 如果使用Puppet 3.7.3+,则可以使用$system32事实来处理混合环境。 For more information see Handling File Paths on Windows . 有关更多信息,请参见在Windows上处理文件路径
  • HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall is one of four different possible locations. HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall是四个可能的位置之一。 Again with 32-bit Puppet, you are subject to registry redirection unless you are using the Registry module. 同样,对于32位Puppet,除非使用注册表模块,否则您将受到注册表重定向的约束。 If the software can be installed as 32-bit, you may need to check whether it also exists at HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall as well if you are running 64-bit Puppet or not subject to the registry redirector. 如果该软件可以32位安装,则可能需要检查它是否也存在于HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall (如果您正在运行64位Puppet或不受注册表限制)重定向器。

Fr3edom21. Fr3edom21。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM