diff --git a/test/integration/targets/copy/tasks/dest_in_non_existent_dir.yml b/test/integration/targets/copy/tasks/dest_in_non_existent_dir.yml new file mode 100644 index 00000000000..88e7d5e9361 --- /dev/null +++ b/test/integration/targets/copy/tasks/dest_in_non_existent_dir.yml @@ -0,0 +1,28 @@ +# src is a file, dest is a non-existent directory: checks that dest is created +- name: Ensure that dest directory doesn't exist + file: + path: '{{ remote_dir }}/new_sub_dir1/' + state: absent + +- name: Copy file, dest is a non-existing target directory + copy: + src: '{{ item.src }}' + dest: '{{ remote_dir }}/new_sub_dir1/{{ item.dest }}' + register: copy_result + +- name: assert copy worked + assert: + that: + - 'copy_result|success' + - 'copy_result|changed' + +- name: stat the copied path + stat: + path: '{{ remote_dir }}/new_sub_dir1/sub_dir2/{{ item.check }}' + register: stat_file_in_dir_result + +- name: assert that the file exists + assert: + that: + - stat_file_in_dir_result.stat.exists + - stat_file_in_dir_result.stat.isreg diff --git a/test/integration/targets/copy/tasks/src_file_dest_file_in_non_existent_dir.yml b/test/integration/targets/copy/tasks/src_file_dest_file_in_non_existent_dir.yml new file mode 100644 index 00000000000..f5b927d100b --- /dev/null +++ b/test/integration/targets/copy/tasks/src_file_dest_file_in_non_existent_dir.yml @@ -0,0 +1,26 @@ +- name: Ensure that dest directory doesn't exist + file: + path: '{{ remote_dir }}/new_sub_dir1' + state: absent + +- name: Copy file, dest is a file in non-existing target directory + copy: + src: foo.txt + dest: '{{ remote_dir }}/new_sub_dir1/sub_dir2/foo.txt' + register: copy_result + ignore_errors: True + +- name: Assert copy failed + assert: + that: + - 'copy_result|failed' + +- name: Stat the dest + stat: + path: '{{ remote_dir }}/new_sub_dir1' + register: stat_file_in_dir_result + +- name: assert that dest doesn't exist + assert: + that: + - 'not stat_file_in_dir_result.stat.exists' diff --git a/test/integration/targets/copy/tasks/tests.yml b/test/integration/targets/copy/tasks/tests.yml index 7fcb424508a..74328d6713a 100644 --- a/test/integration/targets/copy/tasks/tests.yml +++ b/test/integration/targets/copy/tasks/tests.yml @@ -926,3 +926,15 @@ - stat_file_in_dir_result.stat.isreg - stat_circular_symlink_result.stat.exists - stat_circular_symlink_result.stat.islnk + +# src is a file, dest is a non-existent directory: checks that dest is created +- include: dest_in_non_existent_dir.yml + with_items: + - { src: 'foo.txt', dest: 'sub_dir2/', check: 'foo.txt' } + - { src: 'subdir', dest: 'sub_dir2/', check: 'subdir/bar.txt' } + - { src: 'subdir/', dest: 'sub_dir2/', check: 'bar.txt' } + - { src: 'subdir', dest: 'sub_dir2', check: 'subdir/bar.txt' } + - { src: 'subdir/', dest: 'sub_dir2', check: 'bar.txt' } + +# src is a file, dest is file in a non-existent directory: checks that a failure occurs +- include: src_file_dest_file_in_non_existent_dir.yml