Environmental Variables

55 views
Skip to first unread message

Marek Dohojda

unread,
Sep 7, 2010, 7:46:11 PM9/7/10
to puppet...@googlegroups.com
Hi Everybody, I been looking through google for better part of the day but I haven't been able to find an answer to my problem.

I need an environmental variable to be present in puppet, so that yum works correctly.  However after reboot puppet doesn't read /etc/profile and starts without this profile. 
If I go into server and do services puppet restart than everything works fine, since I am running this from an interactive login.

This also doesn't work with the trick of doing FACTER_Variable= because again /etc/profile isn't being parsed so..

I tried to use "environment" in the exec class but it appears that I can't use script to set this variable.. i.e.

environment=`cat /etc/redhat-release | awk '{print $7}'`

because puppet takes above literally and doesn't convert it.

I suppose I could do something in the /etc/init.d/puppet, but the problem I have with that is that when I upgrade puppet this will get over written so I rather not, but if that's the only way to do it....

Thanks!
Marek

Jeff McCune

unread,
Sep 7, 2010, 8:04:57 PM9/7/10
to puppet...@googlegroups.com
On Tue, Sep 7, 2010 at 4:46 PM, Marek Dohojda <chr...@gmail.com> wrote:
> Hi Everybody, I been looking through google for better part of the day but I
> haven't been able to find an answer to my problem.
>
> I need an environmental variable to be present in puppet, so that yum works
> correctly.  However after reboot puppet doesn't read /etc/profile and starts
> without this profile.
> If I go into server and do services puppet restart than everything works
> fine, since I am running this from an interactive login.

If you need to read the value of an environment variable on the
master, then a custom function could do this easily. Simply return
ENV['PATH'] or whatever environment variable you want in the custom
function block.

# <modulepath>/customfunctions/lib/puppet/parser/functions/getenv.rb
module Puppet::Parser::Functions
newfunction(:getenv, :type => :rvalue ) do |args|
ENV[args[0]]
end
end

# Example
$rubylib = getenv("RUBYLIB")

If you need to read the value of an environment variable on the agent,
then a custom fact could do this easily.

# <modulepath>/customfacts/lib/facter/env_path.rb
require 'facter'
Facter.add('env_path') do
setcode do
ENV['PATH']
end
end

Hope this helps,
--
Jeff McCune
http://www.puppetlabs.com/

Jeff McCune

unread,
Sep 7, 2010, 8:52:38 PM9/7/10
to puppet...@googlegroups.com
On Tue, Sep 7, 2010 at 4:46 PM, Marek Dohojda <chr...@gmail.com> wrote:
> I need an environmental variable to be present in puppet, so that yum works
> correctly.

Could you describe the problem a bit more? What environment variable
are you setting? What's the 7th field in /etc/redhat-release you're
trying to get? Why is yum not working correctly without this
information?

Reply all
Reply to author
Forward
0 new messages