Merge pull request #10943 from sivel/sync-ssh-args-v2
Add ability to specify using ssh_args in synchronize for v2
This commit is contained in:
commit
dd7a641e76
1 changed files with 19 additions and 9 deletions
|
@ -22,6 +22,8 @@ import os.path
|
||||||
|
|
||||||
from ansible.plugins.action import ActionBase
|
from ansible.plugins.action import ActionBase
|
||||||
from ansible.utils.boolean import boolean
|
from ansible.utils.boolean import boolean
|
||||||
|
from ansible import constants
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(ActionBase):
|
class ActionModule(ActionBase):
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ class ActionModule(ActionBase):
|
||||||
path = self._get_absolute_path(path=path)
|
path = self._get_absolute_path(path=path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def _process_remote(self, host, task, path, user):
|
def _process_remote(self, host, path, user):
|
||||||
transport = self._connection_info.connection
|
transport = self._connection_info.connection
|
||||||
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":
|
||||||
|
@ -69,7 +71,7 @@ class ActionModule(ActionBase):
|
||||||
def run(self, tmp=None, task_vars=dict()):
|
def run(self, tmp=None, task_vars=dict()):
|
||||||
''' generates params and passes them on to the rsync module '''
|
''' generates params and passes them on to the rsync module '''
|
||||||
|
|
||||||
original_transport = task_vars.get('ansible_connection', self._connection_info.connection)
|
original_transport = task_vars.get('ansible_connection') or self._connection_info.connection
|
||||||
transport_overridden = False
|
transport_overridden = False
|
||||||
if task_vars.get('delegate_to') is None:
|
if task_vars.get('delegate_to') is None:
|
||||||
task_vars['delegate_to'] = '127.0.0.1'
|
task_vars['delegate_to'] = '127.0.0.1'
|
||||||
|
@ -77,24 +79,25 @@ class ActionModule(ActionBase):
|
||||||
if original_transport != 'local':
|
if original_transport != 'local':
|
||||||
task_vars['ansible_connection'] = 'local'
|
task_vars['ansible_connection'] = 'local'
|
||||||
transport_overridden = True
|
transport_overridden = True
|
||||||
self.runner.sudo = False
|
self._connection_info.become = False
|
||||||
|
|
||||||
src = self._task.args.get('src', None)
|
src = self._task.args.get('src', None)
|
||||||
dest = self._task.args.get('dest', 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?
|
# FIXME: this doesn't appear to be used anywhere?
|
||||||
local_rsync_path = task_vars.get('ansible_rsync_path')
|
local_rsync_path = task_vars.get('ansible_rsync_path')
|
||||||
|
|
||||||
# from the perspective of the rsync call the delegate is the localhost
|
# 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', task_vars.get('inventory_hostname'))
|
dest_host = task_vars.get('ansible_ssh_host') or task_vars.get('inventory_hostname')
|
||||||
|
|
||||||
# allow ansible_ssh_host to be templated
|
# allow ansible_ssh_host to be templated
|
||||||
dest_is_local = dest_host in ['127.0.0.1', 'localhost']
|
dest_is_local = dest_host in ['127.0.0.1', 'localhost']
|
||||||
|
|
||||||
# CHECK FOR NON-DEFAULT SSH PORT
|
# CHECK FOR NON-DEFAULT SSH PORT
|
||||||
dest_port = self._task.args.get('dest_port')
|
dest_port = self._task.args.get('dest_port')
|
||||||
inv_port = task_vars.get('ansible_ssh_port', task_vars.get('inventory_hostname'))
|
inv_port = task_vars.get('ansible_ssh_port') or task_vars.get('inventory_hostname')
|
||||||
if inv_port != dest_port and inv_port != task_vars.get('inventory_hostname'):
|
if inv_port != dest_port and inv_port != task_vars.get('inventory_hostname'):
|
||||||
dest_port = inv_port
|
dest_port = inv_port
|
||||||
|
|
||||||
|
@ -130,16 +133,17 @@ class ActionModule(ActionBase):
|
||||||
user = task_vars['hostvars'][conn.delegate].get('ansible_ssh_user')
|
user = task_vars['hostvars'][conn.delegate].get('ansible_ssh_user')
|
||||||
|
|
||||||
if not use_delegate or not user:
|
if not use_delegate or not user:
|
||||||
user = task_vars.get('ansible_ssh_user', self.runner.remote_user)
|
user = task_vars.get('ansible_ssh_user') or self._connection_info.remote_user
|
||||||
|
|
||||||
if use_delegate:
|
if use_delegate:
|
||||||
# FIXME
|
# FIXME
|
||||||
private_key = task_vars.get('ansible_ssh_private_key_file', self.runner.private_key_file)
|
private_key = task_vars.get('ansible_ssh_private_key_file') or self._connection_info.private_key_file
|
||||||
else:
|
else:
|
||||||
private_key = task_vars.get('ansible_ssh_private_key_file', self.runner.private_key_file)
|
private_key = task_vars.get('ansible_ssh_private_key_file') or self._connection_info.private_key_file
|
||||||
|
|
||||||
if private_key is not None:
|
if private_key is not None:
|
||||||
private_key = os.path.expanduser(private_key)
|
private_key = os.path.expanduser(private_key)
|
||||||
|
self._task.args['private_key'] = private_key
|
||||||
|
|
||||||
# use the mode to define src and dest's url
|
# use the mode to define src and dest's url
|
||||||
if self._task.args.get('mode', 'push') == 'pull':
|
if self._task.args.get('mode', 'push') == 'pull':
|
||||||
|
@ -151,6 +155,9 @@ class ActionModule(ActionBase):
|
||||||
src = self._process_origin(src_host, src, user)
|
src = self._process_origin(src_host, src, user)
|
||||||
dest = self._process_remote(dest_host, dest, user)
|
dest = self._process_remote(dest_host, dest, user)
|
||||||
|
|
||||||
|
self._task.args['src'] = src
|
||||||
|
self._task.args['dest'] = dest
|
||||||
|
|
||||||
# Allow custom rsync path argument.
|
# Allow custom rsync path argument.
|
||||||
rsync_path = self._task.args.get('rsync_path', None)
|
rsync_path = self._task.args.get('rsync_path', None)
|
||||||
|
|
||||||
|
@ -162,6 +169,9 @@ class ActionModule(ActionBase):
|
||||||
if rsync_path:
|
if rsync_path:
|
||||||
self._task.args['rsync_path'] = '"%s"' % rsync_path
|
self._task.args['rsync_path'] = '"%s"' % rsync_path
|
||||||
|
|
||||||
|
if use_ssh_args:
|
||||||
|
self._task.args['ssh_args'] = constants.ANSIBLE_SSH_ARGS
|
||||||
|
|
||||||
# run the module and store the result
|
# run the module and store the result
|
||||||
result = self._execute_module('synchronize')
|
result = self._execute_module('synchronize')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue