Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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

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.

share|improve this answer

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

 $ 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 ?

share|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
Excellent answer. I wasted a lot of time not noticing that all Facter variables have lowercase names even if the environment variable has an uppercase name. Everybody pay close attention to the example jnrg gives. – Russell Silva Jan 15 '13 at 17:00
there is broken link – kenorb Jun 9 '14 at 12:10

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


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

Use it in your manifests like:

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

In Puppet enterprise 2.5.1 you can access it via /etc/env.

Also check whether you have the correct environment defined in your /etc/puppetlabs/puppet/puppet.conf -- it should look something like this:

  modulepath = /etc/puppetlabs/puppet/environments/production/modules:/opt/puppet/share/puppet/modules
  manifest   = /etc/puppetlabs/puppet/environments/production/manifests/site.pp
share|improve this answer

The answer is a bit disappointing: You can't (unless you enhance Puppet or Facter). I recently wrote a short blog post about this topic: Accessing environment variables within Puppet

A short summary: Facter is running on every Puppet agent system. Simply enhance Facter to collect all environment variables and then you can access them within Puppet manifests.

Hope that helps!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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