I need to write a function that will, in order to do the following, to read the value of a variable:
- Check if a specific facter variable exists. If not,
- Read the value of the variable from Hiera. If not,
- Use the default value.
I managed to do this in my Puppet script using this if condition.
# foo is read from (in order of preference): facter fact, hiera hash, hard coded value if $::foo == undef { $foo = hiera('foo', 'default_value') } else { $foo = $::foo }
But I want to avoid repeating this if condition for every variable that I want to analyze in this way, and therefore thought about writing a new Puppet function of the format get_args('foo', 'default_value') , which will return me the value from
- fact of fact, if it exists,
- hiera variable or
- just return
default_value .
I know that I can use lookupvar to read the fact from the ruby ββfunction. How to read hiera variable from my ruby ββPuppet function?
source share