Using Hiera to set global variables

puppet

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.

Best Answer

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')