How to code recipe to look for version number and automatically install package

Community Members,

(Windows Installation)
Does anyone have any code for a recipe that when it runs will:

  1. check a repo/share/etc... for a file version
  2. if its greater than the existing version
  3. install

I could use some help... mainly with the #1 and #2. Let me know.

Thank you,

If the file is generated with the same name regardless of the version you can...

Use the remote_file resource to download the installer and the installation should happen idempotently by the package resource if the display name is different.

If the display name is not different then you can use a subscription to kickoff the install when a new file is downloaded.

How do you get Chef to read a config file for versioning stored on a remote storage? I would like to setup a way for chef to read a file for version and run through the logic of whether its greater than the current version installed.

Hi

I do this in Windows quite often, but look it as defining the version i want, so I don't check the version in the repository. If the version of installer is not available then there's an in issue so Chef run fails.

I don't think the package_resource is idempotent for version though, so once downloaded - say v 2.0 - if v1.0 is installed you will need to remove it first.

The way we do this is to define 'version' attribute, e.g.
myapp_version = '1.0'

Then during for install recipe, get current version:

current_version = powershell_out("(Get-Childitem -Path `
                          'HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall') | `
                          Get-ItemProperty | `
                          where-object {$_.DisplayName -eq 'MyApp'} | `
                          Select -ExpandProperty DisplayVersion").stdout.chomp

Next, if it is installed and current version is different from desired version, uninstall it:

if is_package_installed?('MyApp') &&
  current_version != myapp_version
  windows_package 'MyApp' do
    options "/L*V \"C:\\Program Files\\MyApp\\MyApp_#{current_version}_uninstall.log\""
  installer_type :msi
  action :remove
  end
end

Finally, use the windows_package again to install the version you do want.

Hope it helps.