Properly check for prompting state when re-using ssh connection

Fixes #13278
This commit is contained in:
James Cammarata 2015-11-24 09:09:54 -05:00
parent 96fcfe45d0
commit 65747285a4
3 changed files with 7 additions and 2 deletions

View file

@ -362,7 +362,7 @@ class TaskExecutor:
self._task.args = variable_params self._task.args = variable_params
# get the connection and the handler for this execution # get the connection and the handler for this execution
if not self._connection or not getattr(self._connection, '_connected', False): if not self._connection or not getattr(self._connection, 'connected', False):
self._connection = self._get_connection(variables=variables, templar=templar) self._connection = self._get_connection(variables=variables, templar=templar)
self._connection.set_host_overrides(host=self._host) self._connection.set_host_overrides(host=self._host)

View file

@ -75,6 +75,7 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
self.success_key = None self.success_key = None
self.prompt = None self.prompt = None
self._connected = False
# load the shell plugin for this action/connection # load the shell plugin for this action/connection
if play_context.shell: if play_context.shell:
@ -88,6 +89,10 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
if not self._shell: if not self._shell:
raise AnsibleError("Invalid shell type specified (%s), or the plugin for that shell type is missing." % shell_type) raise AnsibleError("Invalid shell type specified (%s), or the plugin for that shell type is missing." % shell_type)
@property
def connected(self):
return self._connected
def _become_method_supported(self): def _become_method_supported(self):
''' Checks if the current class supports this privilege escalation method ''' ''' Checks if the current class supports this privilege escalation method '''

View file

@ -372,7 +372,7 @@ class Connection(ConnectionBase):
# wait for a password prompt. # wait for a password prompt.
state = states.index('awaiting_prompt') state = states.index('awaiting_prompt')
display.debug('Initial state: %s: %s' % (states[state], self._play_context.prompt)) display.debug('Initial state: %s: %s' % (states[state], self._play_context.prompt))
elif self._play_context.become and self._play_context.success_key: elif self._play_context.become and self._play_context.success_key and not self._connected:
# We're requesting escalation without a password, so we have to # We're requesting escalation without a password, so we have to
# detect success/failure before sending any initial data. # detect success/failure before sending any initial data.
state = states.index('awaiting_escalation') state = states.index('awaiting_escalation')