Ask Your Question

How to provide default value for environment variables

asked 2017-10-09 07:23:27 -0600

vaibhav gravatar image

How to provide default value for environment variables set using FACTER if user forgets to set them

edit retag flag offensive close merge delete



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?

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-09 10:27:00 -0600 )edit

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

vaibhav gravatar imagevaibhav ( 2017-10-09 12:13:51 -0600 )edit

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.

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-10 06:58:42 -0600 )edit

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

DarylW gravatar imageDarylW ( 2017-10-11 09:36:44 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-10-10 11:10:04 -0600

MichaelSmith gravatar image

You could either add the environment variable to a managed shell environment, or use a custom or external fact:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-10-09 07:23:27 -0600

Seen: 169 times

Last updated: Oct 10 '17