with settings(user=some_user), cd('/home/some_user'):
append('.ssh/authorized_keys', key, partial=True, use_sudo=use_sudo)
This code silently duplicates existing key in a checked file. The full resulting command is:
sudo -S -p 'sudo password:' cd /home/some_user && egrep "^ssh\-rsa\ AAAAB3Nza[...]jN\+v7w\=\=" ".ssh/authorized_keys"
(as returned by _shell_wrap() call) The problem is: normally, there is no standalone 'cd' command in UNIX, as it is a shell built-in. And ommiting context manager #with settings(hide('everything'), warn_only=True): at the end of contains() reveals that.
#with settings(hide('everything'), warn_only=True):
Quick test to use shell=True in the final call inside contains() fixes that, but possibly has other side-effects.
Yes, adding shell=False to contains and sed were done to remove one level of quoting which was causing issues in various situations, but I can see how that would sink the way cd behaves.
I don't see a good way to have our cake and eat it too, but am open to suggestions. Best I can think of is to add this as a warning in the docstrings in contrib, and an option to these affected methods to allow overriding the shell=False.
It seems running commands this way cd /home/foo && sudo -S -p 'sudo password:' egrep [...] is not what we want.
So here is the quick "workaround" you've suggested. I am not sure where the general warning should go and if the 1.4.4 is the right version to mention in versionchanged. Can you look at this branch and tell if it is OK to send this as a pull request?
cd /home/foo && sudo -S -p 'sudo password:' egrep [...]
That branch looks good, besides two nitpicks:
Re: the PR, I'd recommend using hub pull-request to add the PR to this ticket so we avoid having two tickets.
Allow to override 'shell' argument passed to run/sudo in some contrib…
Do you have any objections on this (the 1.5.x is already out now)?
Tweak language of main docstring, update versionadded, re #703
Attribution re #703
All set now; updated versionadded bits to 1.6 since 1.5 came out a little while ago. Thanks again, & apologies for the delay!