ConfigurationData

The $ConfigurationData variable is a hash table that accepts any data you want. Why would we need another variable that can accept any data? The main difference between this variable and the $Node variable is that the $ConfigurationData variable is global. It does not contain target node-specific information but information that is applicable to the environment as a whole.

Why is this needed? Looking back at our explanation for the $AllNodes variable, we decided whether to install IIS if a server had the Role property defined inside each target node hash table. This was something that was applicable per server and changed depending on which server you were examining. There are some things (settings, values, applications, and so on) that are applicable to all servers no matter what and that you want applied on all servers.

An example of this is an application that must be present on all servers and have the same configuration set in its configuration file. Set the values in the ConfigurationData hash table once, and it will be available to each target node you run this on instead of having to specify the values in each target node hash in the $AllNodes array.

To show how this is specified, we'll steal another example from later on in this chapter but will reduce it just to show the use of $ConfigurationData:

# data file
@{
AllNodes = @(
@{
NodeName = "server1"
},
@{
NodeName = "server2"
}
);
NonNodeData = @{
ConfigFileContents = (Get-Content "Config.xml")
}
}
# end of data file

# beginning of the example configuration
Configuration MyConfiguration
{
Node $AllNodes.NodeName
{
File ConfigFile
{
DestinationPath = "c:foo.txt"
Contents = $ConfigurationData.NonNodeData.ConfigFileContents
}
}
}
# ending of the example configuration

The preceding example will not work if you copy and paste it and try to run it, as we have not covered how to pass configuration data to a configuration block yet; this is only an example.

In our data file, we store the contents of _config.xml_ in a variable called $ConfigFileContents and use that to create a file on each target node. Since this is something that is created on all our servers, we only have to specify it once in the $ConfigurationData section.

In practice, this is for data that does not change much and is generally static. This variable is not used as much, as the power of the inheritance and granularity of the $AllNodes array allows a lot of flexibility while reducing the amount of repeated information.

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

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