Skip to content

Commit

Permalink
synchronize: Use SSH args from SSH connection plugins (#223)
Browse files Browse the repository at this point in the history
SSH configuration migrated from Ansible configuration to
SSH connection configuration. Make ``synchronize`` understand
this.

Fixes: #222

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored Aug 11, 2021
1 parent bd59497 commit a65807e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/222_synchronize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- synchronize - use SSH args from SSH connection plugin (https://github.com/ansible-collections/ansible.posix/issues/222).
22 changes: 10 additions & 12 deletions plugins/action/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def _format_rsync_rsh_target(self, host, path, user):

if self._host_is_ipv6_address(host):
return '[%s%s]:%s' % (user_prefix, host, path)
else:
return '%s%s:%s' % (user_prefix, host, path)
return '%s%s:%s' % (user_prefix, host, path)

def _process_origin(self, host, path, user):

Expand Down Expand Up @@ -178,6 +177,15 @@ def run(self, tmp=None, task_vars=None):

# Store remote connection type
self._remote_transport = self._connection.transport
use_ssh_args = _tmp_args.pop('use_ssh_args', None)

if use_ssh_args and self._connection.transport == 'ssh':
ssh_args = [
self._connection.get_option('ssh_args'),
self._connection.get_option('ssh_common_args'),
self._connection.get_option('ssh_extra_args'),
]
_tmp_args['ssh_args'] = ' '.join([a for a in ssh_args if a])

# Handle docker connection options
if self._remote_transport in DOCKER:
Expand Down Expand Up @@ -215,8 +223,6 @@ def run(self, tmp=None, task_vars=None):
"so it cannot work." % self._connection.transport)
return result

use_ssh_args = _tmp_args.pop('use_ssh_args', None)

# Parameter name needed by the ansible module
_tmp_args['_local_rsync_path'] = task_vars.get('ansible_rsync_path') or 'rsync'
_tmp_args['_local_rsync_password'] = task_vars.get('ansible_ssh_pass') or task_vars.get('ansible_password')
Expand Down Expand Up @@ -390,14 +396,6 @@ def run(self, tmp=None, task_vars=None):

_tmp_args['rsync_path'] = rsync_path

if use_ssh_args:
ssh_args = [
getattr(self._play_context, 'ssh_args', ''),
getattr(self._play_context, 'ssh_common_args', ''),
getattr(self._play_context, 'ssh_extra_args', ''),
]
_tmp_args['ssh_args'] = ' '.join([a for a in ssh_args if a])

# If launching synchronize against docker container
# use rsync_opts to support container to override rsh options
if self._remote_transport in DOCKER + BUILDAH + PODMAN and not use_delegate:
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@
default: yes
use_ssh_args:
description:
- Use the ssh_args specified in ansible.cfg. Setting this to `yes` will also make `synchronize` use `ansible_ssh_common_args`.
- In Ansible 2.10 and lower, it uses the ssh_args specified in C(ansible.cfg).
- In Ansible 2.11 and onwards, when set to C(true), it uses all SSH connection configurations like
C(ansible_ssh_args), C(ansible_ssh_common_args), and C(ansible_ssh_extra_args).
type: bool
default: no
ssh_connection_multiplexing:
Expand Down

0 comments on commit a65807e

Please sign in to comment.