Ask Your Question
0

print array of keys from a nested hash

asked 2016-02-03 16:31:45 -0600

gschandra gravatar image

updated 2016-02-03 16:34:02 -0600

Hi, I have a nested hiera hash like the following:

uat_rev3:
  node1:
    hostname: host1
    http_port: 3011
  node2:
    hostname: host2
    http_port: 3011

I want to store the value "node1,node2" in a variable. Can you please suggest a good way of doing that? is there a hiera function i can use to get that information.

Thanks a lot for your help.

Thanks, Sarat.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-02-04 01:47:44 -0600

jon6000 gravatar image

updated 2016-02-04 01:51:05 -0600

You can use puppetlabs/stdlib:

puppet module install puppetlabs/stdlib

You can then make use of the 'keys' function.

$my_keys = keys($uat_rev3)

Jon

edit flag offensive delete link more
-1

answered 2016-02-04 15:05:56 -0600

gschandra gravatar image

Thanks a lot Jon. This is exactly what I was looking for.

edit flag offensive delete link more

Comments

1

you probably wanted to add a comment to Jon's answer :-) and not a new answer to your question.

Henrik Lindberg gravatar imageHenrik Lindberg ( 2016-02-07 18:27:29 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-02-03 16:31:45 -0600

Seen: 310 times

Last updated: Feb 04 '16