|
ansible copy模块用来文件复制,说明如下:
参数名
| 选项 | 必须 | 参数说明 | backup | yes/no | no | 备份远程节点上的原始文件,在拷贝之前。如果发生什么意外,原始文件还能使用。 | content | yes/no | no | 用来替代src,用于将指定文件的内容,拷贝到远程文件内 | dest | yes/no | yes | 用于定位远程节点上的文件,需要绝对路径。如果src指向的是文件夹,这个参数也必须是指向文件夹 | directory_mode | yes/no | no | 这个参数只能用于拷贝文件夹时候,这个设定后,文件夹内新建的文件会被拷贝。而老旧的不会被拷贝 | follow | yes/no | no | 当拷贝的文件夹内有link存在的时候,那么拷贝过去的也会有link | group | yes/no | no | 指明文件属组 | mode | yes/no | no | 指明文件的权限 | owner | yes/no | no | 指明文件的属主 | src | yes/no | no | 文件源地址路径 | 1.1.默认参数的copy
1
2
| # cat ckl.txt
test ansible copy hahaha
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # ansible dbserver -m copy -a "src=/root/ckl.txt dest=/tmp"
172.16.110.49 | SUCCESS => {
"changed": true,
"checksum": "59e20a4c2f703fda1093edf341529fe15605de1a",
"dest": "/tmp/ckl.txt",
"gid": 0,
"group": "root",
"md5sum": "fad3a2bf27ada6056e6fdad913a88f0f",
"mode": "0644",
"owner": "root",
"size": 25,
"src": "/root/.ansible/tmp/ansible-tmp-1482912542.33-134291331324238/source",
"state": "file",
"uid": 0
}
|
查看远端结果:
1
2
3
| # ansible dbserver -a "cat /tmp/ckl.txt"
172.16.110.49 | SUCCESS | rc=0 >>
test ansible copy hahaha
|
1.2.参数backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # ansible dbserver -m copy -a "src=/root/ckl.txt dest=/root backup=yes"
172.16.110.49 | SUCCESS => {
"changed": true,
"checksum": "59e20a4c2f703fda1093edf341529fe15605de1a",
"dest": "/root/ckl.txt",
"gid": 0,
"group": "root",
"md5sum": "fad3a2bf27ada6056e6fdad913a88f0f",
"mode": "0644",
"owner": "root",
"size": 25,
"src": "/root/.ansible/tmp/ansible-tmp-1482912889.69-220399140870876/source",
"state": "file",
"uid": 0
}
|
1.3.参数content
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # ansible dbserver -m copy -a "content='we are from....' dest=/tmp/kk.txt"
172.16.110.49 | SUCCESS => {
"changed": true,
"checksum": "23f76aac2040c30a7bdaf4b899a133e5fafe4580",
"dest": "/tmp/kk.txt",
"gid": 0,
"group": "root",
"md5sum": "087a2fb23f1cc9c978eb6e6d4107e7ab",
"mode": "0644",
"owner": "root",
"size": 15,
"src": "/root/.ansible/tmp/ansible-tmp-1482914368.54-47626273459925/source",
"state": "file",
"uid": 0
}
|
1
2
3
| # ansible dbserver -a "cat /tmp/kk.txt"
172.16.110.49 | SUCCESS | rc=0 >>
we are from....
|
1.4.参数follow,owner,group,mode
源文件:
1
2
3
4
| # ll /root/ckl
total 4
lrwxrwxrwx 1 root root 8 Dec 28 03:42 f1 -> /data/fm
-rw-r--r-- 1 root root 12 Dec 28 03:49 md.txt
|
执行复制:
1
2
3
4
5
6
| # ansible dbserver -m copy -a "src=/root/ckl/ dest=/tmp/sk owner='ckl' group='ckl' mode=640 follow=yes"
172.16.110.49 | SUCCESS => {
"changed": true,
"dest": "/tmp/sk/",
"src": "/root/ckl"
}
|
查看文件(follow加不加好像没区别):
1
2
3
4
| # ll sk/
total 0
-rw-r--r-- 1 root root 0 Dec 28 03:45 f1
-rw-r--r-- 1 root root 0 Dec 28 03:45 md.txt
|
|
|
|