Catch auth errors in winrm and properly raise errors

Fixes #7875
This commit is contained in:
James Cammarata 2014-08-06 12:10:07 -05:00
parent 6c3999b898
commit 4a157a72a0

View file

@ -89,17 +89,19 @@ class Connection(object):
except WinRMTransportError, exc: except WinRMTransportError, exc:
err_msg = str(exc.args[0]) err_msg = str(exc.args[0])
if re.search(r'Operation\s+?timed\s+?out', err_msg, re.I): if re.search(r'Operation\s+?timed\s+?out', err_msg, re.I):
raise raise errors.AnsibleError("the connection attempt timed out")
m = re.search(r'Code\s+?(\d{3})', err_msg) m = re.search(r'Code\s+?(\d{3})', err_msg)
if m: if m:
code = int(m.groups()[0]) code = int(m.groups()[0])
if code == 411: if code == 401:
raise errors.AnsibleError("the username/password specified for this server was incorrect")
elif code == 411:
_winrm_cache[cache_key] = protocol _winrm_cache[cache_key] = protocol
return protocol return protocol
vvvv('WINRM CONNECTION ERROR: %s' % err_msg, host=self.host) vvvv('WINRM CONNECTION ERROR: %s' % err_msg, host=self.host)
continue continue
if exc: if exc:
raise exc raise errors.AnsibleError(str(exc))
def _winrm_exec(self, command, args=(), from_exec=False): def _winrm_exec(self, command, args=(), from_exec=False):
if from_exec: if from_exec: