Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Environment Variables with Puppet

Tags:

I am using vagrant with puppet to set up virtual machines for development environments. I would like to simply set a few environment variables in the .pp file. Using virtual box and a vagrant base box for Ubuntu 64 bit.

I have this currently.

$bar = 'bar'  class foobar {    exec { 'foobar':      command => "export Foo=${bar}",    } } 

but when provisioning I get an error: Could not find command 'export'.

This seems like it should be simple enough am I missing some sort of require or path for the exec type? I noticed in the documentation there is an environment option to set up environment variables, should I be using that?

like image 712
bgrantdev Avatar asked Aug 23 '13 21:08

bgrantdev


People also ask

What are environments in puppet?

An environment is an isolated group of agent nodes that a primary server can serve with its own main manifest and set of modules. For example, you can use environments to set up scratch nodes for testing before rolling out changes to production, or to divide a site by types of hardware.

Which file contains the environment in the puppet client?

Any environment can contain an environment. conf file. This file can override several settings whenever the Puppet master is serving nodes assigned to that environment.

What is ETC environment used for?

/etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.


2 Answers

If you only need the variables available in the puppet run, whats wrong with :

Exec { environment => [ "foo=$bar" ] } 

?

like image 144
John Avatar answered Oct 17 '22 20:10

John


Simplest way to acomplish this is to put your env vars in /etc/environment, this ensures they are available to everything (or pretty much everything).

Something like this:

class example($somevar) {     file { "/etc/environment":         content => inline_template("SOMEVAR=${somevar}")     } } 

Reason for having the class parameterised is so you can target it from hiera with automatic variable lookup (http://docs.puppetlabs.com/hiera/1/puppet.html#automatic-parameter-lookup) ... if you're sticking something in /etc/environment, it's usually best if you actually make it environment specific.

note: I've only tested this on ubuntu

like image 30
Andrei Serdeliuc ॐ Avatar answered Oct 17 '22 19:10

Andrei Serdeliuc ॐ