Ask Your Question
2

Using keys in nested hiera hash

asked 2013-07-25 19:20:21 -0600

STOIE gravatar image

updated 2013-07-25 19:21:04 -0600

Hi all,

I want to use the keys from a nested hiera hash as values for a create_resources loop in my manifest.

Is this possible and if so, how do I obtain them???

My Hiera:

---
apache:
 2.2:
  devinstance:
   somedom:
    fqdn: "somedom.com"
    alias: "www.somedom.com"
  devappsinstance:
   devappssomedom:
    fqdn: "apps.domedom.com"
    alias: "devapps.somedom.com"
 2.4:
  foobarinstance:
   yipyarr:
    fqdn: "yipyarr.com.au"
    alias: "www.yipyarr.com.au"

Lets say I am after the values (2.2 and 2.4):

And my manifest looks something like:

$apachehash = hiera('apache')
create_resources ( apache::apache_swloop, $apachehash )

define apache_swloop(...) {

        class { "apache::apache_sw ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-07-25 23:37:05 -0600

STOIE gravatar image

I actually believe I may have found the answer.

It appears like you use the "name" var for the key value in your define loop.

ie.

$apachehashdefaults = {
        $apachehash     => '2.2',
}

$apachehash = hiera('apache')
create_resources ( apache::swloop, $apachehash, $apachehashdefaults )

define swloop() {

        class { "apache::sw":
                apaversion              => $name,
        }

}

In this $name = "2.2" and "2.4"... I believe, yet to actually test it...

edit flag offensive delete link more
0

answered 2013-07-25 23:12:17 -0600

GregLarkin gravatar image

Give something like this a try:

  $apachehash = hiera_hash("apache")
  create_resources("apache::apache_sw", $apachehash)

You'll have to make sure that within your apache::apache_sw resource, you can pull apart the contents of $apachehash to get at the bits that you want. Since many of your keys are dynamically-named, I think it might be harder to do that.

You might look at restructuring your YAML file so you can always pull values out of the hash based on well-defined key names. If you get stuck with that, please post back here for further troubleshooting.

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

1 follower

Stats

Asked: 2013-07-25 19:20:21 -0600

Seen: 2,683 times

Last updated: Jul 25 '13