Skip to content

Instantly share code, notes, and snippets.

@amenonsen
Created November 25, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amenonsen/8da2b110aacc70a1b014 to your computer and use it in GitHub Desktop.
Save amenonsen/8da2b110aacc70a1b014 to your computer and use it in GitHub Desktop.
diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py
index d3a8877..debe36b 100644
--- a/lib/ansible/plugins/connection/ssh.py
+++ b/lib/ansible/plugins/connection/ssh.py
@@ -457,12 +457,17 @@ class Connection(ConnectionBase):
tmp_stdout = tmp_stderr = ''
# If we see a privilege escalation prompt, we send the password.
+ # (If we're expecting a prompt but the escalation succeeds, we
+ # didn't need the password and can carry on regardless.)
- if states[state] == 'awaiting_prompt' and self._flags['become_prompt']:
- display.debug('Sending become_pass in response to prompt')
- stdin.write(self._play_context.become_pass + '\n')
- self._flags['become_prompt'] = False
- state += 1
+ if states[state] == 'awaiting_prompt':
+ if self._flags['become_prompt']:
+ display.debug('Sending become_pass in response to prompt')
+ stdin.write(self._play_context.become_pass + '\n')
+ self._flags['become_prompt'] = False
+ state += 1
+ elif self._flags['become_success']:
+ state += 1
# We've requested escalation (with or without a password), now we
# wait for an error message or a successful escalation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment