From 65747285a4d9db63ccd8ed9ad120690860e878b9 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 24 Nov 2015 09:09:54 -0500 Subject: [PATCH] Properly check for prompting state when re-using ssh connection Fixes #13278 --- lib/ansible/executor/task_executor.py | 2 +- lib/ansible/plugins/connection/__init__.py | 5 +++++ lib/ansible/plugins/connection/ssh.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index e6e4cc31488..4a7d7464ef8 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -362,7 +362,7 @@ class TaskExecutor: self._task.args = variable_params # 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.set_host_overrides(host=self._host) diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index 1ff5d8f30b0..06616bac4ca 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -75,6 +75,7 @@ class ConnectionBase(with_metaclass(ABCMeta, object)): self.success_key = None self.prompt = None + self._connected = False # load the shell plugin for this action/connection if play_context.shell: @@ -88,6 +89,10 @@ class ConnectionBase(with_metaclass(ABCMeta, object)): if not self._shell: 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): ''' Checks if the current class supports this privilege escalation method ''' diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 8bbc0312715..aa8eb77d561 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -372,7 +372,7 @@ class Connection(ConnectionBase): # wait for a password prompt. state = states.index('awaiting_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 # detect success/failure before sending any initial data. state = states.index('awaiting_escalation')