Merge pull request #24874 from dkiser/salt-cloud-24870

Fix for salt-cloud when ssh key used to auth and using sudo.
This commit is contained in:
Joseph Hall 2015-06-22 17:46:07 -06:00
commit c32aae96aa

View file

@ -84,6 +84,8 @@ NSTATES = {
}
SSH_PASSWORD_PROMP_RE = re.compile(r'(?:.*)[Pp]assword(?: for .*)?:', re.M)
SSH_PASSWORD_PROMP_SUDO_RE = \
re.compile(r'(?:.*sudo)(?:.*)[Pp]assword(?: for .*)?:', re.M)
# Get logging started
log = logging.getLogger(__name__)
@ -1466,12 +1468,26 @@ def _exec_ssh_cmd(cmd, error_msg=None, allow_failure=False, **kwargs):
while proc.has_unread_data:
stdout, stderr = proc.recv()
if stdout and SSH_PASSWORD_PROMP_RE.search(stdout):
if (
# if authenticating with an SSH key and 'sudo' is found
# in the password prompt
if ('key_filename' in kwargs and kwargs['key_filename']
and SSH_PASSWORD_PROMP_SUDO_RE.search(stdout)
):
# do nothing, as command already has adjustments to
# echo out the sudo password as part of the ssh command
# keep waiting for proc output
continue
# elif authenticating via password and haven't exhausted our
# password_retires
elif (
kwargs.get('password', None)
and (sent_password < password_retries)
):
sent_password += 1
proc.sendline(kwargs['password'])
# else raise an error as we are not authenticating properly
# * not authenticating with an SSH key
# * not authenticating with a Password
else:
raise SaltCloudPasswordError(error_msg)
# 0.0125 is really too fast on some systems