From a65807edc322ec403eb73e006aa9f6e2172026a3 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 11 Aug 2021 10:45:52 +0530 Subject: [PATCH] synchronize: Use SSH args from SSH connection plugins (#223) SSH configuration migrated from Ansible configuration to SSH connection configuration. Make ``synchronize`` understand this. Fixes: #222 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/222_synchronize.yml | 3 +++ plugins/action/synchronize.py | 22 ++++++++++------------ plugins/modules/synchronize.py | 4 +++- 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/222_synchronize.yml diff --git a/changelogs/fragments/222_synchronize.yml b/changelogs/fragments/222_synchronize.yml new file mode 100644 index 0000000000..af84610686 --- /dev/null +++ b/changelogs/fragments/222_synchronize.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- synchronize - use SSH args from SSH connection plugin (https://github.com/ansible-collections/ansible.posix/issues/222). diff --git a/plugins/action/synchronize.py b/plugins/action/synchronize.py index 5da2912a0b..a5752b963c 100644 --- a/plugins/action/synchronize.py +++ b/plugins/action/synchronize.py @@ -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): @@ -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: @@ -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') @@ -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: diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index cf7418b3ca..5f63dd4860 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -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: