| Travis | AppVeyor |
|---|---|
![]() |
- Overview
- Module Description - What the module does and why it is useful
- Setup - The basics of getting started with Chocolatey
- Usage - Configuration options and additional functionality
- Reference - An under-the-hood peek at what the module is doing and how
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
- Attributions
This is a Puppet package provider for chocolatey, which is like apt-get, but for Windows. This should be compatible with a wide range of Puppet versions.
This is the official module for working with the Chocolatey package manager.
This module will ultimately be able to
- install Chocolatey
- work with custom location installations
- configure Chocolatey
- use Chocolatey as a package provider
Chocolatey is a nicer abstraction because it nearly mimics how package managers on other operating systems work. If you can imagine the built in provider for Windows versus Chocolatey, let's take a look at the use case of installing git:
# Using built-in provider
package { "Git version 1.8.4-preview20130916":
ensure => installed,
source => 'C:\temp\Git-1.8.4-preview20130916.exe',
install_options => ['/VERYSILENT']
}# Using Chocolatey (set as default for Windows)
package { 'git':
ensure => latest,
}The built-in provider has the following needs:
- Package name must match exactly the name from installed programs. See package name must be DisplayName
- Package name has issues with unicode characters
- Source must point to the location of the executable installer. See source is required.
- No
ensure => latest- see handling versions and upgrades
Chocolatey's provider on the other hand:
- Package name only has to match the name of the package, which can be whatever you choose.
- The package is a nice abstraction
- Package knows how to install the software silently
- Package knows where to get the executable installer
- Source is free to specify different Chocolatey feeds
- Chocolatey makes
packagemore platform agnostic since it looks exactly like other platforms.
Chocolatey affects your system and what software is installed on it, ranging from tools and portable software to natively installed applications.
Chocolatey requires the following components
- Powershell v2+
- intalled on most systems by default
- .NET Framework v4+
NOTE: The module does not yet offer an installation option for Chocolatey, so you will need to install that as well.
Install this module via any of these approaches:
- puppet forge
- git-submodule (tutorial)
- librarian-puppet
- r10k
If you want to set this provider as the site-wide default,
add to your site.pp:
if $::kernel == windows {
# default package provider
Package { provider => chocolatey, }
}
# OR
case $operatingsystem {
'windows':
Package { provider => chocolatey, }
}package { 'notepadplusplus':
ensure => installed|latest|'1.0.0'|absent,
provider => 'chocolatey',
install_options => ['-pre','-params','"','param1','param2','"'],
uninstall_options => ['-r'],
source => 'https://myfeed.example.com/api/v2',
}- this is versionable so
ensure => '1.0'works - this is upgradeable
- supports
latest(checks upstream),absent(uninstall) - supports
install_optionsfor pre-release, other cli - soon: supports 'holdable'
package { 'notepadplusplus':
ensure => installed,
provider => 'chocolatey',
}package { 'notepadplusplus':
ensure => latest,
provider => 'chocolatey',
}package { 'notepadplusplus':
ensure => '6.7.5',
provider => 'chocolatey',
}package { 'notepadplusplus':
ensure => '6.7.5',
provider => 'chocolatey',
source => 'C:\local\folder\packages',
}package { 'notepadplusplus':
ensure => '6.7.5',
provider => 'chocolatey',
source => '\\unc\source\packages',
}package { 'notepadplusplus':
ensure => '6.7.5',
provider => 'chocolatey',
source => 'https://custom.nuget.odata.feed/api/v2/',
}package { 'notepadplusplus':
ensure => '6.7.5',
provider => 'chocolatey',
source => 'C:\local\folder\packages;https://chocolatey.org/api/v2/',
}package {'launchy':
ensure => installed,
provider => 'chocolatey',
install_options => ['-override', '-installArgs', '"', '/VERYSILENT', '/NORESTART', '"'],
}The underlying installer may need quotes passed to it. This is possible, but not as intuitive. You'll need a set of quotes surrounding the argument and a double set of quotes surrounding the item that must be quoted.
package {'mysql':
ensure => latest,
provider => 'chocolatey',
install_options => ['-override', '-installArgs', '"', '/INSTALLDIR=',
'""', 'C:\Program Files\somewhere', '""', '"'
],
}- Chocolatey provider (
lib/puppet/provider/package/chocolatey.rb) - params.pp (
manifests/params.pp) - install.pp (
manifests/install.pp) - config.pp (
manifests/config.pp)
Chocolatey implements a package type with a resource provider, which is built into Puppet.
This provider supports the install_options and uninstall_options attributes,
which allow command-line options to be passed to the choco command. These options
should be specified as documented below.
- Required binaries:
choco.exe, usually found inC:\Program Data\chocolatey\bin\choco.exe.- The binary is searched for using the Environment Variable
ChocolateyInstall, then by two known locations (C:\Chocolatey\bin\choco.exeandC:\ProgramData\chocolatey\bin\choco.exe). - On Windows 2003 you should install Chocolatey to
C:\Chocolateyor somewhere besides the default. NOTE: the root ofC:\is not a secure location by default, so you may want to update the security on the folder.
- The binary is searched for using the Environment Variable
- Supported features:
install_options,installable,uninstall_options,uninstallable,upgradeable,versionable.
(Property: This attribute represents concrete state on the target system.)
What state the package should be in. You can choose which package to retrieve by
specifying a version number or latest as the ensure value. This defaults to
installed.
Valid options: present (also called installed), absent, latest or a version
number.
An array of additional options to pass when installing a package. These options are
package-specific, and should be documented by the software vendor. One commonly
implemented option is INSTALLDIR:
package {'launchy':
ensure => installed,
provider => 'chocolatey',
install_options => ['-installArgs', '"', '/VERYSILENT', '/NORESTART', '"'],
}The above method of single quotes in an array is the only method you should use
in passing install_options with the Chocolatey provider. There are other ways
to do it, but they are passed through to Chocolatey in ways that may not be
sufficient.
This is the only place in Puppet where backslash separators should be used. Note that backslashes in double-quoted strings must be double-escaped and backslashes in single-quoted strings may be double-escaped.
(Namevar: If ommitted, this attribute's value will default to the resource's title.)
The package name. This is the name that the packaging system uses internally.
The specific backend to use for the package resource. Chocolatey is not the
default provider for Windows so it must be specified (or by using a resource
default, shown in Usage). Valid options for this provider are 'chocolatey'.
Where to find the package file. Chocolatey maintains default sources in its configuration file that it will use by default. Use this to override the default source(s).
Chocolatey accepts different values for source, including accept paths to local files/folders stored on the target system, URLs (to OData feeds), and network drive paths. Puppet will not automatically retrieve source files for you, and usually just passes the value of source to the package installation command.
You can use a file resource if you need to manually copy package files to the
target system.
An array of additional options to pass when uninstalling a package. These options are package-specific, and should be documented by the software vendor.
package {'launchy':
ensure => absent,
provider => 'chocolatey',
uninstall_options => ['-uninstallargs', '"', '/VERYSILENT', '/NORESTART', '"'],
}The above method of single quotes in an array is the only method you should use
in passing uninstall_options with the Chocolatey provider. There are other ways
to do it, but they are passed through to Chocolatey in ways that may not be
sufficient.
This is the only place in Puppet where backslash separators should be used. Note that backslashes in double-quoted strings must be double-escaped and backslashes in single-quoted strings may be double-escaped.
Works with Windows only.
See CONTRIBUTING.md
A special thanks goes out to Rich Siegel who wrote the original provider and continues to contribute to the development of this provider.
