Commit 088682f5 by Toshio Kuratomi

Synchronize in wasn't running on localhost in the default case which meant that…

Synchronize in wasn't running on localhost in the default case which meant that rsync was run on the wrong host.

Fixes #11649
parent 0d7d22d5
......@@ -18,9 +18,11 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import sys
import os.path
from ansible.plugins.action import ActionBase
from ansible.plugins import connection_loader
from ansible.utils.boolean import boolean
from ansible import constants
......@@ -81,39 +83,35 @@ class ActionModule(ActionBase):
transport_overridden = True
self._play_context.become = False
src = self._task.args.get('src', None)
dest = self._task.args.get('dest', None)
use_ssh_args = self._task.args.pop('use_ssh_args', None)
# FIXME: this doesn't appear to be used anywhere?
local_rsync_path = task_vars.get('ansible_rsync_path')
# Parameter name needed by the ansible module
self._task.args['_local_rsync_path'] = task_vars.get('ansible_rsync_path') or 'rsync'
# from the perspective of the rsync call the delegate is the localhost
src_host = '127.0.0.1'
dest_host = task_vars.get('ansible_ssh_host') or task_vars.get('inventory_hostname')
# allow ansible_ssh_host to be templated
### FIXME: do we still need to explicitly template ansible_ssh_host here in v2?
dest_is_local = dest_host in ['127.0.0.1', 'localhost']
# CHECK FOR NON-DEFAULT SSH PORT
dest_port = task_vars.get('ansible_ssh_port') or self._task.args.get('dest_port') or 22
# edge case: explicit delegate and dest_host are the same
if dest_host == task_vars.get('delegate_to'):
dest_host = '127.0.0.1'
# SWITCH SRC AND DEST PER MODE
if self._task.args.get('mode', 'push') == 'pull':
(dest_host, src_host) = (src_host, dest_host)
# CHECK DELEGATE HOST INFO
use_delegate = False
# FIXME: not sure if this is in connection info yet or not...
#if conn.delegate != conn.host:
# if 'hostvars' in task_vars:
# if conn.delegate in task_vars['hostvars'] and original_transport != 'local':
# # use a delegate host instead of localhost
# use_delegate = True
if dest_host == task_vars.get('delegate_to'):
# edge case: explicit delegate and dest_host are the same
dest_host = '127.0.0.1'
use_delegate = True
else:
if 'hostvars' in task_vars:
if task_vars.get('delegate_to') in task_vars['hostvars'] and original_transport != 'local':
# use a delegate host instead of localhost
use_delegate = True
# COMPARE DELEGATE, HOST AND TRANSPORT
process_args = False
......@@ -121,7 +119,23 @@ class ActionModule(ActionBase):
# interpret and task_vars remote host info into src or dest
process_args = True
# SWITCH SRC AND DEST PER MODE
if self._task.args.get('mode', 'push') == 'pull':
(dest_host, src_host) = (src_host, dest_host)
# Delegate to localhost as the source of the rsync unless we've been
# told (via delegate_to) that a different host is the source of the
# rsync
if not use_delegate:
# Create a connection to localhost to run rsync on
### FIXME: Do we have to dupe stdin or is this sufficient?
new_stdin = self._connection._new_stdin
new_connection = connection_loader.get('local', self._play_context, new_stdin)
self._connection = new_connection
# MUNGE SRC AND DEST PER REMOTE_HOST INFO
src = self._task.args.get('src', None)
dest = self._task.args.get('dest', None)
if process_args or use_delegate:
user = None
......@@ -155,6 +169,10 @@ class ActionModule(ActionBase):
self._task.args['src'] = src
self._task.args['dest'] = dest
# Remove mode as it is handled purely in this action module
if 'mode' in self._task.args:
del self._task.args['mode']
# Allow custom rsync path argument.
rsync_path = self._task.args.get('rsync_path', None)
......@@ -169,13 +187,7 @@ class ActionModule(ActionBase):
if use_ssh_args:
self._task.args['ssh_args'] = constants.ANSIBLE_SSH_ARGS
# Remove mode as it is handled purely in this action module
if 'mode' in self._task.args:
del self._task.args['mode']
# run the module and store the result
result = self._execute_module('synchronize', task_vars=task_vars)
return result
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