Search code examples
windowspowershellchef-infraguard

chef windows_package guards exists?


I have a windows_package resource that installs jdk 8 on a windows machine and it looks like this:

java_source="C:\\chef_solo\\utils\\jdk-8u121-windows-x64.exe"
package_name="Java(TM) SE Development Kit 8 (64-bit)"
windows_package package_name do
  source java_source
  action :install
  installer_type :custom
  options "/s #{additional_options}"
end

The problem is that every chef run, it install the same jdk and after the 2nd installation, java is not working anymore.

I was looking for windows_package guards, but couldn't find any. That's because they do not exists?

Anyway, I've found some powershell solutions that check if java exists and I need to know if I can use them somehow as a guard for my windows_package installation.

The solutions are here: How to get the Java version in PowerShell


Solution

  • Guard clauses are a core feature available on all resources, so there is nothing specific to windows_package to find. You can find detailed info on not_if, only_if, and guard_interpreter in the Chef docs.