From a9712bb0fb5acf0e501037eca944a5eaeadf96cf Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 9 Jul 2015 08:23:43 -0400 Subject: [PATCH] Fixing some delegate_to bugs * Moving connection creation until after the task is post_validated, to make sure all fields are properly templated (#11230) * Fixing problems related to the connection method and remote address lookup on the delegated-to host Fixes #11230 --- lib/ansible/executor/task_executor.py | 14 +++++++------- lib/ansible/inventory/host.py | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index ae840a4de69..287c7431b42 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -217,12 +217,6 @@ class TaskExecutor: # variables to the variable dictionary self._connection_info.update_vars(variables) - # get the connection and the handler for this execution - self._connection = self._get_connection(variables) - self._connection.set_host_overrides(host=self._host) - - self._handler = self._get_action_handler(connection=self._connection, templar=templar) - # Evaluate the conditional (if any) for this task, which we do before running # the final task post-validation. We do this before the post validation due to # the fact that the conditional may specify that the task be skipped due to a @@ -251,6 +245,12 @@ class TaskExecutor: del include_variables['_raw_params'] return dict(changed=True, include=include_file, include_variables=include_variables) + # get the connection and the handler for this execution + self._connection = self._get_connection(variables) + self._connection.set_host_overrides(host=self._host) + + self._handler = self._get_action_handler(connection=self._connection, templar=templar) + # And filter out any fields which were set to default(omit), and got the omit token value omit_token = variables.get('omit') if omit_token is not None: @@ -460,7 +460,7 @@ class TaskExecutor: self._connection_info.port = this_info.get('ansible_ssh_port', self._connection_info.port) self._connection_info.password = this_info.get('ansible_ssh_pass', self._connection_info.password) self._connection_info.private_key_file = this_info.get('ansible_ssh_private_key_file', self._connection_info.private_key_file) - self._connection_info.connection = this_info.get('ansible_connection', self._connection_info.connection) + self._connection_info.connection = this_info.get('ansible_connection', C.DEFAULT_TRANSPORT) self._connection_info.become_pass = this_info.get('ansible_sudo_pass', self._connection_info.become_pass) if self._connection_info.remote_addr in ('127.0.0.1', 'localhost'): diff --git a/lib/ansible/inventory/host.py b/lib/ansible/inventory/host.py index ffdbc6f9c3a..c14a6f4a25e 100644 --- a/lib/ansible/inventory/host.py +++ b/lib/ansible/inventory/host.py @@ -123,6 +123,7 @@ class Host: results = combine_vars(results, self.vars) results['inventory_hostname'] = self.name results['inventory_hostname_short'] = self.name.split('.')[0] + results['ansible_ssh_host'] = self.ipv4_address results['group_names'] = sorted([ g.name for g in groups if g.name != 'all']) return results