So I am looking at setting up DSC to manage environments for multiple projects, and within my DSC Configuration I can select the nodes to apply configuration to in one of three ways…
If I want to build the entire environment for one project I can pass in a parameter $Project and use that to select the nodes for the Node{} block to create mof’s for.
Node $AllNodes.where { $_.Project -eq “$Project” }.NodeName
{
…
}
If I want to build all the web servers I can pass in a parameter $Role and select the nodes based on that
Node $AllNodes.where { $_.Role -eq “$Role” }.NodeName
{
…
}
which builds all the web-servers for all the projects, so I can also set up my Node selection like this
Node $AllNodes.where { ($_.Project -eq "$Project") -and ($_.Role -eq "$Role" ) }.NodeName
{
......
}
And that will build all the servers of the select role for the selected project.
It’s a bit messy.
Problem is, to do this I have a bunch of if/else statements to interrogate the parameters and then select one of the three version of the Node{} block to execute.
As I say, messy.
What I would like to try is creating that Node selection string on the fly, I could interrogate the parameters, construct the Node selection criteria, and just have a single Node {} block. That would make sense to me.
Something like this…
If ( $Project -and $Role){
$NodeSelection = “($.Project -eq “$Project”) -and ($.Role -eq “$Role” )”
}ElseIf ( $Project){
$NodeSelection = “($.Project -eq “$Project”)"
}If ( $Role){
$NodeSelection = "($.Role -eq “$Role” )”
}
Node $AllNodes.where{$NodeSlection}.NodeName
{
…
}
However, no matter what I do, the "$" in the $NodeSelection either gets interpreted when the $NodeSelection string is created, evaluating to $null, or it never gets evaluated at all and stays as '$’ in the final evaluation.
This may or may not be the right way to go about what I am doing, but I’d like to see if it could be done, now that I have started.
Any suggestions?
Thanks, Simon.