summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Shrewsbury <Shrews@users.noreply.github.com>2020-06-11 21:18:59 +0200
committerGitHub <noreply@github.com>2020-06-11 21:18:59 +0200
commit0ae4dac65a6f78dac4fcfce6d1074074eeac2f4e (patch)
treef71c4e33d4588d126c1e8fb2c989299044cbca4b /test
parentFix changelog sanity test config detection. (diff)
downloadansible-0ae4dac65a6f78dac4fcfce6d1074074eeac2f4e.tar.xz
ansible-0ae4dac65a6f78dac4fcfce6d1074074eeac2f4e.zip
Fix copy module file perms with remote_src (#69993)
When using 'remote_src: yes' and 'mode: preserve', the code handling the file modes has to be handled on the remote node because it's the one that has access to the source files. This means that the copy module itself must handle this, rather than the copy action plugin (which is where all that logic exists). The copy module handles this when we copy a single file over. But when it is a directory as the src parameter value, the mode of the files beneath it are not considered. Subdirectories are copied with shutil.copytree() which will preserve permissions automatically. Individual files are copied with shutil.copyfile() which does NOT preserve permissions. We need to add some calls to shutil.copymode() to correct that. Note: This *always* retains individial file permissions. Specifying a 'mode' other than 'preserve' when giving a source directory for the 'src' param does not make sense so will be ignored in that case only. Fixes #69783 * Add changelog and test
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/copy/tasks/tests.yml70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/integration/targets/copy/tasks/tests.yml b/test/integration/targets/copy/tasks/tests.yml
index 8e47e4755e..be9553179e 100644
--- a/test/integration/targets/copy/tasks/tests.yml
+++ b/test/integration/targets/copy/tasks/tests.yml
@@ -2189,3 +2189,73 @@
- "stat_remote_dir_src_link_file12_before.stat.gr_name == stat_remote_dir_src_link_file12_after.stat.gr_name"
- "stat_remote_dir_src_link_file12_before.stat.path == stat_remote_dir_src_link_file12_after.stat.path"
- "stat_remote_dir_src_link_file12_before.stat.mode == stat_remote_dir_src_link_file12_after.stat.mode"
+
+# Test for issue 69783: copy with remote_src=yes and src='dir/' preserves all permissions
+- block:
+ - name: Create directory structure
+ file:
+ path: "{{ local_temp_dir }}/test69783/{{ item }}"
+ state: directory
+ loop:
+ - "src/dir"
+ - "dest"
+
+ - name: Create source file structure
+ file:
+ path: "{{ local_temp_dir }}/test69783/src/{{ item.name }}"
+ state: touch
+ mode: "{{ item.mode }}"
+ loop:
+ - { name: 'readwrite', mode: '0644' }
+ - { name: 'executable', mode: '0755' }
+ - { name: 'readonly', mode: '0444' }
+ - { name: 'dir/readwrite', mode: '0644' }
+ - { name: 'dir/executable', mode: '0755' }
+ - { name: 'dir/readonly', mode: '0444' }
+
+ - name: Recursive remote copy with preserve
+ copy:
+ src: "{{ local_temp_dir }}/test69783/src/"
+ dest: "{{ local_temp_dir }}/test69783/dest/"
+ remote_src: yes
+ mode: preserve
+
+ - name: Stat dest 'readwrite' file
+ stat:
+ path: "{{ local_temp_dir}}/test69783/dest/readwrite"
+ register: dest_readwrite_stat
+
+ - name: Stat dest 'executable' file
+ stat:
+ path: "{{ local_temp_dir}}/test69783/dest/executable"
+ register: dest_executable_stat
+
+ - name: Stat dest 'readonly' file
+ stat:
+ path: "{{ local_temp_dir}}/test69783/dest/readonly"
+ register: dest_readonly_stat
+
+ - name: Stat dest 'dir/readwrite' file
+ stat:
+ path: "{{ local_temp_dir}}/test69783/dest/dir/readwrite"
+ register: dest_dir_readwrite_stat
+
+ - name: Stat dest 'dir/executable' file
+ stat:
+ path: "{{ local_temp_dir}}/test69783/dest/dir/executable"
+ register: dest_dir_executable_stat
+
+ - name: Stat dest 'dir/readonly' file
+ stat:
+ path: "{{ local_temp_dir}}/test69783/dest/dir/readonly"
+ register: dest_dir_readonly_stat
+
+ - name: Assert modes are preserved
+ assert:
+ that:
+ - "dest_readwrite_stat.stat.mode == '0644'"
+ - "dest_executable_stat.stat.mode == '0755'"
+ - "dest_readonly_stat.stat.mode == '0444'"
+ - "dest_dir_readwrite_stat.stat.mode == '0644'"
+ - "dest_dir_executable_stat.stat.mode == '0755'"
+ - "dest_dir_readonly_stat.stat.mode == '0444'"