From 2e668f14f754c0e5f691eec131fbc64eed7b6ba0 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 14 Oct 2013 22:10:27 +0300 Subject: [PATCH] copy: Handle "no copy/propagate attrs only" for recursive mode well. For this, add internal "original_basename" param to file module, similar to copy module. (Param name is a bit misnormer now, should be treated as "original basepath"). --- lib/ansible/runner/action_plugins/copy.py | 3 ++- library/files/file | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/runner/action_plugins/copy.py b/lib/ansible/runner/action_plugins/copy.py index f8fff102db7..e0fcad4cfac 100644 --- a/lib/ansible/runner/action_plugins/copy.py +++ b/lib/ansible/runner/action_plugins/copy.py @@ -217,7 +217,8 @@ class ActionModule(object): if raw: # don't send down raw=no module_args.pop('raw') - module_args_tmp = "%s src=%s" % (module_args, pipes.quote(tmp_src)) + module_args_tmp = "%s src=%s original_basename=%s" % (module_args, + pipes.quote(tmp_src), pipes.quote(source_rel)) if self.runner.noop_on_check(inject): module_args_tmp = "%s CHECKMODE=True" % module_args_tmp module_return = self.runner._execute_module(conn, tmp, 'file', module_args_tmp, inject=inject, complex_args=complex_args) diff --git a/library/files/file b/library/files/file index adbc21061af..4ea527cd501 100644 --- a/library/files/file +++ b/library/files/file @@ -144,6 +144,7 @@ def main(): argument_spec = dict( state = dict(choices=['file','directory','link','hard','touch','absent'], default='file'), path = dict(aliases=['dest', 'name'], required=True), + original_basename = dict(required=False), # Internal use only, for recursive ops recurse = dict(default='no', type='bool'), force = dict(required=False,default=False,type='bool'), diff_peek = dict(default=None), @@ -179,7 +180,11 @@ def main(): src = os.path.expanduser(src) if src is not None and os.path.isdir(path) and state != "link": - params['path'] = path = os.path.join(path, os.path.basename(src)) + if params['original_basename']: + basename = params['original_basename'] + else: + basename = os.path.basename(src) + params['path'] = path = os.path.join(path, basename) file_args = module.load_file_common_arguments(params)