From dd1c14a0c7059e26eb736ac5ed619605069763ce Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 14 Apr 2015 21:10:17 -0500 Subject: [PATCH] Adding a method for setting up magic variables from connection info in v2 --- v2/ansible/executor/connection_info.py | 8 ++++++++ v2/ansible/executor/task_executor.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/v2/ansible/executor/connection_info.py b/v2/ansible/executor/connection_info.py index ace2252e3ad..5e14392e11b 100644 --- a/v2/ansible/executor/connection_info.py +++ b/v2/ansible/executor/connection_info.py @@ -261,3 +261,11 @@ class ConnectionInformation: for field in self._get_fields(): value = templar.template(getattr(self, field)) setattr(self, field, value) + + def update_vars(self, variables): + ''' + Adds 'magic' variables relating to connections to the variable dictionary provided. + ''' + + variables['ansible_ssh_port'] = self.port + variables['ansible_ssh_user'] = self.remote_user diff --git a/v2/ansible/executor/task_executor.py b/v2/ansible/executor/task_executor.py index 256d26f8dcf..a75cbed176e 100644 --- a/v2/ansible/executor/task_executor.py +++ b/v2/ansible/executor/task_executor.py @@ -193,9 +193,13 @@ class TaskExecutor: variables = self._job_vars # fields set from the play/task may be based on variables, so we have to - # do the same kind of post validation step on it here before we use it + # do the same kind of post validation step on it here before we use it. self._connection_info.post_validate(variables=variables, loader=self._loader) + # now that the connection information is finalized, we can add 'magic' + # 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._handler = self._get_action_handler(connection=self._connection)