fix for psuedo-connection hostvars not propagating to connection

(mostly done by jimi-c, tested working)
pull/16234/head
nitzmahone 9 years ago
parent 04ce71b4bd
commit ece1ed09d5

@ -409,7 +409,7 @@ class TaskExecutor:
# get the connection and the handler for this execution # get the connection and the handler for this execution
if not self._connection or not getattr(self._connection, 'connected', False) or self._play_context.remote_addr != self._connection._play_context.remote_addr: if not self._connection or not getattr(self._connection, 'connected', False) or self._play_context.remote_addr != self._connection._play_context.remote_addr:
self._connection = self._get_connection(variables=variables, templar=templar) self._connection = self._get_connection(variables=variables, templar=templar)
self._connection.set_host_overrides(host=self._host) self._connection.set_host_overrides(host=self._host, hostvars=variables.get('hostvars', {}).get(self._host.name, {}))
else: else:
# if connection is reused, its _play_context is no longer valid and needs # if connection is reused, its _play_context is no longer valid and needs
# to be replaced with the one templated above, in case other data changed # to be replaced with the one templated above, in case other data changed

@ -112,7 +112,7 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
raise AnsibleError("Internal Error: this connection module does not support running commands via %s" % self._play_context.become_method) raise AnsibleError("Internal Error: this connection module does not support running commands via %s" % self._play_context.become_method)
def set_host_overrides(self, host): def set_host_overrides(self, host, hostvars=None):
''' '''
An optional method, which can be used to set connection plugin parameters An optional method, which can be used to set connection plugin parameters
from variables set on the host (or groups to which the host belongs) from variables set on the host (or groups to which the host belongs)

@ -78,16 +78,14 @@ class Connection(ConnectionBase):
super(Connection, self).__init__(*args, **kwargs) super(Connection, self).__init__(*args, **kwargs)
def set_host_overrides(self, host): def set_host_overrides(self, host, hostvars=None):
''' '''
Override WinRM-specific options from host variables. Override WinRM-specific options from host variables.
''' '''
host_vars = combine_vars(host.get_group_vars(), host.get_vars())
self._winrm_host = self._play_context.remote_addr self._winrm_host = self._play_context.remote_addr
self._winrm_port = int(self._play_context.port or 5986) self._winrm_port = int(self._play_context.port or 5986)
self._winrm_scheme = host_vars.get('ansible_winrm_scheme', 'http' if self._winrm_port == 5985 else 'https') self._winrm_scheme = hostvars.get('ansible_winrm_scheme', 'http' if self._winrm_port == 5985 else 'https')
self._winrm_path = host_vars.get('ansible_winrm_path', '/wsman') self._winrm_path = hostvars.get('ansible_winrm_path', '/wsman')
self._winrm_user = self._play_context.remote_user self._winrm_user = self._play_context.remote_user
self._winrm_pass = self._play_context.password self._winrm_pass = self._play_context.password
@ -104,7 +102,7 @@ class Connection(ConnectionBase):
self._winrm_transport = 'kerberos,%s' % transport_selector self._winrm_transport = 'kerberos,%s' % transport_selector
else: else:
self._winrm_transport = transport_selector self._winrm_transport = transport_selector
self._winrm_transport = host_vars.get('ansible_winrm_transport', self._winrm_transport) self._winrm_transport = hostvars.get('ansible_winrm_transport', self._winrm_transport)
if isinstance(self._winrm_transport, basestring): if isinstance(self._winrm_transport, basestring):
self._winrm_transport = [x.strip() for x in self._winrm_transport.split(',') if x.strip()] self._winrm_transport = [x.strip() for x in self._winrm_transport.split(',') if x.strip()]
@ -116,7 +114,7 @@ class Connection(ConnectionBase):
self._winrm_kwargs = dict(username=self._winrm_user, password=self._winrm_pass) self._winrm_kwargs = dict(username=self._winrm_user, password=self._winrm_pass)
argspec = inspect.getargspec(Protocol.__init__) argspec = inspect.getargspec(Protocol.__init__)
supported_winrm_args = set(argspec.args) supported_winrm_args = set(argspec.args)
passed_winrm_args = set([v.replace('ansible_winrm_', '') for v in host_vars if v.startswith('ansible_winrm_')]) passed_winrm_args = set([v.replace('ansible_winrm_', '') for v in hostvars if v.startswith('ansible_winrm_')])
unsupported_args = passed_winrm_args.difference(supported_winrm_args) unsupported_args = passed_winrm_args.difference(supported_winrm_args)
# warn for kwargs unsupported by the installed version of pywinrm # warn for kwargs unsupported by the installed version of pywinrm
@ -128,7 +126,7 @@ class Connection(ConnectionBase):
# pass through matching kwargs, excluding the list we want to treat specially # pass through matching kwargs, excluding the list we want to treat specially
for arg in passed_winrm_args.difference(internal_kwarg_mask).intersection(supported_winrm_args): for arg in passed_winrm_args.difference(internal_kwarg_mask).intersection(supported_winrm_args):
self._winrm_kwargs[arg] = host_vars['ansible_winrm_%s' % arg] self._winrm_kwargs[arg] = hostvars['ansible_winrm_%s' % arg]
def _winrm_connect(self): def _winrm_connect(self):
''' '''

Loading…
Cancel
Save