Puppet and Windows
Puppet manages Windows servers with the same language and workflow: facts, catalogs, modules and Hiera. The agent runs as a Windows service. Resource types are the same (file, service, user, package) with Windows providers, and extra modules add registry, features and more.
Install the Agent
powershell
# Download the MSI from the Puppet downloads page for your chosen Puppet version, then:
msiexec /qn /norestart /i puppet-agent-x64.msi PUPPET_SERVER=puppet.example.com PUPPET_AGENT_ENVIRONMENT=production
# Check
& "C:\Program Files\Puppet Labs\Puppet\bin\puppet.bat" --version
Get-Service puppet
# Run once
puppet agent -t
| Item | Windows location |
| Program files | C:\Program Files\Puppet Labs\Puppet\ |
| Configuration | C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf |
| SSL files | C:\ProgramData\PuppetLabs\puppet\etc\ssl\ |
| Logs | Windows Event Log (Application) and C:\ProgramData\PuppetLabs\puppet\var\log\ |
| External facts | C:\ProgramData\PuppetLabs\facter\facts.d\ |
Paths and Quoting
Backslashes: In Puppet strings, use forward slashes ('C:/inetpub/wwwroot') or in single quotes with doubled backslashes. Backslashes in double quotes are escape characters, which causes odd errors. Windows accepts forward slashes in nearly all Puppet attributes.
puppet
file { 'C:/app/config.ini':
ensure => file,
content => "port=8080\n", # \n is a Unix line ending; Puppet's windows file type handles this for text
}
# Single quoted with backslashes needs doubling only at the end: 'C:\\Windows\\Temp\\'
$path = 'C:\Program Files\App' # fine in single quotes, but never ends with a single \ before the quote
File Permissions: ACLs
puppet
file { 'C:/app':
ensure => directory,
owner => 'Administrators',
group => 'Administrators',
mode => '0775',
}
# Fine-grained control with the puppetlabs-acl module
acl { 'C:/app/data':
ensure => present,
inherit_parent_permissions => false,
permissions => [
{ identity => 'Administrators', rights => ['full'] },
{ identity => 'SYSTEM', rights => ['full'] },
{ identity => 'DOMAIN\\appsvc', rights => ['modify'] },
],
}
Packages: MSI and Chocolatey
puppet
# MSI installer from a share or URL
package { '7-Zip 23.01 (x64 edition)':
ensure => installed,
source => 'C:/installers/7z2301-x64.msi',
install_options => ['/qn', '/norestart'],
}
# Chocolatey: install the package manager first with the chocolatey module
include chocolatey
package { ['git', 'notepadplusplus', 'vscode']:
ensure => installed,
provider => 'chocolatey',
}
package { 'googlechrome':
ensure => '129.0.6668.90',
provider => 'chocolatey',
}
package { 'old-tool':
ensure => absent,
provider => 'chocolatey',
}
The package name for MSI: For windows provider packages the title must match the display name shown in 'Apps and features' (such as 7-Zip 23.01 (x64 edition)). Chocolatey is easier because names are simple.
Services
puppet
service { 'W32Time':
ensure => running,
enable => true, # Automatic
}
service { 'Spooler':
ensure => stopped,
enable => false,
}
service { 'MyAppService':
ensure => running,
enable => delayed, # Automatic (delayed start)
}
Registry
Use the **puppetlabs-registry** module.
puppet
registry_key { 'HKLM\SOFTWARE\MyCompany\MyApp':
ensure => present,
}
registry_value { 'HKLM\SOFTWARE\MyCompany\MyApp\InstallDir':
ensure => present,
type => string,
data => 'C:\Program Files\MyApp',
}
registry_value { 'HKLM\SOFTWARE\MyCompany\MyApp\Timeout':
ensure => present,
type => dword,
data => 30,
}
# Disable SMBv1 via registry
registry_value { 'HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\SMB1':
ensure => present,
type => dword,
data => 0,
}
Windows Features, Roles and IIS
puppet
# puppetlabs-dism or the built-in windowsfeature resource from the puppetlabs-windows_feature (check Forge)
dsc_windowsfeature { 'IIS':
dsc_ensure => 'Present',
dsc_name => 'Web-Server',
}
# IIS site with the puppetlabs-iis module
iis_application_pool { 'shop_pool':
ensure => present,
managed_runtime_version => 'v4.0',
state => 'started',
}
iis_site { 'shop':
ensure => started,
physicalpath => 'C:\inetpub\shop',
applicationpool => 'shop_pool',
bindings => [{ 'bindinginformation' => '*:80:shop.example.com', 'protocol' => 'http' }],
require => Iis_application_pool['shop_pool'],
}
Scheduled Tasks
puppet
scheduled_task { 'nightly cleanup':
ensure => present,
command => 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe',
arguments => '-NoProfile -ExecutionPolicy Bypass -File C:\scripts\cleanup.ps1',
trigger => {
schedule => daily,
start_time => '02:00',
},
user => 'SYSTEM',
}
PowerShell with exec
puppet
exec { 'set-timezone':
command => 'Set-TimeZone -Id "India Standard Time"',
unless => 'if ((Get-TimeZone).Id -eq "India Standard Time") { exit 0 } else { exit 1 }',
provider => powershell,
logoutput => true,
}
exec { 'enable-rdp':
command => 'Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name fDenyTSConnections -Value 0',
unless => 'if ((Get-ItemProperty "HKLM:\System\CurrentControlSet\Control\Terminal Server").fDenyTSConnections -eq 0) { exit 0 } else { exit 1 }',
provider => powershell,
}
The powershell provider comes from the **puppetlabs-powershell** module. As on Linux, give every exec a guard (unless, onlyif, creates).
DSC: Use PowerShell Desired State Configuration Resources
The **puppetlabs-dsc_lite module lets Puppet call any DSC resource, and the puppetlabs-dsc** family of modules wraps many DSC resources as native Puppet types. DSC is a good option when Microsoft provides a resource for a Windows feature and there is no native Puppet module.
puppet
dsc { 'enable-firewall-rule':
resource_name => 'xFirewall',
module => {
'ModuleName' => 'xNetworking',
'ModuleVersion' => '5.7.0.0',
},
properties => {
'Name' => 'AllowHTTP',
'Ensure' => 'Present',
'Enabled' => 'True',
'Direction' => 'Inbound',
'Protocol' => 'TCP',
'LocalPort' => '80',
'Action' => 'Allow',
},
}
Users, Groups and Hosts
puppet
user { 'appsvc':
ensure => present,
password => Sensitive('Pa55w0rd!ChangeMe'),
groups => ['Administrators'],
comment => 'Service account',
}
group { 'AppOperators':
ensure => present,
members => ['alice', 'bob'],
auth_membership => true, # exact membership list
}
host { 'db.internal':
ip => '10.0.2.20',
}
Windows Facts and Conditions
puppet
if $facts['os']['family'] == 'windows' {
include profile::windows::base
} else {
include profile::linux::base
}
notice($facts['os']['release']['full']) # 2022
notice($facts['windows_edition_id'] ) # if available on your Facter versio
Common Windows Problems
| Problem | Fix |
| Odd characters or failed path | Use forward slashes, single quotes |
| MSI install fails silently | Add /l*v C:/Temp/install.log to install_options, read the log |
| Service will not start | Check the Event Viewer, service account rights |
| PowerShell scripts blocked | Use -ExecutionPolicy Bypass or set policy with the powershell module |
| Reboot required | Use the puppetlabs-reboot module: reboot { 'after_features': when => pending } |
| Slow runs | Use facter.conf to block slow facts, reduce exec use |
puppet
reboot { 'after_install':
apply => finished,
when => pending,
subscribe => Dsc_windowsfeature['IIS'],
}
Practice Tasks
- Install the Windows agent on a lab VM and sign its certificate
- Install
git and 7zip with the Chocolatey provider
- Create a registry key and DWORD value, then change the value by hand and run Puppet
- Create a scheduled task that writes the date to a file every hour
- Install IIS and publish a simple site with the IIS module
Conclusion
Puppet manages Windows with the same code model. Use forward slashes, Chocolatey for software, the registry, IIS, ACL and PowerShell modules for system settings, DSC when needed, and guard every exec.
Quick Summary: MSI agent; Chocolatey provider; registry_value; scheduled_task; powershell exec with unless; DSC; reboot module.