Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinRM Connection Fixes #10664

Merged
merged 3 commits into from
Apr 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 7 additions & 14 deletions lib/ansible/runner/connection_plugins/winrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from __future__ import absolute_import

import base64
import hashlib
import imp
import os
import re
import shlex
Expand All @@ -44,10 +42,6 @@
except ImportError:
pass

_winrm_cache = {
# 'user:pwhash@host:port': <protocol instance>
}

def vvvvv(msg, host=None):
verbose(msg, host=host, caplevel=4)

Expand Down Expand Up @@ -84,22 +78,22 @@ def _winrm_connect(self):
vvv("ESTABLISH WINRM CONNECTION FOR USER: %s on PORT %s TO %s" % \
(self.user, port, self.host), host=self.host)
netloc = '%s:%d' % (self.host, port)
cache_key = '%s:%s@%s:%d' % (self.user, hashlib.md5(self.password).hexdigest(), self.host, port)
if cache_key in _winrm_cache:
vvvv('WINRM REUSE EXISTING CONNECTION: %s' % cache_key, host=self.host)
return _winrm_cache[cache_key]
exc = None
for transport, scheme in self.transport_schemes['http' if port == 5985 else 'https']:
if transport == 'kerberos' and not HAVE_KERBEROS:
if transport == 'kerberos' and (not HAVE_KERBEROS or not '@' in self.user):
continue
if transport == 'kerberos':
realm = self.user.split('@', 1)[1].strip() or None
else:
realm = None
endpoint = urlparse.urlunsplit((scheme, netloc, '/wsman', '', ''))
vvvv('WINRM CONNECT: transport=%s endpoint=%s' % (transport, endpoint),
host=self.host)
protocol = Protocol(endpoint, transport=transport,
username=self.user, password=self.password)
username=self.user, password=self.password,
realm=realm)
try:
protocol.send_message('')
_winrm_cache[cache_key] = protocol
return protocol
except WinRMTransportError, exc:
err_msg = str(exc)
Expand All @@ -111,7 +105,6 @@ def _winrm_connect(self):
if code == 401:
raise errors.AnsibleError("the username/password specified for this server was incorrect")
elif code == 411:
_winrm_cache[cache_key] = protocol
return protocol
vvvv('WINRM CONNECTION ERROR: %s' % err_msg, host=self.host)
continue
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/runner/shell_plugins/powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _build_file_cmd(cmd_parts, quote_args=True):
'''Build command line to run a file, given list of file name plus args.'''
if quote_args:
cmd_parts = ['"%s"' % x for x in cmd_parts]
return ' '.join(['&'] + cmd_parts)
return ' '.join(_common_args + ['-ExecutionPolicy', 'Unrestricted', '-File'] + cmd_parts)

class ShellModule(object):

Expand Down