Use CFengine to install msi Windows packages.
At SURFsara CFengine is used on many systems/clusters, recently we also want to use it on our windows computers. There is not much documentation on using cfengine on windows. This is a short introduction on howto install windows msi packages. There is another blog about this subject and can be found here
This approach is different then the SURFsara method. The SURFsara method has defined a package_method to install and delete the msi packages. You need to download the CFengine entrprise for windows. There is an evaluation version available at:
In our environment the installation must be from a central repository. The repository must be accessible via the http protocol. The msiexec software support the http protocol. The default package_method that are included in the standard CFengine library does not support this functionality. I have written two package_methods to accomplish this.
The first one is to install package via the http protocol. See the code below:
This approach is different then the SURFsara method. The SURFsara method has defined a package_method to install and delete the msi packages. You need to download the CFengine entrprise for windows. There is an evaluation version available at:
In our environment the installation must be from a central repository. The repository must be accessible via the http protocol. The msiexec software support the http protocol. The default package_method that are included in the standard CFengine library does not support this functionality. I have written two package_methods to accomplish this.
The first one is to install package via the http protocol. See the code below:
body package_method sara_msi_install(url, name) # @brief Windows MSI method fot http protocol # @param url The location of the package # @param name The name of the package # # Uses the whole file name as promiser, e.g. "7-Zip-4.50-x86_64.msi". # The name, version and arch is then deduced from the promiser. # { package_changes => "individual"; package_installed_regex => ".*"; package_name_convention => "$(url)/$(name)"; package_delete_convention => "$(url)/$(name)"; package_name_regex => "^(\S+)-(\d+\.?)+"; package_version_regex => "^\S+-((\d+\.?)+)"; package_arch_regex => "^\S+-[\d\.]+-(.*).msi"; package_add_command => '"$(sys.winsysdir)\msiexec.exe" /qn /i'; package_update_command => '"$(sys.winsysdir)\msiexec.exe" /qn /i'; package_delete_command => '"$(sys.winsysdir)\msiexec.exe" /qn /x'; }
The second one is to delete the packages via the product code. You can obtain the product code via Orca program. Open the msi with orca and go to Property->ProductCode. This needed else we must download the package again to delete it.
body package_method sara_msi_delete(name, product_code) # @brief Windows MSI method to delete packages with the product code # @param name The package name # @param product_code The product code of the package. This code is used to delete the package # { package_changes => "individual"; package_installed_regex => ".*"; package_name_convention => "$(name)"; package_delete_convention => "$(product_code)"; package_name_regex => "^.*"; package_add_command => '"$(sys.winsysdir)\msiexec.exe" /qn /i'; package_update_command => '"$(sys.winsysdir)\msiexec.exe" /qn /i'; package_delete_command => '"$(sys.winsysdir)\msiexec.exe" /qn /x'; }
An example how to use it.
Here we install or delete the packages. Just run:- cf-agent -KI -f .\win_packages.cf -DINSTALL
- cf-agent -KI -f .\win_packages.cf -DDELETE
body common control { any:: bundlesequence => { "test" }; } bundle agent test { vars: "packages_install" slist => { "bria-35.7.0364-x86_64.msi", "tortoisesvn-1.8.7.25475-x86_64.msi", }; "packages_delete[bria]" string => "{7CC12F6F-325C-42AC-8015-4FB687156D4C}"; "packages_delete[tortoisesvn]" string => "{A8573F59-C080-4495-A9A8-EC32D8A4ECFF}"; "package_delete_names" slist => getindices("packages_delete"); packages: DELETE:: "$(package_delete_names)" package_policy => "delete", package_method => sara_msi_delete($(package_delete_names), "$(packages_delete[$(package_delete_names)])"); INSTALL:: "$(packages_install)" package_policy => "add", package_method => sara_msi_install("http://ftp.sara.nl/windows", $(packages_install)); reports: DELETE:: "package: $(package_delete_names): $(packages_delete[$(package_delete_names)])"; }
Nice, thanks for sharing. I think those bundles are good candidates for the stdlib
ReplyDelete