0

I have a variable set in a script file in /etc/profile.d/somescript.sh I have modified the /etc/sudoers and added "ansible" user to the sudoers file like this:

Defaults !env_reset
ansible    ALL=(ALL) NOPASSWD:   ALL

Why isn't the first line outputting anything ? why "sudo env" is not showing all environment variables (only partial)?

[ansible@ACEPP-LM-01 ~]$ sudo env | grep ENV
[ansible@ACEPP-LM-01 ~]$ sudo echo $ENV
PP
[ansible@ACEPP-LM-01 ~]$ echo $ENV
PP
[ansible@ACEPP-LM-01 ~]$ env | grep ENV
ENV=PP
ady8531
  • 689
  • 5
  • 13
  • 24
  • 1
    You should ask these questions in http://unix.stackexchange.com/ or http://askubuntu.com/ – Stan May 18 '15 at 15:39
  • I'd call superuser a valid location for this as well -- it's more a usage question than anything else. Indeed, though, it's certainly not a question about writing code, which is StackOverflow's domain. – Charles Duffy May 18 '15 at 15:41

1 Answers1

0

The files at /etc/profile.d are being sourced only at login shell. run the sudo with -i argument.

sudo -i env | grep ENV

You can read more here about the different bashinvocation ways

Yuri G.
  • 4,323
  • 1
  • 17
  • 32
  • How can I make sudo to run as "sudo -i" by default ? – ady8531 May 19 '15 at 08:12
  • As far as I know you can't. You can set an alias `sudo='sudo -i'` in your `.bashrc` file. But it depends on the way you are invoking the `sudo`, you should care either to source the `.bashrc` by yourself or to invoke the `sudo` within an interactive shell. Hope this helps you – Yuri G. May 19 '15 at 13:32