Using the Windows module pack
This guide covers creating a managed permission with
ACL
, creating managed registry keys and
values with registry
, and installing and
creating your own packages with chocolatey
.
Windows module pack
The Windows module pack is a group of modules available on the Forge curated to help you complete common Windows tasks.
The Forge is an online community of Puppet modules submitted by Puppet and community members. The Forge makes it easier for you to manage Puppet and can save you time by using pre-written modules, rather than writing your own. In addition to being rated by the community, modules in the Forge can be Puppet Approved or Puppet Supported. The major difference is that Approved modules are not available for Puppet Enterprise support services, but are still tested and adhere to a standard for style and quality.
The Windows module pack includes several Windows compatible modules that help you complete common specific tasks. You can find more Windows modules by searching the Forge. While the module pack itself is not supported, the modules by Puppet contained in the pack are individually supported with PE. The rest have been reviewed and recommended by Puppet but are not eligible for commercial support.
The Windows module pack enables you to do the following:
- Read, create, and write registry keys with
registry
. - Interact with PowerShell through the Puppet DSL with
powershell
. - Manage Windows
PowerShell DSC (Desired State
Configuration) resources using
dsc
anddsc_lite
. - Reboot Windows as part of management
as necessary through
reboot
. - Enforce fine-grained access control permissions using
acl
. - Manage Windows Server Update Service
configs on client nodes
wsus_client
. - Install or remove Windows features
with
windowsfeature
. - Download files for use during management via
download_file
. - Build IIS sites and virtual applications with
iis
. - Install packages with
chocolatey
. - Manage environment variables with
windows_env
.
Install the Windows module pack
These steps show you how to install the module pack locally, but you can also install it on the master and pluginsync pushes the module pack to all of your nodes.
Manage permissions with acl
The puppetlabs-acl
module helps you manage access control lists (ACLs), which
provide a way to interact with permissions for the Windows
file system. This module enables you to set basic permissions up to very advanced
permissions using SIDs (Security Identifiers) with an access mask, inheritance, and
propagation strategies. First, start with querying some existing permissions.
View file permissions with ACL
ACL is a custom type and provider, so you can use puppet resource
to look at existing file and
folder permissions.
For some types, you can use the command puppet resource <TYPE NAME>
to get all instances of that
type. However, there could be thousands of ACLs on a Windows system, so it's best to specify the folder you
want to review the types in. Here, check c:\Users
to see what permissions it contains.
puppet resource acl c:\Users
acl { 'c:\Users':
inherit_parent_permissions => 'false',
permissions => [
{identity => 'SYSTEM', rights=> ['full']},
{identity => 'Administrators', rights => ['full']},
{identity => 'Users', rights => ['read', 'execute'], affects => 'self_only'},
{identity => 'Users', rights => ['read', 'execute'], affects => 'children_only'},
{identity => 'Everyone', rights => ['read', 'execute'], affects => 'self_only'},
{identity => 'Everyone', rights => ['read', 'execute'], affects => 'children_only'}
],
}
As you can see, this particular folder does not inherit permissions from its parent folder; instead, it sets its own permissions and determines how child files and folders inherit the permissions set here.
{'identity' => 'SYSTEM', 'rights'=> ['full']}
states that the “SYSTEM” user has full rights to this folder, and by default all children and grandchildren files and folders (as these are the same defaults when creating permissions in Windows).{'identity' => 'Users', 'rights' => ['read', 'execute'], 'affects' => 'self_only'}
gives read and execute permissions to Users but only on the current directory.{'identity' => 'Everyone', 'rights' => ['read', 'execute'], 'affects' => 'children_only'}
gives read and execute permissions to everyone, but only on subfolders and files.
Create a Puppet managed permission
Now the permissions have been set up for this directory. You can get into more advanced permission scenarios if you read the usage scenarios on this module’s Forge page.
Create Puppet managed registry keys with registry
You might eventually need to use the registry to access
and set highly available settings, among other things. The puppetlabs-registry
module, which is also a Puppet Supported Module enables you to set both registry keys
and values.
View registry
keys
and values with puppet resource
puppetlabs-registry
is a custom type and
provider, so you can use puppet resource
to
look at existing registry settings.
It is also somewhat
limited, like the acl
module in that it is
restricted to only what is specified.
Keys are like file paths (directories) and values are like files that can have data and be of different types.
Create managed keys
Learn how to make managed registry keys, and see Puppet correct configuration drift when you try and alter them in Registry Editor.
Example
class puppetconf::disable_error_reporting {
registry_value { 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\ForceQueue':
type => dword,
data => '1',
}
registry_value { 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\DontShowUI':
type => dword,
data => '1',
}
registry_value { 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\DontSendAdditionalData':
type => dword,
data => '1',
}
registry_key { 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\Consent':
ensure => present,
}
registry_value { 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\Consent\DefaultConsent':
type => dword,
data => '2',
}
}
Create, install and repackage packages with the chocolatey
module
Chocolatey is a package manager for Windows that is similar in design and execution to package
managers on non-Windows systems. The chocolatey
module is a Puppet Approved Module, so it's not eligible for Puppet Enterprise support services. The module has the capability to
intall and configure Chocolatey itself, and then manage software on Windows with Chocolatey packages.
View existing packages
Chocolatey has a custom provider for the package resource
type, so you can use puppet resource
to
view existing packages.
puppet resource package --param provider |
more
The additional provider parameter in this command outputs all types of installed packages that are detected by multiple providers.
Install Chocolatey
These steps are to install Chocolatey (choco.exe) itself. You use the module to ensure Chocolatey is installed.
Install a package with chocolatey
Normally, when installing packages you copy them locally first, make any required changes to bring everything they download to an internal location, repackage the package with the edits, and build your own packages to host on your internal package repository (feed). For this exercise, however, you directly install a portable Notepad++ from Chocolatey's community feed. The Notepad++ CommandLine package is portable and shouldn't greatly affect an existing system.
If you want to use this package for a production scenario, you need an
internal custom feed. This is simple to set up with the chocolatey_server
module. You could also use Sonatype Nexus,
Artifactory, or a CIFS share if you want to host packages with a non-Windows option, or you can use anything on Windows that exposes a NuGet OData feed (Nuget is the packaging
infrastructure that Chocolatey uses). See the How To
Host Feed page of the chocolatey
wiki for more in-depth information. You could also store packages on your master
and use a file resource to verify they are in a specific local directory prior to ensuring
the packages.
Example
The following example ensures that Chocolatey, the Chocolatey Simple Server (an internal Chocolatey package repository), and some packages are installed. It requires the additional chocolatey/chocolatey_server module.
In c:\<FILE
PATH>\packages
you must have packages for Chocolatey, Chocolatey.Server, RoundhousE, Launchy,
and Git, as well as any of their dependencies for this to work.
case $operatingsystem {
'windows': {
Package {
provider => chocolatey,
source => 'C:\packages',
}
}
}
# include chocolatey
class {'chocolatey':
chocolatey_download_url => 'file:///C:/packages/chocolatey.0.9.9.11.nupkg',
use_7zip => false,
log_output => true,
}
# This contains the bits to install the custom server.
# include chocolatey_server
class {'chocolatey_server':
server_package_source => 'C:/packages',
}
package {'roundhouse':
ensure => '0.8.5.0',
}
package {'launchy':
ensure => installed,
install_options => ['-override', '-installArgs','"', '/VERYSILENT','/NORESTART','"'],
}
package {'git':
ensure => latest,
}
Copy an existing package and make it internal (repackaging packages)
To make the existing package local, use these steps.
Chocolatey's community feed has quite a few packages, but they are geared towards community and use the internet for downloading from official distribution sites. However, they are attractive as they have everything necessary to install a piece of software on your machine. Through the repackaging process, by which you take a community package and bring all of the bits internal or embed them into the package, you can completely internalize a package to host on an internal Chocolatey/NuGet repository. This gives you complete control over a package and removes the aforementioned production trust and control issues.
Create a package with chocolatey
Creating your own packages is, for some system administrators, surprisingly simple compared to other packaging standards.
Ensure you have at least
Chocolatey CLI (choco.exe) version 0.9.9.11
or newer for this next part.
Vagrant is installed!
Uninstall packages with Chocolatey
In addition to installing and creating packages, Chocolatey can also help you uninstall them.
To verify that the choco
autoUninstaller
feature is turned on, use
choco feature
to list the features and
their current state. If you're using include
chocolatey
or class chocolatey
to ensure Chocolatey is installed, the configuration is applied automatically (unless you
have explicitly disabled it). Starting in Chocolatey version 0.9.10
, it is enabled by default.
You can look in the Control Panel, Programs and Features to see that it’s no longer installed!