diff --git a/changelogs/fragments/connection_reset.yaml b/changelogs/fragments/connection_reset.yaml new file mode 100644 index 00000000000..b5b9ca2d36b --- /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 3b56989ac5c..f09bc63dd0f 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 45473684b04..3badee968e5 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 8b7893b6350..e2e9c889315 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 5acc0f236a8..9e0fd342703 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 3daa06e0c40..14984372144 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()