From cfb1f72d1c5ba0aae878d2d9e2c0ae27164660e6 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 24 Feb 2017 08:42:23 +0100 Subject: [PATCH] Improve winrm import error message (#20267) The requests python module is needed, however it is not a dependency of the python-winrm package. The python-winrm package does require python-requests_ntlm, which does not seem to pull python-requests. So for the time being (until Red Hat fixes their package) give a more informative error message. --- lib/ansible/plugins/connection/winrm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index 1ef503b4a0b..c5b610b3c2a 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -41,6 +41,7 @@ from ansible.compat.six.moves.urllib.parse import urlunsplit from ansible.errors import AnsibleError, AnsibleConnectionFailure from ansible.errors import AnsibleFileNotFound from ansible.module_utils._text import to_bytes, to_native, to_text +from ansible.module_utils.pycompat24 import get_exception from ansible.plugins.connection import ConnectionBase from ansible.plugins.shell.powershell import exec_wrapper, become_wrapper, leaf_exec from ansible.utils.hashing import secure_hash @@ -51,12 +52,14 @@ try: from winrm import Response from winrm.protocol import Protocol except ImportError: - raise AnsibleError("winrm is not installed") + e = get_exception() + raise AnsibleError("winrm or requests is not installed: %s" % str(e)) try: import xmltodict except ImportError: - raise AnsibleError("xmltodict is not installed") + e = get_exception() + raise AnsibleError("xmltodict is not installed: %s" % str(e)) try: from __main__ import display