On 18/01/2013 14:06, Brian Coca wrote:
> Sudo normally removes most env vars, you should be able to configure it
> to preserve those you need.
>
> Sudo has a -E flag that prevents env filtering, test with that.
Hi Brian,
May be I misexplained my problem, but it is not about preserving
environment; it's about getting the environment of the target user.
For instance, when the playbook is ran with this :
- hosts: ubuntu
name: Install ruby for the configured ruby user
sudo: True
sudo_user: rubyuser
# should be ${ruby_user}, but can't for now because of #1665
tasks:
- name: Gets current ruby version
action: shell rbenv version
register: ruby_current_version
The 'rubyuser' environment on the remote node is not loaded when the
tasks are run. This prevents tools like rvm or rbenv from working,
because they both need to be initialized and have their path added to
$PATH, and this setup phase typically takes place in .bash_profile.
Just to check :
$ ansible all -m shell -a 'echo $HOME' -l somehost -U someuser
somehost | success | rc=0 >>
/root
What I'd rather get : /home/someuser
So the need here is to be sure that when root SUDOs as someuser, the
latter gets it's environment properly (AFAIK, -E does the exact oppostite).
And the problem is not doing it by hand, but being able to get the
user-we-sudo-as environment loaded.
May be I'm missing the point, and loading the target user is a problem,
but I don't really see why. As a side effect, it would have solved #1864.