diff --git a/CHANGELOG.md b/CHANGELOG.md index 1085b58f2ee..8cca81d89b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Ansible Changes By Release * If the user is not using paramiko or vault, allow Ansible to run if pycrypto is not installed. * Fixed a bug in pkg_util module that caused "update_catalog must be one of" error if 'update_catalog' arg was used. +* Fixed a bug where psuedo-connection vars (eg, ansible_winrm_transport) defined in group_vars or host_vars were not getting passed to the connection. ## 2.1 "The Song Remains the Same" - ACTIVE DEVELOPMENT diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index f35ba897f18..db8ab9b7fa1 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 e1b9e959d0e..064637715a0 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 f5023d7efc6..3e022a478fc 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): '''