Closed Akasurde closed 3 years ago
The code on this was bugging me and I woke up with a thought on this.
Could this be changed from:
# Determine if we need a user@
user = None
if not dest_is_local:
# Src and dest rsync "path" handling
if boolean(_tmp_args.get('set_remote_user', 'yes'), strict=False):
if use_delegate:
user = task_vars.get('ansible_delegated_vars', dict()).get('ansible_ssh_user', None)
if not user:
user = task_vars.get('ansible_ssh_user') or self._play_context.remote_user
if not user:
user = C.DEFAULT_REMOTE_USER
else:
user = task_vars.get('ansible_ssh_user') or self._play_context.remote_user
To:
# Determine if we need a user@
user = None
if not dest_is_local:
# Src and dest rsync "path" handling
if boolean(_tmp_args.get('set_remote_user', 'yes'), strict=False):
if use_delegate:
delegated_task_vars = task_vars.get('ansible_delegated_vars', dict())
user = delegated_task_vars.get('ansible_user') or delegated_task_vars.get('ansible_ssh_user')
if not user:
user = task_vars.get('ansible_user') or task_vars.get('ansible_ssh_user') or self._play_context.remote_user
if not user:
user = C.DEFAULT_REMOTE_USER
else:
user = task_vars.get('ansible_user') or task_vars.get('ansible_ssh_user') or self._play_context.remote_user
The key pieces being to check for 'ansible_user' in preference to 'ansible_ssh_user'. My suggestion on this to also create a delegated_task_vars variable local to this section to reduce lookups.
I'd like to contribute a PR to fix this - I have attempted to run "ansible-test" using the following:
ansible-test sanity --docker default -v
Unfortunately that seems to fail.
ERROR: The 10 sanity test(s) listed below (out of 45) failed. See error output above for details.
ansible-doc
changelog
import --python 2.6
import --python 2.7
import --python 3.5
import --python 3.6
import --python 3.7
import --python 3.8
import --python 3.9
validate-modules
The general error on these is along the lines of:
ERROR: plugins/module_utils/__init__.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/module_utils/firewalld.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/module_utils/mount.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/__init__.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/acl.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/at.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/authorized_key.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/firewalld.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/mount.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/patch.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/seboolean.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/selinux.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/synchronize.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
ERROR: plugins/modules/sysctl.py:0:0: traceback: ImportError: No module named 'ansible_collections.ansible.ansible'
Can you advise on how to run the unit tests prior to beginning dev work on this?
Disregard previous comment - I had the project checkout on disk as ansible_collections/ansible/ansible.posix
- moving it to ansible_collections/ansible/posix
resolved issue - I can run sanity/unit tests now
Documentation doesn't refer to ansible_ssh_user
anymore, not even as a deprecated option: https://docs.ansible.com/ansible/2.9/user_guide/intro_inventory.html, although synchronize
's action plugin and unit tests still use it in place of (or mixed with) ansible_user
:
$ grep -rl ansible_ssh_user *
plugins/action/synchronize.py
tests/unit/plugins/action/fixtures/synchronize/delegate_remote_su/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote_su/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic_vagrant/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic_vagrant/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic_become_cli/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic_become_cli/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_sudo/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_sudo/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic_with_private_key/taskvars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic_with_private_key/taskvars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic/taskvars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic/taskvars_in.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote_play_context_private_key/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote_play_context_private_key/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_become_cli/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_become_cli/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/basic_become/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/basic_become/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote_with_private_key/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote_with_private_key/task_vars_in.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote/task_vars_out.json
tests/unit/plugins/action/fixtures/synchronize/delegate_remote/task_vars_in.json
This is also the case for ansible_ssh_port
(that should be ansible_port
).
resolved_by_pr #159
From @djgraff209 on Jun 23, 2020 22:12
SUMMARY
The Ansible 'synchronize' refers to the deprecated 'ansible_ssh_user' variable exclusively without taking into account the 'ansible_user' (2.9+) variable.
ISSUE TYPE
COMPONENT NAME
synchronize
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Controller: MacOS Catalina 10.15.5 / Python3 3.8.2 Target Node Set: 8 nodes running Redhat 7.7 1 node running CentOS 7.7
STEPS TO REPRODUCE
Assume following:
Provide a playbook to synchronize between a RedHat and CentOS
EXPECTED RESULTS
Expect that synchronize plugin will copy redhat@host1:/some/directory/somefile.tar.gz to centos@host2:/tmp/somefile.tar.gz using rsync command delegated to host1.
ACTUAL RESULTS
Task fails to copy indicating too many authentication attempts.
NB - I updated my inventory adding
ansible_ssh_user
to matchansible_user
on host2 and the operation succeededDigging through the source https://github.com/ansible/ansible/blob/stable-2.9/lib/ansible/plugins/action/synchronize.py#L320
This section appears to need some care & feeding to consider
ansible_user
Copied from original issue: ansible/ansible#70248