Compiling configurations for local target nodes

Our focus in this chapter is on how to push DSC configurations and not how to use DSC configurations, so our example configuration is simple and short. This reduces the amount of code we are working with and the amount of logging we output, which allows us to fit the DSC configurations in our chapter without having pages of printouts.

At this point, you should be familiar with compiling DSC configuration scripts into MOF files. In this chapter, we make the assumption that you have a good grasp of the DSC configuration block syntax and how to use and author DSC configuration scripts. If you are skipping around or feeling fuzzy about these concepts, refer to these chapters before you continue.

In our example script, we will create a text file on the primary drive with dummy contents. Again, we are purposely not being fancy here in order to focus on how to push DSC configurations and not the DSC configurations themselves:

Configuration SetupAllTheThings
{
  Node "localhost"
  {
    File CreateFile
    {
      Ensure          = "Present"
      DestinationPath = "c:	est.txt"
      Contents        = "Wakka"
    }
  }
}

$mofPath = [IO.Path]::Combine($PSScriptRoot, "SetupAllTheThings") SetupAllTheThings -OutputPath $mofPath

Compiling the preceding DSC configuration script gives us a valid MOF file that we can use on the local computer. This should all be straightforward for you by now, and you should see the following results from the compiling of the MOF file:

[BOX1 PS] > C:vagrantSetupAllTheThings.ps1
    
    Directory: C:vagrantSetupAllTheThings
    
    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    -----         7/01/2015   3:19 PM       1276 localhost.mof
  

If that doesn't compile correctly, look at your syntax and ensure it's the same as what we have laid out here. It may help if you add the Verbose parameter to our DSC configuration function to see what is going on as the MOF is compiled. If you are still having trouble or want to see even more information, then you can set your $DebugPreference to Continue and receive even more diagnostic information. An example output is as follows:

DEBUG:    MSFT_PackageResource: ResourceID = [Package]InstallTheThing
DEBUG:    MSFT_PackageResource:  Processing property 'DependsOn' [
DEBUG:    MSFT_PackageResource:    Processing completed 'DependsOn' ]
DEBUG:    MSFT_PackageResource:  Processing property 'Ensure' [
DEBUG:    MSFT_PackageResource:    Processing completed 'Ensure' ]
DEBUG:    MSFT_PackageResource:  Processing property 'Name' [
DEBUG:    MSFT_PackageResource:        Canonicalized property 'Name' = 'The Thing'
DEBUG:    MSFT_PackageResource:    Processing completed 'Name' ]
DEBUG:    MSFT_PackageResource:  Processing property 'Path' [
DEBUG:    MSFT_PackageResource:   Canonicalized property 'Path' = 'c:allthethings	hing.msi'
DEBUG:    MSFT_PackageResource:    Processing completed 'Path' ]
DEBUG:    MSFT_PackageResource:  Processing property 'ProductId' [
DEBUG:    MSFT_PackageResource:   Canonicalized property 'ProductId' = '{8f665668-7679-4f53-acde-06cf7eab5d73}'  
Sometimes, it's hard to see the exact error in the DSC output, so get used to using PowerShell to inspect the built-in $error array to drill down and find the exact information you need, as shown here:
[BOX1 PS] > $error[0] | Format-List -Property * -Force  

If we examine the localhost.mof file, we will see that the file resource laid out applies to a target node named localhost. This means that although we compile this MOF file on the computer we are sitting at, this MOF file can be pushed to any computer, whether locally or remotely, because localhost applies to any computer. If we wanted to restrict which target nodes used specific MOF files, we would need to specify their host names in the Node block. We will cover this when we deal with pushing DSC configurations remotely in a little bit.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset