Hi all,
It seems I can not get the remote user's environment loaded when using
sudo in a playbook (or at the command line).
Here is an example : I need to retrieve the installed ruby version with
rbenv. Ruby is installed for user 'rbuser', and rbenv requires .bashrc
to be loaded so it can be found.
Trying at the command line (or in a playbook with "sudo: True" and
"sudo_user: rbuser") doesn't work :
ws$ ansible all -m shell -a 'rbenv version' -l goat -U rbuser
<goat> EXEC /bin/sh -c 'sudo -k && sudo -p "[sudo snip] password: " -u
rbuser /bin/sh -c '"'"'/usr/bin/python
/tmp/ansible-1358499444.98-121478482753266/command; rm -rf
/tmp/ansible-1358499444.98-121478482753266/ >/dev/null 2>&1'"'"''
goat | FAILED | rc=127 >>
/bin/sh: 1: rbenv: not found
Trying the geenrated python directly from the node unsurprisingly gives
the same result :
ws$ ssh root@goat
root@goat:~ sudo -u rbuser /bin/sh -c '/usr/bin/python
/tmp/ansible-1358499444.98-121478482753266/command'
{"changed": true, "end": "2013-01-18 09:57:54.312280", "stdout": "",
"cmd": "rbenv version ", "start": "2013-01-18 09:57:54.302952", "delta":
"0:00:00.009328", "stderr": "/bin/sh: 1: rbenv: not found", "rc": 127}
However, when trying with an additional (-i) flag (asking sudo to load
the user's environment), it works fine :
root@goat:~ sudo -iu rbuser /bin/sh -c '/usr/bin/python
/tmp/ansible-1358499444.98-121478482753266/command'
{"changed": true, "end": "2013-01-18 09:58:06.176637", "stdout": "system
(set by /home/rbuser/.rbenv/version)", "cmd": "rbenv version ", "start":
"2013-01-18 09:58:06.061737", "delta": "0:00:00.114900", "stderr": "",
"rc": 0}
Am I missing something here ? Should we invoke sudo with -i flag in
make_sudo_command ?
Thanks,
M