-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The attribute 'remote_user' of the object 'connection._play_context' contains the variable name instead of its value. #1040
Comments
Thank you, this may be closely related to #1022 or a case of it. |
Hi, I have the same issue.
Ansible: 2.14.0 |
Notes
|
@macksyma believe your example will now work, with Mitogen 0.3.13. Sorry for the long wait. |
@moreati It seems that another bug came up after this fix. Now, variables defined in ---
- hosts: localhost
gather_facts: no
vars:
my_user: "my_user"
tasks: or as extra vars: ansible-playbook -vv test_playbooks/test_mitogen.yml -e "my_user=my_user" seem to hit the right context and everything works fine. Here is the task list used for the test: ---
- hosts: localhost
gather_facts: no
tasks:
- name: "define user and host"
set_fact:
my_user: "my_user"
my_host: "10.192.65.127"
exec_command: "uname -a"
- debug:
var: my_user
- name: "test"
shell: "{{ exec_command }}"
delegate_to: "{{ my_host }}"
remote_user: "{{ my_user }}" execution result:
|
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.
2.13 ansible core 2.14.0 and core 2.13.13 too
No
Yes
Host: Ubuntu 22.04.3 LTS (target host doesn't matter for this issue)
Host: python3.10 (target host doesn't matter for this issue)
The text was updated successfully, but these errors were encountered: