Chocolatey Package Manager for Windows

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, but OneGet 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.

installchoco

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!

installnpp

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.

installpuppetmodule1-sslfail

To install the root certificate for Puppet Forge:

  1. Save this certificate (GeoTrust Global CA) as GeoTrustCA.pem.
  2. Run certutil -v -addstore Root .\GeoTrustCa.pem to add the certificate
  3. Re-run puppet module install chocolatey-chocolatey

installpuppetmodule2

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”.

chocopackages

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

installprocexp

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\.

procexpinstall

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!

One thought on “Chocolatey Package Manager for Windows

  1. Pingback: #49 – Chocolatey

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax