Another common challenge with DSC, is how to compose DSC configurations.
People have seen the trick of having a Configuration, and the following code within:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Configuration MyDSCConfig { | |
Node $ConfigurationData.AllNodes.nodename { | |
if($Node.roles -contains 'MyRole') { | |
# do stuff here, like calling DSC Resources | |
MyCompositeResource StuffForMyRole { | |
# … | |
} | |
} | |
if($Node.roles -contains 'MyOtherRole') { | |
MyOtherResource OtherStuff { | |
# … | |
} | |
} | |
} | |
} |
This is a good way to get started and works well for small-ish configurations, but it gets out of hand pretty quickly, as it’s hard to read all the if
statements and their content. Some variant of this are using Where
clauses around the Node expression.