summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2017-06-21 10:13:06 +0200
committerMatt Davis <nitzmahone@users.noreply.github.com>2017-06-21 10:13:06 +0200
commitd79315e19e1ddc31beaab4ed2b52ac76141e15c6 (patch)
treeb9e9fff72f1646305650477a1bc9975990d3ef21 /lib
parentadd traceback and more helpful errors for ec2_vpc_route_table (#25704) (diff)
downloadansible-d79315e19e1ddc31beaab4ed2b52ac76141e15c6.tar.xz
ansible-d79315e19e1ddc31beaab4ed2b52ac76141e15c6.zip
avoid winrm errors when not connecting to winrm (#25921)
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/plugins/connection/winrm.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py
index 8bc2fa0a64..2a33ad876d 100644
--- a/lib/ansible/plugins/connection/winrm.py
+++ b/lib/ansible/plugins/connection/winrm.py
@@ -51,13 +51,15 @@ try:
import winrm
from winrm import Response
from winrm.protocol import Protocol
+ HAS_WINRM = True
except ImportError as e:
- raise AnsibleError("winrm or requests is not installed: %s" % str(e))
+ HAS_WINRM = False
try:
import xmltodict
+ HAS_XMLTODICT = True
except ImportError as e:
- raise AnsibleError("xmltodict is not installed: %s" % str(e))
+ HAS_XMLTODICT = False
try:
from __main__ import display
@@ -99,6 +101,9 @@ class Connection(ConnectionBase):
'''
Override WinRM-specific options from host variables.
'''
+ if not HAS_WINRM:
+ return
+
self._winrm_host = self._play_context.remote_addr
self._winrm_port = int(self._play_context.port or 5986)
self._winrm_scheme = hostvars.get('ansible_winrm_scheme', 'http' if self._winrm_port == 5985 else 'https')
@@ -134,7 +139,7 @@ class Connection(ConnectionBase):
raise AnsibleError('The installed version of WinRM does not support transport(s) %s' % list(unsupported_transports))
# if kerberos is among our transports and there's a password specified, we're managing the tickets
- kinit_mode = str(hostvars.get('ansible_winrm_kinit_mode', '')).strip()
+ kinit_mode = to_text(hostvars.get('ansible_winrm_kinit_mode', '')).strip()
if kinit_mode == "":
# HACK: ideally, remove multi-transport stuff
self._kerb_managed = "kerberos" in self._winrm_transport and self._winrm_pass
@@ -294,6 +299,12 @@ class Connection(ConnectionBase):
self.protocol.cleanup_command(self.shell_id, command_id)
def _connect(self):
+
+ if not HAS_WINRM:
+ raise AnsibleError("winrm or requests is not installed: %s" % to_text(e))
+ elif not HAS_XMLTODICT:
+ raise AnsibleError("xmltodict is not installed: %s" % to_text(e))
+
super(Connection, self)._connect()
if not self.protocol:
self.protocol = self._winrm_connect()