ansile模块之copy
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansile模块之copy相关的知识,希望对你有一定的参考价值。
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
# cat ckl.txt test ansible copy hahaha
# 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 }
查看远端结果:
# ansible dbserver -a "cat /tmp/ckl.txt" 172.16.110.49 | SUCCESS | rc=0 >> test ansible copy hahaha
1.2.参数backup
# 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
# 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 }
# ansible dbserver -a "cat /tmp/kk.txt" 172.16.110.49 | SUCCESS | rc=0 >> we are from....
1.4.参数follow,owner,group,mode
源文件:
# 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
执行复制:
# 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加不加好像没区别):
# 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
本文出自 “深呼吸再出击” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1886992
以上是关于ansile模块之copy的主要内容,如果未能解决你的问题,请参考以下文章