The fetch module is the same as the copy function, which is the file transfer between different machines, the former is pulling files from the node to the master machine (the machine with ansible), the latter is transferring files from the master to the node. The template module can insert variables into the copied file.
(Official document) the Copy module copies a file on the local box to remote locations. Use the Fetch module to copy files from remote locations to the local box. If you need variable interpolation with copied files, use the template module.
Common parameters:
SRC and dest are abbreviations for source and destination, ignoring.
Fail_on_missing=yes, if the source file does not exist, the task will fail.
The following command line illustrates:
1, #ansible hostname-m fetch-a "Src=/tmp/srcfile dest=/tmp/destdir"
Regardless of whether dest ends with "/", the path to the target file on the master machine is:/tmp/destdir/hostname/tmp/srcfile
2, #ansible hostname-m fetch-a "Src=/tmp/srcfile dest=/tmp/destdir/ Flag=yes"
Path to the destination file on the master:/tmp/destdir/srcfile
Run the operation on my own the following will be an error
#ansible hostname-m fetch-a "Src=/tmp/srcfile dest=/tmp/destdir flag=yes"
#ansible hostname-m fetch-a "src=/tmp/* dest=/tmp/destdir/flag=yes" I thought the files in the Src/tmp directory would be copied to the/tmp/destdir directory.
3, #ansible hostname-m fetch-a "Src=/tmp/srcfile dest=/tmp/destdir/12345 flag=yes"
The path to the destination file on the host computer:/tmp/destdir/12345 actually renamed the file (there was no Destdir directory on the console)
4, #ansible hostname-m fetch-a "Src=/tmp/srcfile dest=destdir/12345 flag=yes"
Path of the destination file on the master:/etc/ansible/destdir/12345 (relative to ansible master path)
This article is from the "11524698" blog, please be sure to keep this source http://11534698.blog.51cto.com/11524698/1826465
ansible files Module:fetch & copy & Template.....continuing