From ac9278ff0f3daa0e369a7846d39f5240d38da61a Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 29 Sep 2017 20:13:32 -0400 Subject: [PATCH] remove action plugin only fields from 'file' calls (#31047) * remove action plugin only fields from 'file' calls fixes #30556 * Add a test for #30556 --- lib/ansible/plugins/action/copy.py | 17 ++++++++--------- test/integration/targets/copy/tasks/tests.yml | 5 +++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/ansible/plugins/action/copy.py b/lib/ansible/plugins/action/copy.py index fa7bbf1f548..c78f3ada26d 100644 --- a/lib/ansible/plugins/action/copy.py +++ b/lib/ansible/plugins/action/copy.py @@ -186,6 +186,10 @@ def _walk_dirs(topdir, base_path=None, local_follow=False, trailing_slash_detect class ActionModule(ActionBase): + def _create_remote_file_args(self, module_args): + # remove action plugin only keys + return dict((k, v) for k, v in module_args.items() if k not in ('content', 'decrypt')) + def _copy_file(self, source_full, source_rel, content, content_tempfile, dest, task_vars, tmp, delete_remote_tmp): decrypt = boolean(self._task.args.get('decrypt', True), strict=False) @@ -286,7 +290,7 @@ class ActionModule(ActionBase): # 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 - new_module_args = self._task.args.copy() + new_module_args = self._create_remote_file_args(self._task.args) new_module_args.update( dict( src=tmp_src, @@ -297,11 +301,6 @@ class ActionModule(ActionBase): if lmode: new_module_args['mode'] = lmode - # remove action plugin only keys - for key in ('content', 'decrypt'): - if key in new_module_args: - del new_module_args[key] - module_return = self._execute_module(module_name='copy', module_args=new_module_args, task_vars=task_vars, tmp=tmp, delete_remote_tmp=delete_remote_tmp) @@ -326,7 +325,7 @@ class ActionModule(ActionBase): dest = dest_status_nofollow['lnk_source'] # Build temporary module_args. - new_module_args = self._task.args.copy() + new_module_args = self._create_remote_file_args(self._task.args) new_module_args.update( dict( src=source_rel, @@ -335,6 +334,7 @@ class ActionModule(ActionBase): state='file', ) ) + if lmode: new_module_args['mode'] = lmode @@ -513,8 +513,7 @@ class ActionModule(ActionBase): for source_full, source_rel in source_files['files']: # copy files over. This happens first as directories that have # a file do not need to be created later - module_return = self._copy_file(source_full, source_rel, content, content_tempfile, - dest, task_vars, tmp, delete_remote_tmp) + module_return = self._copy_file(source_full, source_rel, content, content_tempfile, dest, task_vars, tmp, delete_remote_tmp) if module_return is None: continue diff --git a/test/integration/targets/copy/tasks/tests.yml b/test/integration/targets/copy/tasks/tests.yml index b121f2d4583..e030935b74e 100644 --- a/test/integration/targets/copy/tasks/tests.yml +++ b/test/integration/targets/copy/tasks/tests.yml @@ -102,6 +102,7 @@ copy: src: foo.txt dest: "{{ remote_file }}" + decrypt: no register: copy_result2 - name: Assert that the file was not changed @@ -113,6 +114,7 @@ copy: content: "modified" dest: "{{ remote_file }}" + decrypt: no register: copy_result3 - name: Check the stat results of the file @@ -137,6 +139,7 @@ content: "modified" dest: "{{ remote_file }}" mode: 0700 + decrypt: no register: copy_result4 - name: Check the stat results of the file @@ -167,6 +170,7 @@ content: 'modified' dest: '{{ remote_file }}' mode: 0700 + decrypt: no register: copy_results - name: Check the stat results of the file @@ -191,6 +195,7 @@ content: 'modified' dest: '{{ remote_file }}' mode: 0404 + decrypt: no register: copy_results - name: Check the stat results of the file