The Windows PowerShell Blog has been writing about PowerShell's Desired State Configuration (DSC). DSC is the Microsoft's proposal for computer's configuration management on the Windows world. One of the last articles explains how DSC allows both push and pull configuration modes.
Desired State Configuration is an addition to the PowerShell tool which gives the possibility of declaring what is the desired configuration of a given node, or machine. This is a different approach from what PowerShell already allowed with an imperative style. Instead of focusing on what steps are to be executed in order to configure a machine, a script that leverages DSC just states the intended configuration. It is for the PowerShell DSC system to decide on how to do it.
PowerShell DSC has the concept of resources. Resources are building blocks that allow the configuration of items such as: users; groups; server roles or registry entries. PowerShell DSC already has several built-in resources, but it is possible to create custom ones. The following example uses the File resource to state that on localhost
the contents of C:\inetpub\wwwroot
should be an exact replica of C:\SiteFiles
:
Configuration SiteConfig { # A Configuration block can have zero or more Node blocks Node "localhost" { # File is a built-in resource you can use to manage files and directories # This example ensures files from the source directory are present in the destination directory File MyFileExample { Ensure = "Present" # You can also set Ensure to "Absent" Type = "Directory“ # Default is “File” Recurse = $true SourcePath = "C:\SiteFiles" # This is a path that has web files DestinationPath = "C:\inetpub\wwwroot" # The path where we want to ensure the web files are present } } }
To apply a configuration, PowerShell offers two modes: push and pull. Push mode is triggered immediately by the execution of the Start-DscConfiguration
cmdlet. For instance, the following command applies the configuration on the current path to all the specified nodes inside the script:
Start-DscConfiguration -Wait -Verbose -Path .
Pull mode gives the initiative to the nodes themselves. It is a node's responsibility to poll a pull server to check for new configurations. When a new configuration is available, the Local Configuration Manager (LCM) - Powershell DSC's engine - downloads and applies it. Pull mode is a bit more complex to setup: the pull server, a web site, needs to be configured; and a LCM needs to be configured on each target node, via the Set-DscLocalConfigurationManager
. The Windows Powershell team published an article with a helper tool to make it easier to setup the pull server.
Although most tools support both modes, some, like Ansible, favor push while others, such as Puppet or Chef, favor pull. There are many arguments for and against each mode. Push mode is more associated with simplicity and control: it doesn't require the installation of any specific software on the target nodes and the configuration is triggered at the user's request. Pull mode is associated with scalability and rich metadata capabilities: the target nodes do the configuration themselves, asynchronously, and the pull server can store metadata of each target node state in a central location.