If you are copying a directory, it doesn't matter whether or not the target path ends with /
. In both cases, Ansible first ensure the target directory exists and then copy the source directory into the target directory. That is, given either:
- copy:
src: src_dir
dest: /tmp/dest/
Or:
- copy:
src: src_dir
dest: /tmp/dest
In both cases, Ansible will first create /tmp/dest
if it does not exist and will then create /tmp/dest/src_dir
and populate it with the contents of src_dir
.
However, if you are copying a file the situation is a little different. If the target destination /tmp/dest
does not exist, this playbook will create a file named /tmp/dest
:
- copy:
src: src_file
dest: /tmp/dest
However, if you add a trailing path to the destination, then Ansible will first create the directory /tmp/dest
and then create the file /tmp/dest/src_file
.
- copy:
src: src_file
dest: /tmp/dest/
If a directory named /tmp/dest
already exists, then both of the above examples will do the same thing (create /tmp/dest/src_file
).