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
Solution for what I need is putting an alias sudo="sudo -i" in ~/.bashrc of root and also the user ansible.
ENVcontains a file path, it is used by some old shells as the path of a file sourced on startup (also in POSIX shells, but only when interactive). So it's one of those that sudo always blacklists to avoid users bypassing the sudo policies (even with!env_reset).ENV=hostname | awk -F- '{print $1}' | sed 's/ACE//'`` - no pathsudo echo $ENV, that is not actually an indication that$ENVis set in the sudo environment. The variable is expanded by your shell before it runssudo.