Author Posts

April 17, 2018 at 7:38 pm

Is it possible to have multiple nodenames in a the allnodes configurationdata hashtable?

@{
    Allnodes=@(
          @{
		NodeName='server1','server2','server3'
		Region='sub'
        @{
		NodeName='computeserver'
		Region='compute'

		}
    )
}

April 17, 2018 at 11:27 pm

No, it is not. If you need to group them you can use the "Role" concept that is quite commonly used.

docs.microsoft.com

April 18, 2018 at 12:22 am

That doesn't help me if i am trying to simplify my configuration file. The application I'm working with has 1 web server, and 157 compute nodes. It seems like a poor design that I'd have to put 158 unique hash table entries.

April 19, 2018 at 9:33 pm

I agree. It does feel like a design flaw. However, tools like Datum help to overcome those design flaws.

In the meantime, it's a hashtable ... just build it (it's basically what Datum does):

$NodesByRegion = @{
    sub = @(
        'server1',
        'server2',
        'server3'
    )
    compute = @('computeserver')
}

$MyData = @{
    AllNodes = [System.Collections.ArrayList] @()
}

foreach ($region in $NodesByRegion.GetEnumerator()) {
    foreach ($node in $region.Value) {
        $nodeData = @{
            NodeName = $node
            Region = $region.Name
        }
        $MyData.AllNodes.Add($nodeData) | Out-Null
    }
}

This will create $MyData for you, based on $NodesByRegion. Here is $MyData converted to JSON for depth readability:

PS > $MyData | ConvertTo-Json
{
    "AllNodes":  [
                     {
                         "NodeName":  "computeserver",
                         "Region":  "compute"
                     },
                     {
                         "NodeName":  "server1",
                         "Region":  "sub"
                     },
                     {
                         "NodeName":  "server2",
                         "Region":  "sub"
                     },
                     {
                         "NodeName":  "server3",
                         "Region":  "sub"
                     }
                 ]
}

Hope this helps. 🙂

April 19, 2018 at 11:16 pm

Thank you! I've never heard of Datum until now! It will definitely help with what I'm working on.