From ba420c47cdaf3e9405d6ddefe0a4e221f7022718 Mon Sep 17 00:00:00 2001 From: Nicolas Porcel Date: Fri, 25 Aug 2017 03:09:15 +0200 Subject: [PATCH] synchronize: Use private_key and ssh_user with delegate_to (Fixes #16215) (#21686) --- lib/ansible/modules/files/synchronize.py | 2 +- lib/ansible/plugins/action/synchronize.py | 3 ++- .../action/fixtures/synchronize/delegate_remote/meta.yaml | 2 +- .../action/fixtures/synchronize/delegate_remote_su/meta.yaml | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/files/synchronize.py b/lib/ansible/modules/files/synchronize.py index 44d815494c..76f4b1b2b9 100644 --- a/lib/ansible/modules/files/synchronize.py +++ b/lib/ansible/modules/files/synchronize.py @@ -467,7 +467,7 @@ def main(): if is_rsh_needed(source, dest): ssh_cmd = [module.get_bin_path('ssh', required=True), '-S', 'none'] if private_key is not None: - ssh_cmd.extend(['-i', private_key]) + ssh_cmd.extend(['-i', os.path.expanduser(private_key) ]) # If the user specified a port value # Note: The action plugin takes care of setting this to a port from # inventory if the user didn't specify an explicit dest_port diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index d4d3589cc1..94ba0e1e6d 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -316,6 +316,8 @@ class ActionModule(ActionBase): 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 @@ -326,7 +328,6 @@ class ActionModule(ActionBase): private_key = self._play_context.private_key_file if private_key is not None: - private_key = os.path.expanduser(private_key) _tmp_args['private_key'] = private_key # use the mode to define src and dest's url diff --git a/test/units/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml b/test/units/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml index 06a08e6ae5..1c55b2856a 100644 --- a/test/units/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml +++ b/test/units/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml @@ -23,4 +23,4 @@ asserts: - "self.execute_called" - "self.final_module_args['_local_rsync_path'] == 'rsync'" - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'el6host:/tmp/deleteme'" + - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" diff --git a/test/units/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml b/test/units/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml index 47ae6e1d61..28e35c9e32 100644 --- a/test/units/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml +++ b/test/units/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml @@ -30,4 +30,4 @@ asserts: - "self.execute_called" - "self.final_module_args['_local_rsync_path'] == 'rsync'" - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'el6host:/tmp/deleteme'" + - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'"