How to setup a default hiera lookup value

2019-08-25 03:15发布

问题:

I am setting up my Puppet code using Hiera such that if a value is not found in Hiera, it assigns a default value to it. I am not getting the desired results and wanted to know how others did it :

lookup( <NAME>, [<VALUE TYPE>], [<MERGE BEHAVIOR>], [<DEFAULT VALUE>] )

I think I found the answer https://www.devco.net/archives/2016/03/13/the-puppet-4-lookup-function.php , will try it shortly

lookup({"name" => "some::thing", "default_value" => "default"})

回答1:

The solution that worked for me was :

$myvar1 = lookup( { "name" => "myvar1", "default_value" => "default" } )


回答2:

Generally , if the value logpath is declared in hiera . Puppet manifest will pick up the value automatically .If it is not found in Hiera , then puppet agent will error out saying that value is not found .

If the value is not declared in Hiera , there is always a way where in one can declare the value in puppet manifest . if the value is not find in Puppet Hiera , then manifest is looked into for the puppet value .

As a good practice , value is declared in hiera and as well as puppet manifest .If the value is not found in Hiera , puppet will look into variable present in manifest



标签: puppet hiera