Ansible series (9) Copy Module
Copy Module
The role of the copy module in ansible is to copy the files on the ansible Execution Machine to a remote node.
The opposite operation of the fetch module.
Common module Parameters
Parameter Name |
Required? |
Default Value |
Option |
Description |
Src |
No |
|
|
The absolute path is used to locate the files on the machine where ansible runs. If a folder is copied, the folder will be copied as a whole. If the end is "/", only the contents in the folder will be taken into consideration. Everything feels like rsync |
Content |
No |
|
|
It is used to replace src and copy the content of a specified file to a remote file. |
Dest |
Yes |
|
|
Used to locate files on a remote node. An absolute path is required. If src points to a folder, this parameter must also point to a folder. |
Backup |
No |
No |
Yes/no |
Back up the original file on the remote node before copying it. In case of any exceptions, the original file can be used. |
Directory_mode |
No |
|
|
This parameter can only be used to copy folders. After this setting, new files in the folder will be copied. Old Ones won't be copied. |
Follow |
No |
No |
Yes/no |
If a link exists in the copied folder, the link will be copied. |
Force |
No |
Yes |
Yes/no |
The default value is yes, which overwrites files with different remote content (the file name may be the same ). If no, the file will not be copied. If this file is available remotely |
Group |
No |
|
|
Sets the permission for a group to copy files to a remote node. |
Mode |
No |
|
|
Equivalent to chmod, the parameter can be "u + rwx or u = rw, g = r, o = r" |
Owner |
No |
|
|
Sets the permission for a user to copy files to a remote node. |
Case
# Set/srv/myfiles/foo. copy the conf file to the remote node/etc/foo. conf, whose owner is foo, whose group is foo, and whose permission is 0644-copy: src =/srv/myfiles/foo. conf dest =/etc/foo. conf owner = foo group = foo mode = 0644 # the same as in the preceding case, the difference is just permission writing-copy: src =/srv/myfiles/foo. conf dest =/etc/foo. conf owner = foo group = foo mode = "u = rw, g = r, o = r" # Write another permission-copy: src =/srv/myfiles/foo. conf dest =/etc/foo. conf owner = foo group = foo mode = "u + rw, g-wx, o-rwx" # copy/mine/ntp. conf to remote section And back up/etc/ntp. conf on the remote node. -Copy: src =/mine/ntp. conf dest =/etc/ntp. conf owner = root group = root mode = 644 backup = yes
Common parameter return values
Parameter Name |
Parameter description |
Return Value |
Return Value Type |
Example |
src |
Location on ansible executor |
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/file.txt.2015-02-12@22:09~ |
uid |
After execution, the owner's ID |
success |
int |
100 |
dest |
Target directory or file of the remote node |
success |
string |
/path/to/file.txt |
checksum |
The checksum value after the file is copied. |
success |
string |
6e642bb8dd5c2e027bf21dd923337cbb4214f827 |
md5sum |
Md5 checksum value after the file is copied |
when supported |
string |
2a5aeecc61dc98c4d780b14b330e3282 |
state |
Status after execution |
success |
string |
file |
gid |
Group ID with folders and files after execution |
success |
int |
100 |
mode |
Permission for the file after execution |
success |
string |
0644 |
owner |
Name of the file owner after execution |
success |
string |
httpd |
group |
Names of all groups in the file after execution |
success |
string |
httpd |
size |
File size after execution |
success |
int |
1220 |