June 4, 2020

Puppet Facts for Windows: What They Are, What They Do + Ways to Utilize Them

Windows
Products & Services

To manage your Windows desktops and servers based on the version / edition of Windows installed across your organization, use Windows build-specific Puppet facts.

Back to top

What are Puppet Facts?

In Puppet, Facts are pieces of information on the state of a client. Puppet Facts facts contain client information like OS and network interface IP address. Puppet Facts are used to manage configurations for the client.

Puppet Facts come from Facter, Puppet’s system profiling tool, which uses a set of Ruby libraries to run across platforms.

Back to top

What are Windows Puppet Facts? What Do They Do?

If you have a mix of Windows servers (Core and ServerStandard) and Windows desktops with varying versions and editions of Windows, using Windows Puppet facts allows you to:

  • Avoid installing GUI type tools (Notepad++) on Windows core servers
  • Ensure that new features (e.g. Windows Terminal) are only installed on versions of Windows that support them
  • Install VS Code with Puppet extensions on client desktops only

Set Yourself Apart with Deeper Puppet Skills

Free on-demand courses let you build your skillset faster and get ready for certification.

PUPPET TRAINING

Back to top

Examples of Puppet Facts for Windows

Let’s see what all this looks like in some Puppet code:

 if $facts['os']['windows']['release_id'] >= '1904' {
    # Ensure Build Version Supports Windows Terminal
    package { 'microsoft-windows-terminal':
      ensure   =>  installed,
      provider => 'chocolatey',
    }
  }


  if $facts['os']['windows']['installation_type'] != 'Server Core' {
    # Editors not permitted on Core Servers
    package { 'notepadplusplus':
      ensure   =>  installed,
      provider => 'chocolatey',
    }
  }


  if $facts['os']['windows']['installation_type'] == 'Client' {
    # VS Code to be installed on Desktops with Puppet Extensions
    package { 'vscode':
      ensure   =>  installed,
      provider => 'chocolatey',
    }
    package { 'vscode-puppet':
      ensure   =>  installed,
      provider => 'chocolatey',
    }
  }



 

The previous example uses a number of facts under the os.windows key:

C:> facter os.windows
{
  Display_version => "22H2"  

  edition_id => "Professional",
  installation_type => "Client",
  product_name => "Windows 10 Pro",
  release_id => "22H2",
  system32 => "C:\WINDOWS\system32"
}


 

All of these facts are derived from the Windows Registry Key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion as shown in the following table.

Registry Value

Fact

Description

Syntax/Example

DisplayVersion

display_version

Version codename mixed string

22H2

ReleaseID

release_id

The 4 digit Windows Build Version

YYMM (e.g. 1904) until deprecation in 21H1 now YYHM

InstallationType

installation_type

Differentiates Server, Server Core, and Client (Desktop)

Server

EditionID

edition_id

Server or Desktop Edition variant

ServerStandard, Professional, Enterprise

ProductName

product_name

Textual Product Name

Windows 2022 Standard Edition

Note: There are some inconsistencies across Windows versions due to changes and deprecations of the underlying registry entry. ReleaseID was deprecated in 21H1 and Display Version added, although for 21H1 the release version remains 2009. It changes to mirroring display version after that point. Server 2012 doesn’t have ReleaseID as it wasn’t added until 1803. The registry entry also lists the product name for Windows 11 as Windows 10 and this major version should be sourced from os.release.major instead.

These facts also support:

  • Fact Collection to determine Windows 10 Build Versions (Feature releases)
  • Patching and ensuring supported versions are in use

The os facts are documented at Core Facts and this can be expanded on creating your own Windows custom facts following the Starting out writing custom facts for Windows guide. The facterdb project contains sample facts for various versions of Windows and other operating systems.

Back to top

Do More with Puppet on Windows

If you're looking for more information about Puppet on Windows, check out the Top Questions and Answers for Puppet on Windows and the Windows collection on the Puppet Forge.

The Puppet Forge also contains content from the PowerShell gallery, allowing Windows users to automate the deployment of PowerShell DSC content wrapped in Puppet modules.

Learn More

John O’Connor was a senior engineer in developer services who has a passion for ensuring Windows remains a first-class Puppet citizen.

This post was originally published on June 4, 20202, and has been updated for accuracy.

Back to top