copy: check behavior related to dest creation when src is a file

This commit is contained in:
Pierre-Louis Bonicoli 2017-08-13 14:33:04 +02:00 committed by Toshio Kuratomi
parent e52096e78a
commit 470989bff9
3 changed files with 66 additions and 0 deletions

View file

@ -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

View file

@ -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'

View file

@ -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