Passing the parameter at the time of msi installation


I want to install the msi package. At the time of installation i want to change the installation directory. So I need to pass my custom path in windows_package.

can anybody tell me how to achieve it.


Hi @ramaduraiu

I think the easiest way to change the path is to store the path in an attribute, this can then be overridden at node, environment or role level.

Say for example you want to install 7-zip and the 7-zip install EXE will reside in C:\Installers\7-Zip

In your attributes file

default['7-zip']['install_path'] = 'C:\Installers\7-zip'

In your resource (package or windows_package)

windows_package '7-zip' do
  source File.join(node['7-zip']['install_path'], '7zip.exe')
  action :install

In your environment (or knife node edit for individual servers)

node.default['7-zip']['install_path'] = 'D:\Installers'

However, when using attributes my preference is to create a single attribute where possible and pull out sub elements.

For example, take the installer, I would create an attribute with path

default['7-zip']['installer'] = 'C:\Installers\7-zip\7zip.exe'

In recipe pull out the component parts

7z_exe_name = File.basename(node['7-zip']['installer'])
7z_exe_path = File.dirname(node['7-zip']['installer'])

Of course, solutions doesn’t fit all situations.


You can use options property in windows_package.

windows_package “package_name” do
source 'package.msi’
options 'path here’

I have tried it . it not works for me.

I have tried to use above attributes.but it not works for me. I have attached the my attribute and recipe contents .
Please have a look at it and do the needful

node.default[‘SourceGear DiffMerge (x64)’][‘install_path’] = ‘C:\chefs’


windows_package "installDiffMerge" do
source File.join(node['SourceGear DiffMerge (x64)']['install_path'], 'DiffMerge_4.2.0.697.stable_x64.msi')	
installer_type :msi
action :install    



Hi @ramaduraiu

Oh dear, I’m sorry that my recommendation did not work.

There are two windows_package resources that I know of, one comes with the Windows cookbook, the other is built in to Chef but they both offer similar functionality.

My understanding is that the location or filename of the package you want to install will change at runtime, is this correct? Is the file on the local file system?

If the file is on the local file system the code you supplied should work, according to the documentation the source method for windows_package should allow for a path or URI.

I’d make a couple of changes though if both location and filename will change to give more clarity to the code

attributes file

default['merge_diff']['location''] = 'c:\chef' 
default['merge_diff']['installer''] = 'DiffMerge_4.2.0.697.stable_x64.msi' 


windows_package "install diff merge" do
   source File.join(node['merge_diff']['location''], node['merge_diff']['installer''])
   installer_type :msi
   action :install

In your .kitchen.yml file

- name: a_test_suite
  run_list: ["recipe[test_stuff]"]
      location: "d:\\install_folder"

If, however you want to change the location that the Merge Diff file installs to then @sasisai is correct, you need to pass in command line parameters to the package you are installing using the options method.

If the package you want to install is SourceGear DiffMerge then I cannot find the appropriate silent installation parameters, the best documentation I could find was here

The instructions simply say “This will install the application in Program Files”.

Unfortunately I do not have the Windows SDK/Orca or an MSI package manager installed on my current developer machine here so cannot interrogate the MSI table to see if there are any properties to set the installation folder.

However it looks like the DiffMerge package is simple installer (I could be wrong), so I downloaded it to my temp folder and extracted it with the following

msiexec /a c:\temp\DiffMerge_4.2.0.697.stable_x64.msi /qb TARGETDIR=c:\temp\merge

The folder structure was


There was an EXE called sgdm, is this what you want?

Therefore in a Chef recipe you might be able to set the TARGETDIR for windows_package

windows_package 'c:\temp\DiffMerge_4.2.0.697.stable_x64.msi' do
    options "/q TARGETDIR=c:\temp\merge"
    action :install

NB: all we are doing is extracting the EXE NOT installing DiffMerge, therefore the Windows Package resource will not be idempotent unless you put an only_if guard to check for the existence of a sentinel file.

HI Chris_Sullivan

Thank you very much. I have done some changes in option line.

options “/qb TARGETDIR=c:\temp\merge”. it works for me.

I have got one more scenario like I want to pass targetdir and weburl parameters at the time of installation.

Can you tell how can we pass it .


Hello @ramaduraiu

The options are used to create the statement that is executed by the OS so add as much as you like

windows_package 'c:\temp\DiffMerge_4.2.0.697.stable_x64.msi' do
options "/q TARGETDIR=c:\temp\merge weburl='your url'"
action :install

What you will need to be careful about is the use of single and double quotes as you may have to end up escaping them which makes for confusing statements.

As said, the above is not an idea solution you really need to have a dedicated command line parameter for destination folder.

Thank you. it is working fine.