Ask Your Question
0

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

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

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-08 15:22:52 -0600

You virtually build a new hash by writing a hash literal:

{$facts['fqdn'] => $lookup_var[$facts['fqdn']]}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-07-25 12:25:44 -0600

Seen: 321 times

Last updated: Oct 08