Straightened out the logic for delegate handling in synchronize action module
This commit is contained in:
parent
90867d0d0a
commit
d8cd3d603e
1 changed files with 9 additions and 4 deletions
|
@ -35,13 +35,12 @@ class ActionModule(object):
|
||||||
|
|
||||||
def setup(self, module_name, inject):
|
def setup(self, module_name, inject):
|
||||||
''' Always default to localhost as delegate if None defined '''
|
''' Always default to localhost as delegate if None defined '''
|
||||||
if inject.get('delegate_to') is None:
|
if inject['delegate_to'] is None:
|
||||||
inject['delegate_to'] = '127.0.0.1'
|
inject['delegate_to'] = '127.0.0.1'
|
||||||
inject['ansible_connection'] = 'local'
|
inject['ansible_connection'] = 'local'
|
||||||
# If sudo is active, disable from the connection set self.sudo to True.
|
# If sudo is active, disable from the connection set self.sudo to True.
|
||||||
if self.runner.sudo:
|
if self.runner.sudo:
|
||||||
self.runner.sudo = False
|
self.runner.sudo = False
|
||||||
self.sudo = True
|
|
||||||
|
|
||||||
def run(self, conn, tmp, module_name, module_args,
|
def run(self, conn, tmp, module_name, module_args,
|
||||||
inject, complex_args=None, **kwargs):
|
inject, complex_args=None, **kwargs):
|
||||||
|
@ -63,8 +62,14 @@ class ActionModule(object):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
src_host = inject['delegate_to']
|
# from the perspective of the rsync call the delegate is the localhost
|
||||||
|
src_host = '127.0.0.1'
|
||||||
dest_host = inject.get('ansible_ssh_host', inject['inventory_hostname'])
|
dest_host = inject.get('ansible_ssh_host', inject['inventory_hostname'])
|
||||||
|
|
||||||
|
# edge case: explicit delegate and dest_host are the same
|
||||||
|
if dest_host == inject['delegate_to']:
|
||||||
|
dest_host = '127.0.0.1'
|
||||||
|
|
||||||
if options.get('mode', 'push') == 'pull':
|
if options.get('mode', 'push') == 'pull':
|
||||||
(dest_host, src_host) = (src_host, dest_host)
|
(dest_host, src_host) = (src_host, dest_host)
|
||||||
if not dest_host is src_host:
|
if not dest_host is src_host:
|
||||||
|
@ -82,7 +87,7 @@ class ActionModule(object):
|
||||||
del options['mode']
|
del options['mode']
|
||||||
|
|
||||||
rsync_path = options.get('rsync_path', None)
|
rsync_path = options.get('rsync_path', None)
|
||||||
if not rsync_path and self.sudo:
|
if not rsync_path and self.runner.sudo:
|
||||||
rsync_path = 'sudo rsync'
|
rsync_path = 'sudo rsync'
|
||||||
|
|
||||||
# make sure rsync path is quoted.
|
# make sure rsync path is quoted.
|
||||||
|
|
Loading…
Reference in a new issue