How can I reload environment variable file using puppet?

2,178 views
Skip to first unread message

Tim C

unread,
Nov 8, 2010, 5:01:43 PM11/8/10
to Puppet Users
Hi I'm trying to setting http_proxy environment variable by adding it
to the /etc/environment file.

I was wondering how I can force puppet to reload this file whenever
the file changes.

I have tried a few things and none of them have worked,

1.)
exec { "source_environment":
command => "source /etc/environment",
subscribe => File["/etc/environment"],
refreshonly => true
}


2.)
exec { "source /etc/environment":
subscribe => File["/etc/environment"],
refreshonly => true
}

3.)
exec { "export http_proxy="http://localhost:3128"":
subscribe => File["/etc/environment"],
refreshonly => true
}


Is there a better way to do this? I just need to ensure that the
environment var http_proxy is globally set.

Richard Crowley

unread,
Nov 8, 2010, 5:11:09 PM11/8/10
to puppet...@googlegroups.com

No subshell will be able to modify the parent's environment, which is
what you're after. Try setting environment variables in the Puppet
process's environment:

rcrowley@wd-40:~$ puppet apply test.pp
warning: Could not retrieve fact fqdn
notice: /Stage[main]//Exec[sh -c 'echo $HOOAH >/tmp/foo']/returns:
executed successfully
rcrowley@wd-40:~$ cat /tmp/foo

rcrowley@wd-40:~$ HOOAH=hooah puppet apply test.pp
warning: Could not retrieve fact fqdn
notice: /Stage[main]//Exec[sh -c 'echo $HOOAH >/tmp/foo']/returns:
executed successfully
rcrowley@wd-40:~$ cat /tmp/foo
hooah
rcrowley@wd-40:~$

Setting values in /etc/environment will probably work provided you
restart the Puppet process in question after the contents of that file
have been set.

Hope that helps,

Richard

Tim C

unread,
Nov 8, 2010, 5:48:31 PM11/8/10
to Puppet Users
Thanks for you help.

Does that mean that there is no way to do it from inside of a puppet
module?

jcbollinger

unread,
Nov 9, 2010, 9:49:21 AM11/9/10
to Puppet Users


On Nov 8, 4:48 pm, Tim C <tcolli...@gmail.com> wrote:
> Thanks for you help.
>
> Does that mean that there is no way to do it from inside of a puppet
> module?

It means that there is no way at all to do it from inside Puppet that
will affect the current execution of Puppet itself.

Puppet does a lot of calling out to external programs, however, and if
you're trying to make the environment change effective immediately for
something that is performed in such a call then you may be able to do
it. I'd recommend creating a custom function for that purpose; the
key (Ruby) statement would be writing to the Ruby ENV hash:
ENV['http_proxy'] = 'http://localhost:3128'. You can find more
information on writing custom functions here:
http://docs.puppetlabs.com/guides/custom_functions.html.

Having said all that, I'm curious what you're trying to do that
requires the environment variable to apply to anything in the current
Puppet run. There might be an alternative that avoids the problem
altogether.


John

James Bailey

unread,
Nov 9, 2010, 2:12:26 AM11/9/10
to puppet...@googlegroups.com
On 8 November 2010 22:48, Tim C <tcol...@gmail.com> wrote:
> Thanks for you help.
>
> Does that mean that there is no way to do it from inside of a puppet
> module?
>
Please forgive I am new to Puppet but the question seem to be does
Puppet respond to standard process signals so for example if puppet
responds in the modern way to a SIGHUP and rereads it config files
then a variable if would be changed, if changed. If it does then
sending that signal from inside a Puppet module should work.

Jim

Reply all
Reply to author
Forward
0 new messages