Open macksyma opened 4 months ago
Thank you, this may be closely related to #1022 or a case of it.
Hi,
I have the same issue.
mitogen_get_stack
print without the changes mentioned by @macksyma
discovered_interpreter: false
result:
- kwargs:
check_host_keys: ignore
compression: true
connect_timeout: 10
hostname: '{{ my_ip_address }}'
identities_only: false
identity_file: null
keepalive_count: 10
keepalive_interval: 30
password: null
port: null
python_path:
- /usr/bin/python3
remote_name: null
ssh_args:
- -F
- /data/my-work/my_custom_ssh_config
- -o
- UserKnownHostsFile=/dev/null
- -o
- ConnectTimeout=20
- -o
- ControlMaster=auto
- -o
- ControlPersist=60s
ssh_debug_level: null
ssh_path: ssh
username: '{{ lookup(''env'', ''USERNAME'') | default(my.username, true) }}'
method: ssh
mitogen_get_stack
print after the changes mentioned by @macksyma
discovered_interpreter: false
result:
- kwargs:
check_host_keys: ignore
compression: true
connect_timeout: 10
hostname: 10.31.103.20
identities_only: false
identity_file: null
keepalive_count: 10
keepalive_interval: 30
password: null
port: null
python_path:
- /usr/bin/python3
remote_name: null
ssh_args:
- -F
- /data/my-work/my_custom_ssh_config
- -o
- UserKnownHostsFile=/dev/null
- -o
- ConnectTimeout=20
- -o
- ControlMaster=auto
- -o
- ControlPersist=60s
ssh_debug_level: null
ssh_path: ssh
username: hrawat
method: ssh
Ansible: 2.14.0 Target OS: Alpine Linux v3.17 Python: 3.10.13 mitogen: 0.3.6
I've discovered the incorrect transmission of the
remote_user
variable's value when usingdelegate_to
with Mitogen 3.4. For example, let's take a simple task:Here is the error I've received executing this task:
In the debug log, I see that the ssh command line contains the name of the variable transmitted into the
remote_user
-{{ jumper_test_user }}
, instead of the actual value of this variable:After further investigation, I've discovered that Mitogen takes the username for ssh from object
_connection._play_context
, transmitted to Mitogen'sActionModuleMixin
from Ansible'sTaskExecutor
. Inside theActionModuleMixin
object, I've found that_self._play_context.remote_user
contains the correct value of the variablejumper_test_user
, but the connection objectself._connection._play_context.remote_user
contains the variable name, including brackets, just like I saw it in the ssh command line.I've checked how the method
_execute
of Ansible's classTaskExecutor
updates attributes of its ownself._play_context
andself._connection._play_context
, and found that at some point,self._play_context
ofTaskExecutor
also contains the name of variables instead of their value. But then, it executes the methodpost_validate()
for itsself._play_context
(PlayContext inherits it from its parent classes):that replaces variable names with their values. Unfortunately, it doesn't execute this method for
_connection._play_context
, and as a result, we have variable names instead of values. I'm not sure whether it is a bug or there is some reason to avoid execution of this method for_connection._play_context
inside method_execute
. As a temporary workaround, I've appended the constructor ofActionModuleMixin
with the execution ofself._connection._play_context.post_validate(templar=connection.templar)
:and after that got the correct value of
remote_user
when usingdelegate_to
in my tasks.Probably you will find better approach solving this issue.
Thank you in advance.