Jira (HI-637) Allow usage of Hash Keys as Array

1 view
Skip to first unread message

Martin Alfke (Jira)

unread,
Jan 3, 2023, 6:12:03 AM1/3/23
to puppe...@googlegroups.com
Martin Alfke created an issue
 
Hiera / Improvement HI-637
Allow usage of Hash Keys as Array
Issue Type: Improvement Improvement
Assignee: Unassigned
Created: 2023/01/03 3:11 AM
Priority: Normal Normal
Reporter: Martin Alfke

Within YAML it is possible to specify a hash key as an array:

cat yaml.yaml 
---
hash:
  ['key1', 'key2']:
    param: 'value' 

One can use the YAML.load_file method:

irb 
2.5.8 :001 > require 'yaml'
 => true 
2.5.8 :002 > data= YAML.load_file('yaml.yaml')
 => {"hash"=>{["key1", "key2"]=>{"param"=>"value"}}} 
2.5.8 :003 > puts data
{"hash"=>{["key1", "key2"]=>{"param"=>"value"}}}
 => nil 
2.5.8 :004 > exit

Within Hiera YAML Data, the usage of an array as Hash Key title is not possible:

Running Puppet lookup explain:

Searching for "hash"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Hierarchy entry "Classifier Configuration Data"
      No such key: "hash"
  Environment Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
    Hierarchy entry "yaml hierarchy"
      Path "/etc/puppetlabs/code/environments/production/data/nodes/puppet5.yaml"
        Original path: "nodes/%{facts.networking.hostname}.yaml"
        No such key: "hash"
      Path "/etc/puppetlabs/code/environments/production/data/role/-.yaml"
        Original path: "role/%{facts.external_facts.role}-%{facts.external_facts.env}.yaml"
        Path not found
      Path "/etc/puppetlabs/code/environments/production/data/role/.yaml"
        Original path: "role/%{facts.external_facts.role}.yaml"
        Path not found
      Path "/etc/puppetlabs/code/environments/production/data/role/.yaml"
        Original path: "role/%{trusted.extensions.pp_role}.yaml"
        Path not found
      Path "/etc/puppetlabs/code/environments/production/data/os/RedHat.yaml"
        Original path: "os/%{facts.os.family}.yaml"
        Path not found
      Path "/etc/puppetlabs/code/environments/production/data/zone/.yaml"
        Original path: "zone/%{facts.external_facts.zone}.yaml"
        Path not found
      Path "/etc/puppetlabs/code/environments/production/data/common.yaml"
        Original path: "common.yaml"
        Found key: "hash" value: nil

When adding also a string key only the string key gets returned:

hash:
  'ele1':
    param: 'value'
  ['key1', 'key2']:
    'param': 'value'  

Return value:

        Found key: "hash" value: {
          "ele1" => {
            "param" => "value"
          } 

Especially in combination with stdlib::manage::create:resources an Array as Hash Key makes sense:

stdlib::manage::create_resources:
  package:
    ['less', 'vim', 'htop']:
      ensure: present

But that is not (yet) possible.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages