I'm working on configuring servers using Powershell Desired State Configuration (DSC). I have several different groups of IIS servers. The configuration for all of them is about 90% identical, but there are differences between the groups.
In order to follow good programming practices and re-use the common code, I attempted to use multiple configuration objects to configure the groups. There was one configuration object full of common configuration, and then each group had a configuration object with group specific config. It looked something like this:
Configuration CommonConfiguration { Node "IISServer1" { #Common configuration settings go here, such as this one (to keep things brief, I'm only showing one setting... there would be many more): WindowsFeature Role_Web_Server_IIS { Ensure = "Present" Name = "Web-Server" } } } Configuration IISGroup1Configuration { Node "IISServer1" { #Configuration resources for group1 go here. Again, much shorter than real life. WindowsFeature Feature_ASP_Dot_Net_4_5 { Ensure = "Present" Name = "Web-Asp-Net45" } } }
To fully configure a server in my first group of IIS servers, I would need to use both these configuration objects by running them like this:
CommonConfiguration IISGroup1Configuration Start-DscConfiguration -Path ".\CommonConfiguration\" Start-DscConfiguration -Path ".\IISGroup1Configuration\"
DSCConfiguration runs twice and starts two Powershell jobs, both of which seem to complete. But there is a problem, and I'm wondering if it is at all solvable.
Problem:
When I try to use other DSC cmdlets to control my server's configuration, such as Restore-DCSConfiguration or Get-DSCConfiguration, it only seems to work on what ever configuration object ran last. For example, Get-DSCConfiguration returns only the IISGroup1Configuration, because that ran last. I've tried playing around with order, and whichever configuration I run last is what is returned. Similarly, if I were to try to keep my configuration enforced with restore-configuration, it's only going to work on IISGroup1Configuration, because it ran last. This is an example of what I ran that returned only one of the configuration objects.
Get-DscConfiguration -CimSession "IISServer1"
The behavior I want is for the server to treat ever configuration block run on it as its configuration and return all of them. But since it doesn't, does this mean I have to have everything needed to configure a server in a single configuration block? For example, if I wanted to use DSC to configure two groups of IIS servers, would I have to have the following?
Configuration Group1 { Node "IISServer1" { #---Common configuration, 90% the same--- #---Group 1 specifics---- } } Configuration Group2 { Node "IISServer2" { #---Common configuration copy pasted in, 90% the same--- #---Group 2 specifics---- } }
If this is how I have to do things, and a node can have only one configuration block be its "configuration", then this is absolutely terrible from a code reuse perspective. If I have six groups of servers, and I want to edit some shared code, I'm going to have to go into six groups of configuration objects and edit the same line six times. That leads to errors and makes a mess. Is there any way to avoid this, while have the server consider all configuration objects run against it to be part of its configuration?