Published on 10 February 2016 by

In my last blog post, Creating your own Chocolatey packages, I showed you how to create a Notepad++ package. Now we are going to use the Chocolatey package provider module to install the package with Puppet.

The Chocolatey package provider is a Puppet Approved module that allows you to install and configure Chocolatey and manage Chocolatey packages. With the Chocolatey package provider you get the benefit of:

  • Managing software across all of your Puppet-enabled Windows nodes
  • Managing the installation of Chocolatey itself on those nodes without requiring any external network access
  • Completely configuring Chocolatey and managing sources for packages. Some configuration is available now, and some configuration will be available in the first half of this year.
  • We are looking at making the provider a supported module in the near term for organizations that need a higher level of support.

You could use Chocolatey by itself, but you may find working with it across all of your systems somewhat time-consuming and possibly error prone, albeit much faster than manually managing software. For example, you could accidentally forget to install a package, or use different installation arguments on different machines. Chocolatey is great when it comes to managing packages and software and Puppet is excellent at guaranteeing state across all of your machines and automatically handling configuration drift. Using the two together is a fantastic combination when you have many machines to manage!

The first thing you’ll want to do is install the module. You can either install just the Chocolatey package provider or you can install the Windows module pack.

Now we want to install the Notepad++ package we just created in the previous post. Let’s create a manifest called chocolatey.pp and add the following to it:

package { 'notepadplusplus':
  ensure   => installed,
  provider => chocolatey,
  source   => 'c:\packages',

For this example, we’re using a simple folder share with source location of c:\packages. For other options, see my previous post on hosting your own server.

We can also adjust the default location for Chocolatey packages by setting the default Package resource for Windows.

if $::kernel == 'windows' {
  Package { source => ‘c:\packages’, }

A third way to set sources for Chocolatey is in its own configuration. We’ll cover that in detail later when the functionality to set configuration values is available in the Chocolatey Puppet provider.

We also want to ensure that Chocolatey is installed, so we can use the provider to do so. Add the following to the manifest:

include chocolatey

In a production scenario, you’re likely to have the Chocolatey package itself (chocolatey.nupkg) stored somewhere internally. In cases like that, you can use the internal nupkg for Chocolatey installation:

class {'chocolatey':
  chocolatey_download_url => 'https://internalurl/to/chocolatey.nupkg',
  use_7zip                => false,
  log_output              => true,

To use Chocolatey as our default provider for Puppet, we can easily set the default provider for the Package resource on Windows.

if $::kernel == 'windows' {
  Package { provider => chocolatey, }

Now that we’ve set everything up, our chocolatey.pp manifest should look similar to this:

if $::kernel == 'windows' {
  Package { 
    provider => chocolatey, 
    source => ‘c:\packages’, 

include chocolatey

package { 'notepadplusplus':
  ensure   => installed,

Let’s validate the manifest by typing puppet parser validate c:\path\to\chocolatey.pp in the command prompt. If the parser returns nothing, it means validation passed.

Now let’s apply the manifest with puppet apply c:\path\to\chocolatey.pp. Your output may look similar to what you see below:

Notice: Compiled catalog for win2012r2x64 in environment production in 0.58 seconds
Notice: /Stage[main]/Chocolatey::Install/Windows_env[chocolatey_PATH_env]/ensure : created
Notice: /Stage[main]/Chocolatey::Install/Windows_env[chocolatey_ChocolateyInstall_env]/ensure: created
Notice: /Stage[main]/Chocolatey::Install/Exec[install_chocolatey_official]/returns: executed successfully
Notice: /Stage[main]/Chocolatey::Install/Exec[install_chocolatey_official]: Triggered 'refresh' from 2 events
Notice: /Stage[main]/Main/Package[notepadplusplus]/ensure: created
Notice: Finished catalog run in 35.22 seconds

Now we’ve taken our Chocolatey package and used Puppet to ensure both Chocolatey and the package is installed on our system!

We can also ensure the package upgrades automatically by changing ensure to latest or a specific version.

package { 'notepadplusplus':
  ensure   => latest,

We can remove the package and uninstall the software by changing ensure to absent.

package { 'notepadplusplus':
  ensure   => absent,

A more in depth review of creating a package can be found in our Windows modules docs under Chocolatey: Create a Package.

Stay tuned for more Chocolatey goodness in the next post in our Chocolatey blog series!

Learn More

Share via:

Great usage explanation for the chocolatey module, but the file `chocolatey.pp` is a bit confusing... How can I use the created `chocolatey.pp` within `site.pp` now?

New to puppet and using chocolatey.

our initial install of chocolatey is similiar to yours.. but our nupkg has a version.

class {'chocolatey':


url => 'https://internalurl/to/chocolatey.0.10.7.nupkg',

use_7zip => false,

log_output => true,


So puppet installs 0.10.7

we want to use a newer choco.  so I upload a new package to the URL there.. and modify the

url => 'https://internalurl/to/chocolatey.0.10.11.nupkg',

BUT it just doesnt install the newer choco!

any help would be apprecaited.

Hi! You'll want to use something like the URL we default to, which points to a nuget repo where the package lives rather than the specific package:

$download_url = ''

If you're still having problems, could you drop a line in the Windows channel on the public community slack (link below) or file a bug report in JIRA? 

- Puppet Community Slack:

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.