Uploaded image for project: 'Hiera'
  1. Hiera
  2. HI-517

Lookup on hash of arrays

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Incomplete
    • Affects Version/s: HI 3.2.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Template:

      Description

      Hello, I am not sure if this is possible at all, but let me introduce with challenge I am experiencing.
      I have this configuration:

      cloud::provision:
        'strname':
          key1: str1
          key2: str2
          sg_key:
            -
              protocol: 'tcp'
              port: '1111'
              cidr: '172.31.0.0/16'
            -
              protocol: 'tcp'
              port: '2222'
              cidr: '172.31.0.0/16'
            -
              protocol: 'tcp'
              port: '3333'
              cidr: '172.31.0.0/16'
      

      So, I have a lot of these rules (array of hashes) for every security group for every EC2 instance on AWS. I want to simplify whole process and make a lookup like this:

      common.yaml

      lookupkey:
            -
              protocol: 'tcp'
              port: '1111'
              cidr: '172.31.0.0/16'
            -
              protocol: 'tcp'
              port: '2222'
              cidr: '172.31.0.0/16'
            -
              protocol: 'tcp'
              port: '3333'
              cidr: '172.31.0.0/16'
      

      and have this:

      cloud::provision:
        'strname':
          key1: str1
          key2: str2
          sg_key: "%{hiera('lookupkey')}"
      

      Doing a lookup from CLI (first example), I am getting this response:

      {"strname"=>
        {"key1"=>"str1",
         "key2"=>"str2",
         "sg_key"=>
          [{"protocol"=>"tcp", "port"=>"1111", "cidr"=>"172.31.0.0/16"},
           {"protocol"=>"tcp", "port"=>"2222", "cidr"=>"172.31.0.0/16"},
           {"protocol"=>"tcp", "port"=>"3333", "cidr"=>"172.31.0.0/16"}]}}
      

      If I try to do a lookup in second example (with hiera lookup), I am getting this:

      {"strname"=>
        {"key1"=>"str1",
         "key2"=>"str2",
         "sg_key"=>
      "[{\"protocol\"=>\"tcp\", \"port\"=>\"1111\", \"cidr\"=>\"172.31.0.0/16\"}, {\"protocol\"=>\"tcp\", \"port\"=>\"2222\", \"cidr\"=>\"172.31.0.0/16\"}, {\"protocol\"=>\"tcp\", \"port\"=>\"3333\", \"cidr\"=>\"'172.31.0.0/16\"}]"}}
      
      

      Is this possible at all? Thanks.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            d.susic Dusan Susic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support