mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #11783 from ansible/synchronize-fix
Synchronize in wasn't running on localhost in the default case which …
This commit is contained in:
commit
4f1d365a25
1 changed files with 42 additions and 30 deletions
|
@ -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'
|
||||
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
|
||||
|
@ -152,8 +166,12 @@ class ActionModule(ActionBase):
|
|||
src = self._process_origin(src_host, src, user)
|
||||
dest = self._process_remote(dest_host, dest, user)
|
||||
|
||||
self._task.args['src'] = src
|
||||
self._task.args['dest'] = dest
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue