Chapter 3 : fetch only works on files, not directories
In Chapter 3 of the Second Edition, it says on page 35 that the src for the copy module can be a file or directory (and implies the same with fetch). This is in fact not true as I discovered by experimenting on Ansible Core/Base 2.11 and as stated in the Ansible documentation (same for version 2.9 and 2.10). The src parameter has to be a file. So if you want to copy a directory you have to use synchronize or rsync module (or put the directory in an archive and use the unarchive module as suggested on page 36). Hope this helps !
@MrPOC - In the documentation (latest version for copy module), it states for the src parameter:
If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied. This behavior is similar to the rsync command line tool.
You should be able to copy files or directories without issue (I still do this quite often for smaller directories).
For large directories, the operation is a bit faster with synchronize/rsync, though—see note in the same docs:
The
ansible.builtin.copymodule recursively copy facility does not scale to lots (>hundreds) of files.
Hello,
Indeed (I thought I checked the copy module documentation too but apparently I didn't), copy does work with folders but for some reason fetch doesn't. My bad.
Maybe you could mention this difference between the 2 modules, but it's not necessary as the documentation is quite clear about this. I just assumed the 2 modules could work with folders because both in the docs and in your book they are each presented as "like the other one but in reverse". I'll let you close this issue if you think it's not worth mentioning.
Ah true; I should probably be clear that fetch doesn't work quite the same as copy.