1

I'd like to set a value used repeatedly by several classes and resources from Hiera. In other words, set a global parameter through Hiera. So, in the appropriate yaml file, I have:

myvarr: 'foo'

Then, in the manifests, I tried:

if $myvar == 'foo'

as well as

if $::myvar == 'foo'

to no avail. How is this done? Looking at the Puppet docs didn't help much, all I saw was class based examples.

  • try with $var = hiera('myavr') – c4f4t0r Jul 29 '15 at 17:42
  • @c4f4t0r yup - that's what I needed. If you post that as an answer, I'll happily accept it. – MrSilverSnorkel Jul 29 '15 at 19:08
2

From puppet 3, puppet does hiera automatic lookup, but if you have many modules or classes, doing automatic lookup for every module or class variable increase the catalog compilation time, for disable automatic lookup

data_binding_terminus = none

I prefer make explicit call, only where I need to get data from hiera:

$var = hiera('foo')
| improve this answer | |
0

Hiera injects the variable into a class. So you need to define a class my class and in your hiera use myclass::var: foo . This will make var=foo inside myclass.

Also, hiera should be used for overwriting default values, not set defaults.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.