How do I access an environment variable (from the puppet daemon's environment) in a puppet manifest?

link|improve this question

58% accept rate
Do you mean a variable generated by facter? – Scott Pack Mar 30 '10 at 0:49
I mean the bash environment variables like $PATH and $USER. – joeforker Mar 30 '10 at 12:44
feedback

3 Answers

From what I can tell Puppet runs without any Bash environment variables. It seems to get all its environment from Facter. There is a script here to import your regular envvars as Facter envvars.

link|improve this answer
feedback

I think we need more informations on what you are trying to achieve... Facter exposes by default FACTER_ environment variables :

http://docs.reductivelabs.com/guides/faq.html#can_i_access_environmental_variables_with_facter

 $ FACTER_FOO="bar" 
 $ export FACTER_FOO
 $ facter | grep 'foo'
   foo => bar

But for $PATH or $USER... Why not tells puppet to use a given path or a user (for an exec ?) explicitly ?

link|improve this answer
It's very ordinary to control an interpreter with environment variables, for a variety of reasons... especially if you think about sometimes running puppet as an interpreter (in the #! line?) instead of a daemon... – joeforker Mar 31 '10 at 19:29
feedback

You'd need to use a server side function for this if you want the puppetmaster's environment. Since facter gets you client facts.

$RUBYLIB/puppet/parser/functions/env.rb:

module Puppet::Parser::Functions
  newfunction(:env) do |args|
    variable = args[0]
    ENV[variable]
  end
end

Use it in your manifests like:

$blah = env("PATH")
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.