企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
常用参数: src:源 content= 取代src 表示直接用此处执行的信息copy到远程文件中 dest:目录(必须要使用绝对路径) mode: 权限 owner: 属主 group: 属主 follow: 如果复制里是链接,我们就会把链接后的文件拷贝到目标 案例:拷贝文件 ~~~ [admin@node1 ansible]$ ansible webserver -m copy -a "src='/etc/fstab' dest='/tmp' mode='600'" ~~~ 查看 ~~~ [admin@node1 ansible]$ ansible webserver -m shell -a "ls -l /tmp|grep fstab" 192.168.20.138 | SUCCESS | rc=0 >> -rw-------. 1 admin admin 465 Mar 17 15:28 fstab 192.168.20.137 | SUCCESS | rc=0 >> -rw-------. 1 admin admin 465 Mar 17 15:29 fstab ~~~ 案例2: 拷贝目录 ~~~ [admin@node1 scripts]$ ansible webserver -m copy -a "src='/server/scripts' dest='/server' mode='644' owner='admin'" -b --ask-sudo-pass [DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature will be removed in version 2.6. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. SUDO password: 192.168.20.138 | SUCCESS => { "changed": true, "dest": "/server/", "src": "/server/scripts" } 192.168.20.137 | SUCCESS => { "changed": true, "dest": "/server/", "src": "/server/scripts" } [admin@node1 scripts]$ ansible webserver -a "ls -l /server" 192.168.20.138 | SUCCESS | rc=0 >> total 0 drwxr-xr-x. 2 admin root 46 Mar 17 15:48 scripts 192.168.20.137 | SUCCESS | rc=0 >> total 0 drwxr-xr-x. 2 admin root 46 Mar 17 15:48 scripts [admin@node1 scripts]$ ansible webserver -a "ls -l /server/" 192.168.20.138 | SUCCESS | rc=0 >> total 0 drwxr-xr-x. 2 admin root 46 Mar 17 15:48 scripts 192.168.20.137 | SUCCESS | rc=0 >> total 0 drwxr-xr-x. 2 admin root 46 Mar 17 15:48 scripts [admin@node1 scripts]$ ansible webserver -a "ls -l /server/scripts" 192.168.20.138 | SUCCESS | rc=0 >> total 12 -rw-r--r--. 1 admin root 465 Mar 17 15:48 fstab -rw-r--r--. 1 admin root 23 Mar 17 15:48 issue -rw-r--r--. 1 admin root 1037 Mar 17 15:48 passwd 192.168.20.137 | SUCCESS | rc=0 >> total 12 -rw-r--r--. 1 admin root 465 Mar 17 15:48 fstab -rw-r--r--. 1 admin root 23 Mar 17 15:48 issue -rw-r--r--. 1 admin root 1037 Mar 17 15:48 passwd ~~~ ~~~ [admin@node1 ~]$ ansible webserver -m copy -a 'src="/app/pet/" dest="/app/web" owner=admin group=root' -b -K SUDO password: 192.168.52.132 | SUCCESS => { "changed": true, "dest": "/app/web/", "src": "/app/pet/" } 192.168.52.130 | SUCCESS => { "changed": true, "dest": "/app/web/", "src": "/app/pet/" } 192.168.52.131 | SUCCESS => { "changed": true, "dest": "/app/web/", "src": "/app/pet/" } [admin@node1 ~]$ ansible webserver -m copy -a 'src="/app/pet/" dest="/app/web" owner=admin group=root' -b -K SUDO password: 192.168.52.130 | SUCCESS => { "changed": false, "dest": "/app/web/", "src": "/app/pet/" } 192.168.52.132 | SUCCESS => { "changed": false, "dest": "/app/web/", "src": "/app/pet/" } 192.168.52.131 | SUCCESS => { "changed": false, "dest": "/app/web/", "src": "/app/pet/" } ~~~