mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make the actual user used for executing play available as 'ansible_ssh_user' variable
This commit is contained in:
parent
957a7bf373
commit
a58baae2c4
1 changed files with 9 additions and 3 deletions
|
@ -433,7 +433,6 @@ class Runner(object):
|
|||
complex_args = utils.safe_eval(complex_args)
|
||||
if type(complex_args) != dict:
|
||||
raise errors.AnsibleError("args must be a dictionary, received %s" % complex_args)
|
||||
|
||||
result = self._executor_internal_inner(
|
||||
host,
|
||||
self.module_name,
|
||||
|
@ -478,9 +477,8 @@ class Runner(object):
|
|||
new_args = new_args + "%s='%s' " % (k,v)
|
||||
module_args = new_args
|
||||
|
||||
# module_name may be dynamic (but cannot contain {{ ansible_ssh_user }})
|
||||
module_name = template.template(self.basedir, module_name, inject)
|
||||
module_args = template.template(self.basedir, module_args, inject)
|
||||
complex_args = template.template(self.basedir, complex_args, inject)
|
||||
|
||||
if module_name in utils.plugins.action_loader:
|
||||
if self.background != 0:
|
||||
|
@ -536,9 +534,13 @@ class Runner(object):
|
|||
actual_host = delegate_to
|
||||
actual_port = port
|
||||
|
||||
# user/pass may still contain variables at this stage
|
||||
actual_user = template.template(self.basedir, actual_user, inject)
|
||||
actual_pass = template.template(self.basedir, actual_pass, inject)
|
||||
|
||||
# make actual_user available as __magic__ ansible_ssh_user variable
|
||||
inject['ansible_ssh_user'] = actual_user
|
||||
|
||||
try:
|
||||
if actual_port is not None:
|
||||
actual_port = int(actual_port)
|
||||
|
@ -561,6 +563,10 @@ class Runner(object):
|
|||
if getattr(handler, 'NEEDS_TMPPATH', True):
|
||||
tmp = self._make_tmp_path(conn)
|
||||
|
||||
# render module_args and complex_args templates
|
||||
module_args = template.template(self.basedir, module_args, inject)
|
||||
complex_args = template.template(self.basedir, complex_args, inject)
|
||||
|
||||
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
|
||||
|
||||
conn.close()
|
||||
|
|
Loading…
Reference in a new issue