puppethiera

Create new array from hiera_hash, but avoid nested data


I have a hiera_hash that looks like this:

signalfx_custom_receivers:
  smartagent/http1:
    type: http
    host: "es.mydomain.tv"
    useHTTPS: true
  smartagent/http2:
    type: http
    host: "es.other.tv"
    useHTTPS: true
  smartagent/http3:
    type: http
    host: "pmd-akamai.cdn.mydomain.tv"
    useHTTPS: true

I'm trying to generate an array from this to use elsewhere. The array should only contain smartagent values, so should looks like this:

[smartagent/http1, smartagent/http2, smartagent/http3]

I've tried the following:

$signalfx_custom_pipeline   = Array($signalfx_custom_receivers)

However, this includes all of the nested key/values, and ends up looking like this:

[["smartagent/http1", {"type"=>"http", "host"=>"es.mydomain.tv", "useHTTPS"=>true}], ["smartagent/http2", {"type"=>"http", "host"=>"es.other.tv", "useHTTPS"=>true}], ["smartagent/http3", {"type"=>"http", "host"=>"pmd-akamai.cdn.mydomain.tv", "useHTTPS"=>true}]]

How can I generate an array, but avoid adding these nested values?


Solution

  • I'm trying to generate an array from this to use elsewhere. The array should only contain smartagent values

    That is, the keys of the hash. Extracting these is exactly what the built-in keys() function does:

    $signalfx_custom_pipeline = keys($signalfx_custom_receivers)
    
    # or
    
    $signalfx_custom_pipeline = $signalfx_custom_receivers.keys()
    

    The two forms behave identically, but personally, I find the second clearer in this case.