Setting Environment Variables with Puppet

Set Environment Variables with Puppet

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

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

?

Setting environment variables with puppet

I would take a look at this related question.

*.sh scripts in /etc/profile.d are read at user-login time (as the post says, at the same time /etc/profile is sourced)

Variables export-ed in any script placed in /etc/profile.d will therefore be available to your users.

You can then use a file resource to ensure this action is idempotent. For example:

file { "/etc/profile.d/my_test.sh":
content => 'export MYVAR="123"'
}

Puppet: Set env variables & boot app - variables undefined

The shell that runs your exec appears not to honor /etc/environment.

There is two ways to go about this.

Use the envrironment explicitly

Write a wrapper script that does a

. /etc/environment

before invoking the npm proper.

Set the needed variables via manifest

Pass the environment parameter to the exec like so:

exec { 'Daemonize API':
environment => [ 'NODE_ENV=development, ],
...
}

This answer might be related.

How to set an environment variable on a server with puppet?

Solved it:

# init.pp
$jruby_sh = "/etc/profile.d/jruby.sh"
file { $jruby_sh:
ensure => present,
source => "puppet:///modules/jruby/jruby.sh",
owner => "root",
group => "root",
mode => 644,
require => File[$jruby_home]
}

# jruby.sh
export JRUBY_HOME=/opt/jruby
export PATH=$PATH:$JRUBY_HOME/bin

How to set environment variables in Ubuntu OS using Puppet

You have only defined bashrc class. To execute code of the class you must instance it. The recommended way to do that is to add:

include bashrc

to some manifest. More about class instantiation here.

To modify content of bashrc file you use augeas resource. Here you have guide how to use it.

setting environment in puppet

You have asked two rather different questions: how to set a node's environment and how to use the nodes' environments to customize the data that will be drawn from Hiera on their behalf. You have missed a very important preliminary question: should I be defining and using environments at all?

Since you are new to Puppet, I suggest you start off by ignoring environments as much as you can do. It is by no means essential to use multiple environments in your site configuration, and although it is not unusual to establish separate environments along the lines you describe, the value or propriety of doing so is much less clear than you may suppose. You have quite enough to learn without delving into environments; I suggest that at least for now, you just leave everything in the default environment, "production". Focus on more pressing topics, instead.

If you insist on going straight into environments, then the first of the questions you posed is easier to answer: a node's environment may be set on the node's side by inserting the desired value for the environment key in that node's configuration file, or on the master side (supposing you are using a master) by setting up an external node classifier (ENC) and having it provide a value for the global variable $environment. If you do both then the master wins.

As for customizing Hiera data by environment, you would typically set up an environment-specific level of your Hiera data hierarchy, via your central hiera.yaml configuration file. You would interpolate the environment name into this file ("%{environment}") to form the part or all of the base name for the data file at one level. For each environment in which you want customized data, you would provide the corresponding Hiera data file in the appropriate data directory for one or more of the Hiera back ends you have configured.

How do I set Windows environment paths in current Puppet session?

I found a workaround that allows the puppet script to run fully.

Running set "PATH=%PATH%;C:\Program Files\Git\cmd" in the command line before puppet apply file.pp sets git's future location as an environment variable just for the current command prompt (set, not setx). This way, when another command prompt is opened, the one-time path is gone, but the same path is added from the actual installation of git.



Related Topics



Leave a reply



Submit