ansible 使用copy模块
使用场景:将本地的文件或者目录,拷贝远程主机的文件或目录。
比如:将本地的hosts文件拷贝到远程的hosts文件。
命令:ansible 192.168.1.9 -m copy -a "src=/etc/hosts dest=/etc/hosts"
例子:
[root@server ansible]# ansible 192.168.1.9 -m copy -a "src=/etc/hosts dest=/etc/hosts"
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
192.168.1.9 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"checksum": "a0bbafbc864e6b78d31b05d2c29418277781da4b",
"dest": "/etc/hosts",
"gid": 0,
"group": "root",
"md5sum": "64ef5bbeeaa986f14d3f98e4b47a0a2d",
"mode": "0644",
"owner": "root",
"secontext": "system_u:object_r:net_conf_t:s0",
"size": 196,
"src": "/home/ansible/.ansible/tmp/ansible-tmp-1597488743.77-2981-273660008975974/source",
"state": "file",
"uid": 0
}
官方链接:https://docs.ansible.com/ansible/latest/modules/copy_module.html