Ask Your Question
0

How to provide default value for environment variables

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

vai 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

Comments

1

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

vai gravatar imagevai ( 2017-10-09 12:13:51 -0500 )edit
1

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 -0500 )edit
1

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 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-10-10 11:10:04 -0500

MichaelSmith gravatar image

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...

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

Stats

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

Seen: 49 times

Last updated: Oct 10