Using custom DSC resources in Puppet
In this blog, I will go through the steps of taking a custom community Desired State Configuration (DSC) resource module, in this case “cSNNP,” which is used to configure SNMP on a Windows computer, and use it in a Puppet manifest using the Puppet dsc_lite
module. The dsc_lite
module is an alternative to the existing dsc
module, providing users with a more direct and lightweight approach to using Puppet with DSC.
PowerShell Desired State Configuration (DSC) is a fantastic tool for configuring Window servers. Not only does Microsoft produce a large amount of resources that can be used in DSC, but the community produces a lot of resources too. Many times, when there is no Microsoft-provided resources that fit a need for a Windows server, a custom community-created resource exists that you can leverage.
Combining Puppet and DSC resources using dsc_lite
can provide excellent benefits for managing Windows. For instance, monitoring your configurations on Windows through native DSC can be difficult due to not having a GUI to use. This is where combining Puppet and DSC makes a lot of sense. Using Puppet as your configuration management solution but also leveraging DSC resources has been supported for a while, but with the release of the dsc_lite
Puppet module, IT teams can now leverage any DSC resource as long as it can be used with Invoke-DSCResource. Ultimately, this means Puppet users can configure Windows using all those great DSC resources in the PowerShell Gallery without waiting for Puppet to add them as a supported resource.
Distributing DSC resources
When using DSC, one thing to consider is how to get resources to your target nodes. Ideally, this would likely be an internal repository that holds all the DSC resources, so that you do not rely on the PowerShell Gallery. For the sake of simplicity, I will be using the PowerShell Gallery as a repository in this example.
A quick and easy way to ensure your nodes obtain the DSC resources you use in Puppet, is to use the exec Puppet resource and set a repository like this:
exec { 'Set-NuGetProvider': command => 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force', unless => 'if (!(Get-PackageProvider -Name nuget)){exit 1}', provider => 'powershell', } -> exec { 'Set-PSGalleryTrusted': command => 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted', unless => 'if ((Get-PSRepository -Name PSGallery | Select-Object -ExpandProperty InstallationPolicy) -ne Trusted){exit 1}', provider => 'powershell', } ->
Above we ensure the NuGet package provider is installed and the PSGallery repository is trusted. You can easily change this to an internal repository as well.
Next, we can use the exec resource again to install the required modules that contain our DSC resources (xPSDesiredStateConfiguration and cSNMP):
Read more at Puppetlabs.com