Jordi
Jordi

Reputation: 23277

Chef: Setting environment variables

I need to set OS environment variables on my Centos/7 machine.

I've tried it using on my variables.rb file:

host = 'locahost'
port = 9201

ENV['LV_ES_HOST'] = host
ENV['LV_ES_PORT'] = '#{port}'

Nevertheless, on shell:

$ echo $LV_ES_HOST

$
  1. How could I set an Os environment variable?
  2. Could it be possible to set a OS enviroment variable only visible for an user?

I need a OS available environment variable in order for my jee applications to be able to read its value.

I'm running several jee containers on my machine, and the applications are running on need to get the LC_ES_HOST environment variable.

Upvotes: 2

Views: 2227

Answers (1)

coderanger
coderanger

Reputation: 54249

The other question doesn't really explain the underlying problem. Unix environment variables are inherited from parent process to child process during a fork(). So when you set things via ENV in your Chef code, it does affect subprocesses that come under Chef like things run via an execute resource. When you log in via SSH, however, your shell is not a subprocess of chef-client so those variables aren't visible. Unfortunately Unix has no general purpose solution for global environment variables so you need to pick one of a number of compromises, which are listed in the other question.

Upvotes: 2

Related Questions