From ce88df3cf4374b9c45a3f4baebe193fd4fcd2051 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 14 Oct 2013 22:09:45 +0300 Subject: [PATCH] copy: Handle dest path variations for recursive mode. --- lib/ansible/runner/action_plugins/copy.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/action_plugins/copy.py b/lib/ansible/runner/action_plugins/copy.py index 32167e9a7c..f8fff102db 100644 --- a/lib/ansible/runner/action_plugins/copy.py +++ b/lib/ansible/runner/action_plugins/copy.py @@ -113,6 +113,10 @@ class ActionModule(object): full_path = os.path.join(base_path, file) rel_path = full_path[sz:] source_files.append((full_path, rel_path)) + # If it's recursive copy, destination is always a dir, + # explictly mark it so (note - copy module relies on this). + if not dest.endswith("/"): + dest += "/" else: source_files.append((source, os.path.basename(source))) @@ -192,7 +196,11 @@ class ActionModule(object): # don't send down raw=no module_args.pop('raw') - module_args_tmp = "%s src=%s original_basename=%s" % (module_args, pipes.quote(tmp_src), pipes.quote(source_rel)) + # src and dest here come after original and override them + # we pass dest only to make sure it includes trailing slash + # in case of recursive copy + module_args_tmp = "%s src=%s dest=%s original_basename=%s" % (module_args, + pipes.quote(tmp_src), pipes.quote(dest), pipes.quote(source_rel)) module_return = self.runner._execute_module(conn, tmp, 'copy', module_args_tmp, inject=inject, complex_args=complex_args) else: