The -U SUDO_USER is not really working for me because Ansible can’t find sudo. The root cause appears that it isn’t set in the target hosts bash shell $PATH variable because Ansible doesn’t seem to load in the .bash_profile or .profile
I don’t have root on the target machines to setup a sudo symbolic link in /bin/sh. Is there some way to setup Ansible to look in other places for executables besides the default PATH=/usr/bin:/bin ? The sys admins setup sudo in /usr/local/bin/ instead because that’s the standard they are using.
I tried setting sudo_exe=/usr/local/bin/sudo in ansible.cfg and it didn’t like that. Ansible just hung when I did that.
Here’s my shell output to give the idea of what’s happening on my system.
$ ansible --verbose -i /app/scripts/webadm/ansible/hosts proxy -a “env”
xqa1prxy2 | success | rc=0 >>
LANG=C
SHELL=/bin/bash
SSH_CLIENT=192.168.0.13 49783 22
USER=webadm
PATH=/usr/bin:/bin
MAIL=/var/mail//webadm
_=/usr/bin/python
PWD=/export/home/webadm
TZ=US/Pacific
HOME=/export/home/webadm
SHLVL=2
LOGNAME=webadm
SSH_CONNECTION=192.168.0.13 49783 192.168.0.5 22
xqa1prxy1 | success | rc=0 >>
LANG=C
SHELL=/bin/bash
SSH_CLIENT=192.168.0.13 43491 22
USER=webadm
PATH=/usr/bin:/bin
MAIL=/var/mail//webadm
_=/usr/bin/python
PWD=/export/home/webadm
TZ=US/Pacific
HOME=/export/home/webadm
SHLVL=2
LOGNAME=webadm
SSH_CONNECTION=192.168.0.13 43491 192.168.0.4 22
$ ansible --verbose -i /app/scripts/webadm/ansible/hosts proxy -a “ls -l” -U ldapadm
xqa1prxy2 | FAILED >> {
“failed”: true,
“msg”: “/bin/sh: sudo: not found\r\n”,
“parsed”: false
}
xqa1prxy1 | FAILED >> {
“failed”: true,
“msg”: “/bin/sh: sudo: not found\r\n”,
“parsed”: false
}
$ ansible --verbose -i /app/scripts/webadm/ansible/hosts proxy -a “echo $PATH”
xqa1prxy1 | success | rc=0 >>
/export/home/webadm/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/app/local/bin
xqa1prxy2 | success | rc=0 >>
/export/home/webadm/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/app/local/bin
$ ansible --verbose -i /app/scripts/webadm/ansible/hosts proxy -a “/usr/local/bin/sudo -h”
xqa1prxy1 | success | rc=0 >>
sudo - execute a command as another user
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
name>#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] []
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
user name|#uid] file …
Options:
-a type use specified BSD authentication type
-b run command in the background
-C fd close all file descriptors >= fd
-E preserve user environment when executing command
-e edit files instead of running a command
-g group execute command as the specified group
-H set HOME variable to target user’s home dir.
-h display help message and exit
-i [command] run a login shell as target user
-K remove timestamp file completely
-k invalidate timestamp file
-l[l] command list user’s available commands
-n non-interactive mode, will not prompt user
-P preserve group vector instead of setting to target’s
-p prompt use specified password prompt
-S read password from standard input
-s [command] run a shell as target user
-U user when listing, list specified user’s privileges
-u user run command (or edit file) as specified user
-V display version information and exit
-v update user’s timestamp without running a command
– stop processing command line arguments
xqa1prxy2 | success | rc=0 >>
sudo - execute a command as another user
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
name>#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] []
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
user name|#uid] file …
Options:
-a type use specified BSD authentication type
-b run command in the background
-C fd close all file descriptors >= fd
-E preserve user environment when executing command
-e edit files instead of running a command
-g group execute command as the specified group
-H set HOME variable to target user’s home dir.
-h display help message and exit
-i [command] run a login shell as target user
-K remove timestamp file completely
-k invalidate timestamp file
-l[l] command list user’s available commands
-n non-interactive mode, will not prompt user
-P preserve group vector instead of setting to target’s
-p prompt use specified password prompt
-S read password from standard input
-s [command] run a shell as target user
-U user when listing, list specified user’s privileges
-u user run command (or edit file) as specified user
-V display version information and exit
-v update user’s timestamp without running a command
– stop processing command line arguments