1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

remove action plugin only fields from 'file' calls (#31047)

* remove action plugin only fields from 'file' calls

fixes #30556

* Add a test for #30556
This commit is contained in:
Brian Coca 2017-09-29 20:13:32 -04:00 committed by Toshio Kuratomi
parent 92f777e815
commit ac9278ff0f
2 changed files with 13 additions and 9 deletions

View file

@ -186,6 +186,10 @@ def _walk_dirs(topdir, base_path=None, local_follow=False, trailing_slash_detect
class ActionModule(ActionBase): 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, def _copy_file(self, source_full, source_rel, content, content_tempfile,
dest, task_vars, tmp, delete_remote_tmp): dest, task_vars, tmp, delete_remote_tmp):
decrypt = boolean(self._task.args.get('decrypt', True), strict=False) 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 # 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 # 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( new_module_args.update(
dict( dict(
src=tmp_src, src=tmp_src,
@ -297,11 +301,6 @@ class ActionModule(ActionBase):
if lmode: if lmode:
new_module_args['mode'] = 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_return = self._execute_module(module_name='copy',
module_args=new_module_args, task_vars=task_vars, module_args=new_module_args, task_vars=task_vars,
tmp=tmp, delete_remote_tmp=delete_remote_tmp) tmp=tmp, delete_remote_tmp=delete_remote_tmp)
@ -326,7 +325,7 @@ class ActionModule(ActionBase):
dest = dest_status_nofollow['lnk_source'] dest = dest_status_nofollow['lnk_source']
# Build temporary module_args. # 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( new_module_args.update(
dict( dict(
src=source_rel, src=source_rel,
@ -335,6 +334,7 @@ class ActionModule(ActionBase):
state='file', state='file',
) )
) )
if lmode: if lmode:
new_module_args['mode'] = lmode new_module_args['mode'] = lmode
@ -513,8 +513,7 @@ class ActionModule(ActionBase):
for source_full, source_rel in source_files['files']: for source_full, source_rel in source_files['files']:
# copy files over. This happens first as directories that have # copy files over. This happens first as directories that have
# a file do not need to be created later # a file do not need to be created later
module_return = self._copy_file(source_full, source_rel, content, content_tempfile, module_return = self._copy_file(source_full, source_rel, content, content_tempfile, dest, task_vars, tmp, delete_remote_tmp)
dest, task_vars, tmp, delete_remote_tmp)
if module_return is None: if module_return is None:
continue continue

View file

@ -102,6 +102,7 @@
copy: copy:
src: foo.txt src: foo.txt
dest: "{{ remote_file }}" dest: "{{ remote_file }}"
decrypt: no
register: copy_result2 register: copy_result2
- name: Assert that the file was not changed - name: Assert that the file was not changed
@ -113,6 +114,7 @@
copy: copy:
content: "modified" content: "modified"
dest: "{{ remote_file }}" dest: "{{ remote_file }}"
decrypt: no
register: copy_result3 register: copy_result3
- name: Check the stat results of the file - name: Check the stat results of the file
@ -137,6 +139,7 @@
content: "modified" content: "modified"
dest: "{{ remote_file }}" dest: "{{ remote_file }}"
mode: 0700 mode: 0700
decrypt: no
register: copy_result4 register: copy_result4
- name: Check the stat results of the file - name: Check the stat results of the file
@ -167,6 +170,7 @@
content: 'modified' content: 'modified'
dest: '{{ remote_file }}' dest: '{{ remote_file }}'
mode: 0700 mode: 0700
decrypt: no
register: copy_results register: copy_results
- name: Check the stat results of the file - name: Check the stat results of the file
@ -191,6 +195,7 @@
content: 'modified' content: 'modified'
dest: '{{ remote_file }}' dest: '{{ remote_file }}'
mode: 0404 mode: 0404
decrypt: no
register: copy_results register: copy_results
- name: Check the stat results of the file - name: Check the stat results of the file