diff --git a/changelogs/fragments/winrm-ansible-conn-error.yaml b/changelogs/fragments/winrm-ansible-conn-error.yaml new file mode 100644 index 00000000000..d5df68c75ec --- /dev/null +++ b/changelogs/fragments/winrm-ansible-conn-error.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Raise AnsibleConnectionError on winrm connnection errors diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index 2d43c5f916a..55fb2dbfee7 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -134,6 +134,7 @@ try: import winrm from winrm import Response from winrm.protocol import Protocol + import requests.exceptions HAS_WINRM = True except ImportError as e: HAS_WINRM = False @@ -479,6 +480,8 @@ class Connection(ConnectionBase): raise AnsibleError('winrm send_input failed; \nstdout: %s\nstderr %s' % (to_native(response.std_out), to_native(stderr))) return response + except requests.exceptions.ConnectionError as exc: + raise AnsibleConnectionFailure('winrm connection error: %s' % to_native(exc)) finally: if command_id: self.protocol.cleanup_command(self.shell_id, command_id)