ansible的copy模块测试:
本地主机为m01,远程主机为web01.从m01拷贝文件到web01,本地m01情况:
[root@m01 rsync]# tree /test_dir/
/test_dir/
└── test_dir.txt
1、src是目录,dest是文件,报错,不允许这种情况:
[root@web01 tmp]# ll
总用量 0
-rw-r–r-- 1 root root 0 2月 12 12:36 test_dir.txt
用ll查看目的主机上存在test_dir.txt文件,执行ansible:
[root@m01 rsync]# ansible group2 -m copy -a “src=/test_dir dest=/tmp/test_dir.txt”
172.16.1.7 | FAILED! => {
“msg”: “Failed to get information on remote file (/tmp/test_dir.txt/test_dir/test_dir.txt): 不是目录”
}
2、src是目录,dest是目录 如果目的目录不存在,则自动创建:
[root@web01 tmp]# ll
总用量 0
-rw-r–r-- 1 root root 0 2月 12 12:36 test_dir.txt
用ll查看目的主机上/tmp下不存在test目录,执行ansible:
[root@m01 rsync]# ansible group2 -m copy -a “src=/test_dir dest=/tmp/test/”
在目的地的/tmp下原本没有/test目录存在&#x