Help extracting full hash (with title) from a hash of hashes.

asked 2018-07-25 12:25:44 -0500

scottyish gravatar image

I have a YAML that looks like this:

Cluster_list:
  server1.domain.com:
    port: 1234
    ssl_port: 0987
  server2:domain.com:
    port: 1234
    ssl_port: 0987
  server3.domain.com:
    port: 1234
    ssl_port: 0987

The lookup would give a hash like this into the variable:

{server1.domain.com => {port => 1234, ssl_port => 0987}, server2:domain.com => {port => 1234, ssl_port => 0987}, server3.domain.com => {port => 1234, ssl_port => 0987}}

I can then grab one of the internal hashes using a subscript of ['server2.domain.com']... this returns the children of server2.domain.com. How can I also get the title for this hash into the variable?

What I want to do is basicially:

$this_server = $lookup_var[$facts[fqdn]]

and end up with $this_server having the full hash: server2:domain.com => {port => 1234, ssl_port => 0987}

edit retag flag offensive close merge delete