We briefly covered compiling DSC configurations for use on a Pull Server in Chapter 2, DSC Architecture, and we will build on that introduction here. We are going to use the following example DSC configuration with our DSC Pull Server. It's not fancy and it doesn't do a whole lot, but it is great at showing how DSC Pull Servers do the work for us:
Configuration SetupTheSite { Import-DscResource -Module PSDesiredStateConfiguration Import-DscResource -Module xWebAdministration Node $AllNodes.Where({ $_.Roles -contains 'Target'}).NodeName { WindowsFeature IIS { Ensure = 'Present' Name = 'Web-Server' } <#..#> xWebsite NewWebsite { Ensure = 'Present' State = 'Started' Name = $Node.WebSiteName PhysicalPath = $Node.WebSiteFolder BindingInfo = MSFT_xWebBindingInformation{ Protocol = 'HTTP' Port = '80' } DependsOn = '[File]WebContent' } } }
It uses the xWebSite
and xWebApplication
DSC Resources from the xWebAdministration
module to install a simple website on our target node. This allows us to showcase the DSC Pull Server distributing the MOF to the target nodes and distributing the xWebAdministrion
module to all the target nodes, as well. For these reasons, the following example DSC configuration is cut for length, so download the example book code to see the entire thing.
In WMF 4, we register target nodes with the DSC Pull Server by assigning ConfigurationIDs
to each target node's LCM, then naming the MOF file with the same ConfigurationID
. We already registered the ConfigurationID
with the target node by setting it in the LCM configuration block earlier in the chapter. We now have to rename the MOF file with the ConfigurationID
and place it in the DSC Pull Server directory:
$outputPath = ([IO.Path]::Combine($PSScriptRoot, 'SetupTheSite')) $dataScript = ([IO.Path]::Combine($PSScriptRoot, 'wmf4_config_data.ps1')) $configData = &$dataScript c:vagrantookch06example_configuration.ps1 -outputPath $outputPath -configData $configData | Out-Null Rename-Item -Path (Join-Path $($outputPath) 'dsc-box2.mof') -NewName 'c19fbe22-b664-4a8a-a2a1-477f16ce9659.mof' cp $outputPath* $env:PROGRAMFILESWindowsPowerShellDscServiceConfiguration New-DscChecksum -Path "$env:PROGRAMFILESWindowsPowerShellDscServiceConfiguration" -Force -Verbose New-DscChecksum -Path "$env:PROGRAMFILESWindowsPowerShellDscServiceModules" -Force -Verbose
In your production scripts, you could place the ConfigurationID
in the NodeName
field instead of the name of the node. This will cause the resulting MOF file to be automatically named with the ConfigurationID
. We chose not to do this in the example in order to have the least number of changes down to the data file in the examples.
When making the MOF files for DSC Pull Servers that use RegistrationKeys
, you do not name the MOF file with the ConfigurationID
of the target node, as there is no ConfigurationID
assigned to the target node. Instead, the target node has the same RegistrationKey
configured in its LCM that the DSC Pull Server has. This allows us to name the MOF files with descriptive human-readable names and to use DSC partial configurations. Information on the purpose and usage of RegistrationKeys
is short this early in the WMF 5 preview, so our approach here may change when WMF 5 is finally released.
The example code that follows is relatively naïve since it only handles the one MOF file we are compiling. In production, you would have this as part of a release process where you compiled and renamed the MOF according to the naming scheme you chose. Here, we're using ExampleConfiguration
, but the purpose of it is to name it in a way related to the general idea of the DSC configuration:
$outputPath = ([IO.Path]::Combine($PSScriptRoot, 'SetupTheSite')) $dataScript = ([IO.Path]::Combine($PSScriptRoot, 'wmf5_config_data.ps1')) $configData = &$dataScript c:vagrantookch06example_configuration.ps1 -outputPath $outputPath -configData $configData | Out-Null if(Test-Path (Join-Path $($outputPath) 'ExampleConfiguration.mof')){ rm (Join-Path $($outputPath) 'ExampleConfiguration.mof') } Rename-Item -Path (Join-Path $($outputPath) 'dsc-box2.mof') -NewName 'ExampleConfiguration.mof' cp $outputPath* $env:PROGRAMFILESWindowsPowerShellDscServiceConfiguration New-DscChecksum -Path $env:PROGRAMFILESWindowsPowerShellDscServiceConfiguration -Force -Verbose New-DscChecksum -Path $env:PROGRAMFILESWindowsPowerShellDscServiceModules -Force -Verbose
The result of running this script renames dsc-box2.mof
to ExampleConfiguration.mof
and then copies it to the DSC Pull Server configuration directory, finally creating the checksum files for it:
[PS]> C:vagrantookch06wmf5_04_compile_example_mof.ps1 VERBOSE: Create checksum file 'C:Program FilesWindowsPowerShellDscServiceConfigurationExampleConfiguration.mof.checksum' VERBOSE: Overwrite checksum file 'C:Program FilesWindowsPowerShellDscServiceModulesxPSDesiredStateConfiguration_3.4.0.0.zip.checksum' VERBOSE: Overwrite checksum file 'C:Program FilesWindowsPowerShellDscServiceModulesxWebAdministration_1.7.0.0.zip.checksum'