Hashtable data

The most flexible and preferred method is to use the ConfigurationData hashtable. This specifically structured hashtable provides a flexible way of declaring frequently changing data in a format that DSC will be able to read and then insert into the MOF file as it compiles it. This approach will be covered in greater detail later in Chapter 3, DSC Configuration Files, but it must be included in this chapter to fully describe the DSC architecture. Don't worry too much if the importance of this feature is not readily apparent. With the following command lines, we define a specifically formatted hashtable called $data:

    $data = @{
# Node specific data
# Note that is an array of hashes. It's easy to miss
# the array designation here
AllNodes = @(
# All the WebServers have this identical config
@{
NodeName = "*"
WebsiteName = "FooWeb"
SourcePath = "C:FooBar"
DestinationPath = "C:inetpubFooBar"
DefaultWebSitePath = "C:inetpubwwwroot"
},
@{
NodeName = "web1.foobar.com"
Role = "Web"
},
@{
NodeName = "web2.foobar.com"
Role = "Web"
},
@{
NodeName = "sql.foobar.com"
Role = "Sql"
}
);
}

configuration FooBar
{
# Dynamically find the web nodes from configuration data
Node $AllNodes.where{$_.Role -eq "Web"}.NodeName
{
# Install the IIS role
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
}
}
}
# Pass the configuration data to configuration as follows:
FooBar -ConfigurationData $data

The first item's key is called the $AllNodes key, the value of which is an array of hashtables. The content of these hashtables is free form and can be whatever we need them to be, but they are meant to express the data on each target node. Here, we specify the roles of each node so that inside the configuration, we can perform a where clause and filter for only the nodes that have a web role.

If you look back at the $AllNodes definition, you'll see the three nodes we defined (web1, web2, and sql), but also notice one where we just put an * sign in the NodeName field. This is a special convention that tells DSC that all the information in this hashtable is available to all the nodes defined in this AllNodes array. This is an easy way to specify defaults or properties that apply to all nodes being worked on. We'll cover some strategies for this as we move forward in the book.

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

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