Copy Module
The role of the copy module in Ansible is to copy the files on the ansible execution machine to the remote node.
The reverse operation of the fetch module.
Common module parameters
Name of parameter |
whether you must |
Default Value |
Options |
Description |
Src |
No |
|
|
The absolute path is required to locate the files on the machine that the ansible executes. If the copy is a folder, then the folder will be a whole copy, if the end is "/", then only the contents of the folder is passed. It all feels like rsync. |
Content |
No |
|
|
Used instead of SRC to copy the contents of the specified file to a remote file |
Dest |
Yes |
|
|
For locating files on a remote node, an absolute path is required. If SRC points to a folder, this parameter must also be a pointer to a folder |
Backup |
No |
No |
Yes/no |
Back up the original files on the remote node before copying. If anything happens, the original file can be used. |
Directory_mode |
No |
|
|
This parameter can only be used to copy folders, when this setting, the new files in the folder will be copied. And the old won't be copied. |
Follow |
No |
No |
Yes/no |
When there is a link in the copied folder, then there will be a link in the copy of the past. |
Force |
No |
Yes |
Yes/no |
The default is yes, overwriting remote files with different contents (possibly the same file name). If it is no, the file will not be copied, if the file is remotely |
Group |
No |
|
|
Set a group to have file permissions for copying to a remote node |
Mode |
No |
|
|
Equivalent to chmod, parameter can be "u+rwx or u=rw,g=r,o=r" |
Owner |
No |
|
|
Set the file permissions that a user has copied to the remote node |
Case
# Copy the/srv/myfiles/foo.conf file to the remote node/etc/foo.conf, and its owner is Foo, the group that owns it is Foo, and the permission is 0644- copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644 # as in the case above, the difference is just the way the permission is written- copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode= "u= Rw,g=r,o=r " # another permission notation copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo Group=foo Mode= "u+rw,g-wx,o-rwx" # Copy the/mine/ntp.conf to the remote node/etc/ntp.conf, and back up the/etc/ntp.conf of the remote node. - copy: src=/mine/ntp. conf dest=/etc/ntp. conf owner=root group=root mode= 644 Backup=yes
Common parameter return values
Name of parameter |
parameter Description |
return value |
return value type |
Sample Example |
Src |
Location on the ansible actuator |
Changed |
String |
/home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source |
Backup_file |
Back up the original file |
Changed and if Backup=yes |
String |
/path/to/[email protected]:09~ |
Uid |
After execution, the owner's ID |
Success |
Int |
100 |
Dest |
Destination directory or file for the remote node |
Success |
String |
/path/to/file.txt |
Checksum |
Checksum value after copying a file |
Success |
String |
6e642bb8dd5c2e027bf21dd923337cbb4214f827 |
Md5sum |
MD5 checksum value after copying a file |
When supported |
String |
2a5aeecc61dc98c4d780b14b330e3282 |
State |
Post-execution status |
Success |
String |
File |
Gid |
Group ID with folder, file after execution |
Success |
Int |
100 |
Mode |
Permissions for files after execution |
Success |
String |
0644 |
Owner |
Name of the file owner after execution |
Success |
String |
httpd |
Group |
Name of all groups after executing the file |
Success |
String |
httpd |
Size |
File size after execution |
Success |
Int |
1220 |
There's a lot of this module today, see? The next time there will be a simple case.
Ansible Series (9) Copy module