How to provide default value for environment variables
How to provide default value for environment variables set using FACTER if user forgets to set them
You could either add the environment variable to a managed shell environment, or use a custom or external fact: https://docs.puppet.com/facter/3.9/cu...
Asked: 2017-10-09 07:23:27 -0500
Seen: 111 times
Last updated: Oct 10 '17
Please be more specific. Do you mean $environment, $facts[my_custom_fact], /proc/self/environ? Where are you: Are you in a manifest, a custom fact implementation, or on your client running puppet-agent? By what means is the user supposed to set the “environment variable”'s value?
I am using export FACTER _layout to set the variable layout. The variable layout is used in a puppet manifest. I want to somehow set a default value for layout in the manifest if the user forgets to set it using the above methof
Can't you just test $_facter_layout = defined($FACTER_layout) ? {true => $FACTER_layout, default => 'foobar',} Or do you need/want to change the process' environment? What is this FACTER_layout anyway? I never heard of nor can I find some documentation about it.
FACTER_foo=bar will give you a facter fact named 'foo' with the value 'bar'. I have used this to force/simulate some values for local spot testing, or overriding behavior. For the OP's case, I would use your suggestion above to check if the fact exists with a value, and if it doesn't, use default