From 6f3f4dff7a5ae0b69a7d738c83f7a74c7a946d70 Mon Sep 17 00:00:00 2001 From: Petr Mifek Date: Thu, 17 Sep 2015 23:19:11 +0200 Subject: [PATCH 1/3] Change synchronize module plugin to be backwards compatible with RSync 2.6.9 with regard to handling IPv6 addresses. --- lib/ansible/plugins/action/synchronize.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index f9a4b49bb7b..cb36d9c4859 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -47,10 +47,13 @@ class ActionModule(ActionBase): def _process_origin(self, host, path, user): if host not in C.LOCALHOST: + userPart = '' if user: - return '%s@[%s]:%s' % (user, host, path) + userPart = '%s@' % (user, ) + if ":" in host: + return '[%s%s]:%s' % (userPart, host, path) else: - return '[%s]:%s' % (host, path) + return '%s%s:%s' % (userPart, host, path) if ':' not in path and not path.startswith('/'): path = self._get_absolute_path(path=path) @@ -59,10 +62,13 @@ class ActionModule(ActionBase): def _process_remote(self, host, path, user): transport = self._play_context.connection if host not in C.LOCALHOST or transport != "local": + userPart = '' if user: - return '%s@[%s]:%s' % (user, host, path) + userPart = '%s@' % (user, ) + if ":" in host: + return '[%s%s]:%s' % (userPart, host, path) else: - return '[%s]:%s' % (host, path) + return '%s%s:%s' % (userPart, host, path) if ':' not in path and not path.startswith('/'): path = self._get_absolute_path(path=path) From 27f779a7cc7b2bca543f957419aa8effba3f6cda Mon Sep 17 00:00:00 2001 From: Petr Mifek Date: Fri, 18 Sep 2015 11:46:33 +0200 Subject: [PATCH 2/3] Small clean up and refactor of the rsync target ipv6 observing formatter for synchronize action. --- lib/ansible/plugins/action/synchronize.py | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index cb36d9c4859..eb7848dad05 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -44,16 +44,25 @@ class ActionModule(ActionBase): return path + def _format_rsync_rsh_target(self, host, path, user): + ''' formats rsync rsh target, escaping ipv6 addresses if needed ''' + + def _needs_ipv6_brackets(host): + return ':' in host + + user_prefix = '' + if user: + user_prefix = '%s@' % (user, ) + + if _needs_ipv6_brackets(host): + return '[%s%s]:%s' % (user_prefix, host, path) + else: + return '%s%s:%s' % (user_prefix, host, path) + def _process_origin(self, host, path, user): if host not in C.LOCALHOST: - userPart = '' - if user: - userPart = '%s@' % (user, ) - if ":" in host: - return '[%s%s]:%s' % (userPart, host, path) - else: - return '%s%s:%s' % (userPart, host, path) + return self._format_rsync_rsh_target(host, path, user) if ':' not in path and not path.startswith('/'): path = self._get_absolute_path(path=path) @@ -62,13 +71,7 @@ class ActionModule(ActionBase): def _process_remote(self, host, path, user): transport = self._play_context.connection if host not in C.LOCALHOST or transport != "local": - userPart = '' - if user: - userPart = '%s@' % (user, ) - if ":" in host: - return '[%s%s]:%s' % (userPart, host, path) - else: - return '%s%s:%s' % (userPart, host, path) + return self._format_rsync_rsh_target(host, path, user) if ':' not in path and not path.startswith('/'): path = self._get_absolute_path(path=path) From 6e035a3e94efc18d7547b5b12d0cf520a8408106 Mon Sep 17 00:00:00 2001 From: Petr Mifek Date: Sat, 10 Oct 2015 00:01:22 +0200 Subject: [PATCH 3/3] Move nested function test for ipv6 to top level in synchronize module. --- lib/ansible/plugins/action/synchronize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index eb7848dad05..c80523c0c00 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -44,17 +44,17 @@ class ActionModule(ActionBase): return path + def _host_is_ipv6_address(self, host): + return ':' in host + def _format_rsync_rsh_target(self, host, path, user): ''' formats rsync rsh target, escaping ipv6 addresses if needed ''' - def _needs_ipv6_brackets(host): - return ':' in host - user_prefix = '' if user: user_prefix = '%s@' % (user, ) - if _needs_ipv6_brackets(host): + if self._host_is_ipv6_address(host): return '[%s%s]:%s' % (user_prefix, host, path) else: return '%s%s:%s' % (user_prefix, host, path)