From d723b8541d949809e8b0b5bed3a8873b5f255ac0 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 12 Jul 2018 13:22:01 +1000 Subject: [PATCH] changed winrm _reset to reset and make ssh reset show warning (#42651) * changed winrm _reset to reset and make ssh reset show warning * minor changelog update --- changelogs/fragments/connection_reset.yaml | 3 +++ lib/ansible/executor/task_executor.py | 2 +- lib/ansible/plugins/action/wait_for_connection.py | 2 +- lib/ansible/plugins/action/win_reboot.py | 6 +++--- lib/ansible/plugins/connection/ssh.py | 2 +- lib/ansible/plugins/connection/winrm.py | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/connection_reset.yaml diff --git a/changelogs/fragments/connection_reset.yaml b/changelogs/fragments/connection_reset.yaml new file mode 100644 index 0000000000..b5b9ca2d36 --- /dev/null +++ b/changelogs/fragments/connection_reset.yaml @@ -0,0 +1,3 @@ +minor_changes: +- ssh - reset connection will show a warning instead of failing for older OpenSSH versions +- winrm - change the _reset() method to use reset() that is part of ConnectionBase diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 3b56989ac5..f09bc63dd0 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -767,7 +767,7 @@ class TaskExecutor: display.vvvv("Exception during async poll, retrying... (%s)" % to_text(e)) display.debug("Async poll exception was:\n%s" % to_text(traceback.format_exc())) try: - normal_handler._connection._reset() + normal_handler._connection.reset() except AttributeError: pass diff --git a/lib/ansible/plugins/action/wait_for_connection.py b/lib/ansible/plugins/action/wait_for_connection.py index 45473684b0..3badee968e 100644 --- a/lib/ansible/plugins/action/wait_for_connection.py +++ b/lib/ansible/plugins/action/wait_for_connection.py @@ -82,7 +82,7 @@ class ActionModule(ActionBase): display.vvv("wait_for_connection: attempting ping module test") # call connection reset between runs if it's there try: - self._connection._reset() + self._connection.reset() except AttributeError: pass diff --git a/lib/ansible/plugins/action/win_reboot.py b/lib/ansible/plugins/action/win_reboot.py index 8b7893b635..e2e9c88931 100644 --- a/lib/ansible/plugins/action/win_reboot.py +++ b/lib/ansible/plugins/action/win_reboot.py @@ -158,7 +158,7 @@ class ActionModule(ActionBase): try: self._connection.set_option("connection_timeout", connect_timeout) - self._connection._reset() + self._connection.reset() except AttributeError: display.warning("Connection plugin does not allow the " "connection timeout to be overridden") @@ -178,7 +178,7 @@ class ActionModule(ActionBase): try: self._connection.set_option("connection_timeout", connection_timeout_orig) - self._connection._reset() + self._connection.reset() except (AnsibleError, AttributeError) as e: display.debug("Failed to reset connection_timeout back to default: %s" % to_native(e)) @@ -192,7 +192,7 @@ class ActionModule(ActionBase): # (another reboot occurred) we need to reset the connection # to make sure we are not re-using the same shell id try: - self._connection._reset() + self._connection.reset() except AttributeError: pass raise diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 5acc0f236a..9e0fd34270 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -1108,7 +1108,7 @@ class Connection(ConnectionBase): stdout, stderr = p.communicate() status_code = p.wait() if status_code != 0: - raise AnsibleError("Cannot reset connection:\n%s" % stderr) + display.warning("Failed to reset connection:%s" % stderr) self.close() diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index 3daa06e0c4..1498437214 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -483,7 +483,7 @@ class Connection(ConnectionBase): self._connected = True return self - def _reset(self): # used by win_reboot (and any other action that might need to bounce the state) + def reset(self): self.protocol = None self.shell_id = None self._connect()