Multiple servers Allnodes hashtable

Welcome Forums DSC (Desired State Configuration) Multiple servers Allnodes hashtable

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
9 months ago.

  • Author
    Posts
  • #99069

    Participant
    Points: 3
    Rank: Member

    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

    Participant
    Points: 1
    Rank: Member

    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

      Participant
      Points: 3
      Rank: Member

      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

      Participant
      Points: 0
      Rank: Member

      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

      Participant
      Points: 3
      Rank: Member

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

The topic ‘Multiple servers Allnodes hashtable’ is closed to new replies.