ansible模块--copy模块

网友投稿 766 2022-10-10

ansible模块--copy模块

ansible模块--copy模块

将主控端的文件复制到远程主机,只针对文件src 源文件路径dest 目标文件路径content 将指定内容覆盖写入到目标主机文件中force=no 当主控端拷贝的文件名和目标名一致,但是内容不一致,放弃拷贝force=yes 当主控端拷贝的文件名和目标名一致,但是内容不一致,则进行覆盖backup=yes 当主控端拷贝的文件名和目标名一致,但是内容不一致,则进行备份

1.将源文件,copy到被控端

[root@ansible ~]# ansible mysql -m copy -a 'src=/root/test.sh dest=/tmp/test.sh'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "checksum": "fef3362b2569d5051aacfc796f94b9361ed17501", "dest": "/tmp/test.sh", "gid": 0, "group": "root", "md5sum": "fffb69482b3210a71d551f6a55229669", "mode": "0644", "owner": "root", "size": 26, "src": "/root/.ansible/tmp/ansible-tmp-1636858197.78-2717-153122870288434/source", "state": "file", "uid": 0}

2.将指定内容覆盖到被控端文件内

[root@ansible ~]# ansible mysql -m copy -a "content='This is just a test' dest=/tmp/test.sh"192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "checksum": "7265cdc53d4a78743e5b09d9a842e85d54fe5b44", "dest": "/tmp/test.sh", "gid": 0, "group": "root", "md5sum": "df0a9498a65ca6e20dc58022267f339a", "mode": "0644", "owner": "root", "size": 19, "src": "/root/.ansible/tmp/ansible-tmp-1636858416.25-2753-247910343979913/source", "state": "file", "uid": 0}

3.将文件发送到被控端,如果内容不同则进行备份,并覆盖

[root@ansible ~]# ansible mysql -m copy -a "src=/root/test.sh dest=/tmp/test.sh backup=yes"192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "backup_file": "/tmp/test.sh.4331.2021-11-14@11:05:53~", "changed": true, "checksum": "fef3362b2569d5051aacfc796f94b9361ed17501", "dest": "/tmp/test.sh", "gid": 0, "group": "root", "md5sum": "fffb69482b3210a71d551f6a55229669", "mode": "0644", "owner": "root", "size": 26, "src": "/root/.ansible/tmp/ansible-tmp-1636859151.74-2813-22864520776498/source", "state": "file", "uid": 0}[root@ansible ~]# ansible mysql -m shell -a "ls /tmp/test*"192.168.56.88 | CHANGED | rc=0 >>/tmp/test.sh/tmp/test.sh.4331.2021-11-14@11:05:53~

4.拷贝过程中修改属主权限参数owner 属主group 属组mode 权限

[root@ansible ~]# ansible mysql -m copy -a "src=/root/test.sh dest=/tmp/test.sh owner=mysql group=mysql mode=666"192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "checksum": "fef3362b2569d5051aacfc796f94b9361ed17501", "dest": "/tmp/test.sh", "gid": 1000, "group": "mysql", "mode": "0666", "owner": "mysql", "path": "/tmp/test.sh", "size": 26, "state": "file", "uid": 1000}应该看到copy过去的文件属主也已经改了。[root@ansible ~]# ansible mysql -m shell -a "ls -l /tmp/test*"192.168.56.88 | CHANGED | rc=0 >>-rw-rw-rw- 1 mysql mysql 26 Nov 14 11:05 /tmp/test.sh-rw-r--r-- 1 root root 19 Nov 14 10:53 /tmp/test.sh.4331.2021-11-14@11:05:53~

ansible

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:eweapp- ECShop 非官方版微信小程序商城(eweapp下载)
下一篇:微信小程序-GetWeApp金盆洗脚城[全栈]
相关文章

 发表评论

暂时没有评论,来抢沙发吧~