diff options
author | Sam Doran <sdoran@redhat.com> | 2019-11-11 20:37:58 -0500 |
---|---|---|
committer | Matt Davis <nitzmahone@users.noreply.github.com> | 2019-11-11 17:37:58 -0800 |
commit | 0c89a97107241770757fa326b3882fded2194d06 (patch) | |
tree | d04aa04c9abe7a4dc945d57433bee51f5460b9aa | |
parent | ba2956721049ccff7690ed3b41a3eb44680d6f42 (diff) | |
download | ansible-0c89a97107241770757fa326b3882fded2194d06.tar.gz |
[stable-2.8] copy - check for changes beyond first level of subdirectories (#58323) (#64112)
Add integration test for copy: deep recursive with remote_src=True
(cherry picked from commit b7e38dfa52)
Co-authored-by: Alexander Korsunsky <A.Korsunsky@gmail.com>
-rw-r--r-- | changelogs/fragments/58323-copy-deep-recursive-with-remote_src.yaml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/files/copy.py | 3 | ||||
-rw-r--r-- | test/integration/targets/copy/tasks/tests.yml | 56 |
3 files changed, 61 insertions, 0 deletions
diff --git a/changelogs/fragments/58323-copy-deep-recursive-with-remote_src.yaml b/changelogs/fragments/58323-copy-deep-recursive-with-remote_src.yaml new file mode 100644 index 0000000000..b8106f9232 --- /dev/null +++ b/changelogs/fragments/58323-copy-deep-recursive-with-remote_src.yaml @@ -0,0 +1,2 @@ +bugfixes: +- copy - recursive copy with ``remote_src=yes`` now recurses beyond first level. (Fixes https://github.com/ansible/ansible/issues/58284) diff --git a/lib/ansible/modules/files/copy.py b/lib/ansible/modules/files/copy.py index 0bbbf5a6ba..1a24bd9f56 100644 --- a/lib/ansible/modules/files/copy.py +++ b/lib/ansible/modules/files/copy.py @@ -483,6 +483,9 @@ def copy_common_dirs(src, dest, module): left_only_changed = copy_left_only(b_src_item_path, b_dest_item_path, module) if diff_files_changed or left_only_changed: changed = True + + # recurse into subdirectory + changed = changed or copy_common_dirs(os.path.join(src, item), os.path.join(dest, item), module) return changed diff --git a/test/integration/targets/copy/tasks/tests.yml b/test/integration/targets/copy/tasks/tests.yml index 6f546724c9..e1ee018bad 100644 --- a/test/integration/targets/copy/tasks/tests.yml +++ b/test/integration/targets/copy/tasks/tests.yml @@ -1932,6 +1932,62 @@ - "stat_testcase4_local_follow_false_remote_dir_src_link_file12.stat.exists" - "stat_testcase4_local_follow_false_remote_dir_src_link_file12.stat.islnk" +- block: + - name: execute - Clone the source directory on remote + copy: + remote_src: True + src: '{{ remote_dir }}/remote_dir_src/' + dest: '{{ remote_dir }}/testcase5_remote_src_subdirs_src' + - name: Create a 2nd level subdirectory + file: + path: '{{ remote_dirĀ }}/testcase5_remote_src_subdirs_src/subdir/subdir2/' + state: directory + - name: execute - Copy the directory on remote + copy: + remote_src: True + src: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/' + dest: '{{ remote_dir }}/testcase5_remote_src_subdirs_dest' + local_follow: True + - name: execute - Create a new file in the subdir + copy: + dest: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/subdir/subdir2/file13' + content: 'very new file' + - name: gather - Stat the testcase5_remote_src_subdirs_src/subdir/subdir2/file13 + stat: + path: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/subdir/subdir2/file13' + - name: execute - Copy the directory on remote + copy: + remote_src: True + src: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/' + dest: '{{ remote_dir }}/testcase5_remote_src_subdirs_dest/' + register: testcase5_new + - name: execute - Edit a file in the subdir + copy: + dest: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/subdir/subdir2/file13' + content: 'NOT hello world 12' + - name: gather - Stat the testcase5_remote_src_subdirs_src/subdir/subdir2/file13 + stat: + path: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/subdir/subdir2/file13' + register: stat_testcase5_remote_src_subdirs_file13_before + - name: execute - Copy the directory on remote + copy: + remote_src: True + src: '{{ remote_dir }}/testcase5_remote_src_subdirs_src/' + dest: '{{ remote_dir }}/testcase5_remote_src_subdirs_dest/' + register: testcase5_edited + - name: gather - Stat the testcase5_remote_src_subdirs_dest/subdir/subdir2/file13 + stat: + path: '{{ remote_dir }}/testcase5_remote_src_subdirs_dest/subdir/subdir2/file13' + register: stat_testcase5_remote_src_subdirs_file13 + - name: assert - remote_dir_src has copied with local_follow False. + assert: + that: + - testcase5_new is changed + - testcase5_edited is changed + - "stat_testcase5_remote_src_subdirs_file13.stat.exists" + - "stat_testcase5_remote_src_subdirs_file13_before.stat.checksum == stat_testcase5_remote_src_subdirs_file13.stat.checksum" + + ## test copying the directory on remote with chown |