2

I am facing issue while want to change the default environment variables using chef recipe. My requirement is to change the present working shell (from bash to csh) and change the TERM variable from xterm to vt100. I have tried some combination but its not working.

execute 'change present working shell' do
  command '/bin/csh'
end

execute 'change term env' do
  command 'setenv TERM vt100'
end

Also tried using script to run from chef but its also not working.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
NiteshM
  • 17
  • 2

2 Answers2

0

Assuming you are running a Linux system, you can define environment variables globally in /etc/environment.

The most simple approach to write out that file would be the following:

file "/etc/environment" do
  content "TERM=vt100"
  mode "0644"
end

The shell of a user is specified in /etc/passwd on a per user-level. For a given (existing) user johndoe, you can use the user resource:

user "johndoe" do
  shell "/bin/csh"
  action :manage
end

In order to change the default shell for users that are created afterwards, IIRC there are distro-specific options (see this thread).

Community
  • 1
  • 1
StephenKing
  • 36,187
  • 11
  • 83
  • 112
  • While this is correct answer, it is worth noting that `/etc/environment` and its friends are _far_ from global. They generally apply only to login shells, which is fine for `$TERM` but always remember it's not actually global. They don't apply to things like services (usually) or commands run over SSH without using a shell. – coderanger May 04 '16 at 18:23
  • Thanks for that info. Any way to define a really _global_ environment variable? Didn't have the need, yet, and not sure, if things like `/etc/default/` aren't a better place.. Just for curiosity. – StephenKing May 04 '16 at 18:25
  • No, unfortunately this is one of the few places where Windows did it right and Unix did it wrong. The only ways for env vars to get set is either call `setenv()` (which is what those shell init files do, at a low level) or inherit from a parent process. There just isn't a place to set truly global env vars unless you write your own init I suppose :) – coderanger May 04 '16 at 21:54
0

Thanks..

its working after logout from current shell and login again .. but I want this be effective on current shell and don't want to logout from current working shell.

NiteshM
  • 17
  • 2