Multiple servers Allnodes hashtable

This topic contains 4 replies, has 3 voices, and was last updated by  Brian 3 months ago.

  • Author
    Posts
  • #99069

    Brian
    Participant

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

    @{
        Allnodes=@(
              @{
    		NodeName='server1','server2','server3'
    		Region='sub'
            @{
    		NodeName='computeserver'
    		Region='compute'
    
    		}
        )
    }
    
    
  • #99117

    Wayne Hoggett
    Participant

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

    docs.microsoft.com

    • #99118

      Brian
      Participant

      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.

    • #99285

      Raymond Piller
      Participant

      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. 🙂

    • #99295

      Brian
      Participant

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

You must be logged in to reply to this topic.