Chocolatey Package Manager for Windows
Sep 27, 2016Dan Iverson
One advantage of Linux distributions is they include software package managers like yum
or apt-get
. Package managers make is easy to install software with a single command, like yum install vlc
. There is a package manager for Windows that works well and integrates with Puppet: Chocolatey. Let’s explore how to use Chocolatey and how it works with Puppet.
Microsoft has a package manager,
OneGet
, butOneGet
new enough that it’s not installed by default in PeopleSoft-certified versions of Windows.
Install Chocolatey via PowerShell
If you want to install Chocolatey with PowerShell, the Chocolatey installation page has example commands to do this. The scripts will download and execute a remotely signed PowerShell script which installs Chocolatey and configures it for you. I used:
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
to install Chocolatey on my server.
Using Chocolatey
After installation, restart your PowerShell window. Installing software with Chocolatey is a simple as running this command:
choco install notepadplusplus
Chocolatey will install Notepad++ for you. Simple!
Want to install git
on your server?
choco install git
Done.
If you want to accept license agreements automatically, run this command to change Chocolatey’s global setting:
choco feature enable -n=allowGlobalConfirmation
I primarily use Chocolatey for server management, but you can use it to manager your workstation too. The library of chocolatey packages contains server and workstation software. To view the library, head over to the chocolatey website.
Install Chocolatey via Puppet
chocolatey can be used with Puppet to manage software package on your server. There is an official Puppet module for Chocolatey, so we can install the module and use it our own manifests.
puppet module install chocolatey-chocolatey
You may fine the the module install failed due because the Puppet Forge root certificate is not in the Windows keystore. You’ll also notice some warnings about the version number for the pt_xxx
modules. You can ignore those warnings; the version numbers used by the PeopleTools team don’t follow the Puppet conventions.
To install the root certificate for Puppet Forge:
- Save this certificate (GeoTrust Global CA) as
GeoTrustCA.pem
. - Run
certutil -v -addstore Root .\GeoTrustCa.pem
to add the certificate - Re-run
puppet module install chocolatey-chocolatey
The Chocolatey module depends on three additional Puppet libraries, so the installation windows shows you the dependencies it installed.
└─┬ chocolatey-chocolatey
├── badgerious-windows_env
├── puppetlabs-powershell
└── puppetlabs-stdlib
Use Chocolatey with Puppet
Now we can use Chocolatey in Puppet manfiests. This is great because we can standardize software packages on our servers the same way we standardize configurations.
On my Windows Servers, I use Process Explorer to troubleshoot issues. It’s a free tool from Microsoft and is great for finding processes that are locking access to files. Let’s write a Puppet manifest to install Process Explorer using chocolatey.
On the Chocolatey Packages page, search for “Process Explorer”.
In the results, you’ll see the Chocolatey command to install Process Explorer. Copy the name of the package; we’ll use the name in our manifest.
Create windows_software.pp
under puppet\etc\manifests
. The first line of the manifest will be to include the “Chocolatey” library.
include chocolatey
Then, we need to define a Puppet resource. We use the package
resource, give it the name of the Chocolatey package (from above), and set the ensure
parameter.
package { 'procexp':
ensure => present,
}
Finally, we tell Puppet to use Chocolatey as the package manager.
package { 'procexp':
ensure => present ,
provider => 'chocolatey',
}
Save windows_software.pp
and run puppet apply
:
puppet apply .\windows_software.pp
When the Puppet run is done, you’ll find Process Explorer installed into Chocolatey’s installation directory. The default directory is C:\ProgramData\chocolatey\lib\
.
Update: 9/27/2016
Andy from the psadmin.io Community and podcast episode 42 suggested this tip for using Chocolatey to install git:
choco install -y git -params "/GitAndUnixToolsOnPath"
This will install additional tools like SSH with Git. Thanks Andy!
Note: This was originally posted by Dan Iverson and has been transferred from a previous platform. There may be missing comments, style issues, and possibly broken links. If you have questions or comments, please contact [email protected].