1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #4935 Synchronize module: set destination to an fqdn if connection is not local, and abide by ansible_remote_user

This commit is contained in:
James Tanner 2014-01-02 14:58:12 -05:00
parent 99560e3902
commit cb2214d6f8

View file

@ -34,6 +34,13 @@ class ActionModule(object):
else:
return path
def _process_remote(self, host, path, user):
transport = self.runner.transport
if not host in ['127.0.0.1', 'localhost'] or transport != "local":
return '%s@%s:%s' % (user, host, path)
else:
return path
def setup(self, module_name, inject):
''' Always default to localhost as delegate if None defined '''
if inject.get('delegate_to') is None:
@ -92,8 +99,15 @@ class ActionModule(object):
private_key = os.path.expanduser(private_key)
options['private_key'] = private_key
src = self._process_origin(src_host, src, user)
# use the mode to define src and dest's url
if options.get('mode', 'push') == 'pull':
# src is a remote path: <user>@<host>, dest is a local path
src = self._process_remote(src_host, src, user)
dest = self._process_origin(dest_host, dest, user)
else:
# src is a local path, dest is a remote path: <user>@<host>
src = self._process_origin(src_host, src, user)
dest = self._process_remote(dest_host, dest, user)
options['src'] = src
options['dest'] = dest