Recent addition of "-i" argument to sudo is reverted

It seems this is hanging for various folks, and it's somewhat unclear
why, so I reverted the commit.

Since we recently added a "default_sudo_exe" parameter for those using
alternative environments, it may be reasonable to also have a
"default_sudo_flags" for those that want to try to add things.

--Michael

I’m not sure if we want to pursue this, since the ‘default_sudo_flags’ looks more flexible and would help anyone using sudo alternatives, but here is what I’ve found on the “-i” issue.

I believe “-i” is causing the extra quoting to be stripped by running the command through an additional shell, so /usr/bin/python gets executed without arguments, which puts you in the interpreter, which causes it to hang. The /path/to/module ends up as a positional argument of /bin/sh (or the specified shell.)
Details below.

I setup sudoers with logging this morning, and sudoreplay claims the command being run is this, (doesn’t appear to capture quoting)
COMMAND=/bin/bash -c /bin/sh -c /usr/bin/python /home/fdavis/.ansible/tmp/ansible-1358657347.9-144116437520503/setup

That command from Ansible is,
EXEC /bin/sh -c ‘sudo -k && sudo -S -p “[sudo via ansible, key=bpjzgikavtmldcsajwozygjxrftjzswr] password: " -i -u root /bin/sh -c '”’“‘/usr/bin/python /home/fdavis/.ansible/tmp/ansible-1358657347.9-144116437520503/setup’”‘"’’

Per ‘man /bin/sh’ the “-i” flag runs the shell specified in passwd for the sudo user, in my case it adds “/bin/bash”.
It appears that the extra shell is absorbing the quotes around /path/to/python /path/to/module, and the /path/to/module becomes a $0 in the shell.

This is my understanding of where that module path is ending up:
[fdavis@centos6 ~]$ /bin/sh -c ‘echo $0’ /home/fdavis/.ansible/tmp/ansible-1358657347.9-144116437520503/setup
/home/fdavis/.ansible/tmp/ansible-1358657347.9-144116437520503/setup

I was able to run the following in my terminal with more quote magic, but I don’t know that it helps with anything but adding to the head scratching.
/bin/sh -c ‘/bin/bash -c ‘'’/bin/sh -c ‘"’'’“‘/usr/bin/python /home/fdavis/.ansible/tmp/ansible-1358657347.9-144116437520503/setup’”‘'’"‘’'‘’

I'm not sure if we want to pursue this, since the 'default_sudo_flags' looks
more flexible and would help anyone using sudo alternatives, but here is
what I've found on the "-i" issue.

I believe "-i" is causing the extra quoting to be stripped by running the
command through an additional shell, so /usr/bin/python gets executed
without arguments, which puts you in the interpreter, which causes it to
hang. The /path/to/module ends up as a positional argument of /bin/sh (or
the specified shell.)
Details below.

Nice legwork. And yeah, I agree with the flags suggestion. If we
go further we can put a interpolation point for the command itself in
there (like %{cmd}s) and people can play with extra quoting if they
want.

Shell quoting is the #3 hardest problem in computer science! :slight_smile:

The first two being cache invalidation and naming things:
http://www.martinfowler.com/bliki/TwoHardThings.html

Lorin