简体   繁体   中英

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

I'm new using puppet on Windows. 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.

What I want to do is to copy the MSI installer to a local directory ONLY if the package needs to be installed.

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. 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.

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.

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. 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. If you want the 64-bit system32 binaries, you should consider using 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. If you are on Puppet 3.7.3+, you can use the $system32 fact to handle mixed environments. For more information see Handling File Paths on Windows .
  • HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall is one of four different possible locations. Again with 32-bit Puppet, you are subject to registry redirection unless you are using the Registry module. 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.

Fr3edom21.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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