Commit ea5186ca by James Tanner

Fixes #6590 add set_remote_user parameter to synchronize

This allows usage of custom ssh configs for remote hosts where
the inventory user does not match the configured user.
parent c729bf20
...@@ -30,7 +30,10 @@ class ActionModule(object): ...@@ -30,7 +30,10 @@ class ActionModule(object):
def _process_origin(self, host, path, user): def _process_origin(self, host, path, user):
if not host in ['127.0.0.1', 'localhost']: if not host in ['127.0.0.1', 'localhost']:
return '%s@%s:%s' % (user, host, path) if user:
return '%s@%s:%s' % (user, host, path)
else:
return '%s:%s' % (host, path)
else: else:
return path return path
...@@ -38,7 +41,10 @@ class ActionModule(object): ...@@ -38,7 +41,10 @@ class ActionModule(object):
transport = self.runner.transport transport = self.runner.transport
return_data = None return_data = None
if not host in ['127.0.0.1', 'localhost'] or transport != "local": if not host in ['127.0.0.1', 'localhost'] or transport != "local":
return_data = '%s@%s:%s' % (user, host, path) if user:
return_data = '%s@%s:%s' % (user, host, path)
else:
return_data = '%s:%s' % (host, path)
else: else:
return_data = path return_data = path
...@@ -122,13 +128,14 @@ class ActionModule(object): ...@@ -122,13 +128,14 @@ class ActionModule(object):
if process_args or use_delegate: if process_args or use_delegate:
user = None user = None
if use_delegate: if utils.boolean(options.get('set_remote_user', 'yes')):
user = inject['hostvars'][conn.delegate].get('ansible_ssh_user') if use_delegate:
user = inject['hostvars'][conn.delegate].get('ansible_ssh_user')
if not use_delegate or not user:
user = inject.get('ansible_ssh_user',
self.runner.remote_user)
if not use_delegate or not user:
user = inject.get('ansible_ssh_user',
self.runner.remote_user)
if use_delegate: if use_delegate:
# FIXME # FIXME
private_key = inject.get('ansible_ssh_private_key_file', self.runner.private_key_file) private_key = inject.get('ansible_ssh_private_key_file', self.runner.private_key_file)
......
...@@ -119,6 +119,12 @@ options: ...@@ -119,6 +119,12 @@ options:
- Specify a --timeout for the rsync command in seconds. - Specify a --timeout for the rsync command in seconds.
default: 10 default: 10
required: false required: false
set_remote_user:
description:
- put user@ for the remote paths. If you have a custom ssh config to define the remote user for a host
that does not match the inventory user, you should set this parameter to "no".
default: yes
required: false
notes: notes:
- Inspect the verbose output to validate the destination user/host/path - Inspect the verbose output to validate the destination user/host/path
are what was expected. are what was expected.
...@@ -189,6 +195,7 @@ def main(): ...@@ -189,6 +195,7 @@ def main():
times = dict(type='bool'), times = dict(type='bool'),
owner = dict(type='bool'), owner = dict(type='bool'),
group = dict(type='bool'), group = dict(type='bool'),
set_remote_user = dict(default='yes', type='bool'),
rsync_timeout = dict(type='int', default=10) rsync_timeout = dict(type='int', default=10)
), ),
supports_check_mode = True supports_check_mode = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment