diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index f35ba897f1..db8ab9b7fa 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -409,7 +409,7 @@ class TaskExecutor: # 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: 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: # 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 diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index e1b9e959d0..064637715a 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -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) - 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 from variables set on the host (or groups to which the host belongs) diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index c5efd481f2..c8ea880e73 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -78,16 +78,14 @@ class Connection(ConnectionBase): 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. ''' - host_vars = combine_vars(host.get_group_vars(), host.get_vars()) - self._winrm_host = self._play_context.remote_addr 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_path = host_vars.get('ansible_winrm_path', '/wsman') + self._winrm_scheme = hostvars.get('ansible_winrm_scheme', 'http' if self._winrm_port == 5985 else 'https') + self._winrm_path = hostvars.get('ansible_winrm_path', '/wsman') self._winrm_user = self._play_context.remote_user self._winrm_pass = self._play_context.password @@ -104,7 +102,7 @@ class Connection(ConnectionBase): self._winrm_transport = 'kerberos,%s' % transport_selector else: 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): 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) argspec = inspect.getargspec(Protocol.__init__) 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) # 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 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): '''