|
ansible testhost -m copy -a “src=/etc/ansible dest=/tmp/ansibletestowner=root group=root mode=0644”
注意:源目录会放到目标目录下面去,如果目标指定的目录不存在,它会自动创建。如果拷贝的是文件,dest指定的名字和源如果不同,并且它不是已经存在的目录,相当于拷贝过去后又重命名。但相反,如果test是目标机器上已经存在的目录,则会直接把文件拷贝到该目录下面。
ansible testhost -m copy -a "src=/etc/passwd dest=/tmp/123"
这里的/tmp/123和源机器上的/etc/passwd是一致的,但如果目标机器上已经有/tmp/123目录,则会再/tmp/123目录下面建立passwd文件
直接运行做测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| [iyunv@web9 ~]# ansible web10.gz.com -m copy -a "src=/etc/passwd dest=/tmp/1.txt"
web10.gz.com | SUCCESS => {
"changed": true,
"checksum": "94c290ba39362aba4abe1b85ad4ede97672f610e",
"dest": "/tmp/1.txt",
"gid": 0,
"group": "root",
"md5sum": "091e5f5feb9291cbcb88ebf4fcff530e",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 1273,
"src": "/root/.ansible/tmp/ansible-tmp-1461259050.78-90862552472962/source",
"state": "file",
"uid": 0
}
[iyunv@web9 ~]# ansible testhosts -m copy -a "src=/etc/ansible dest=/tmp/ansibletestowner=root group=root mode=0644"
web10.gz.com | SUCCESS => {
"changed": true,
"dest": "/tmp/ansibletestowner=root/",
"src": "/etc/ansible"
}
172.7.15.111 | SUCCESS => {
"changed": true,
"dest": "/tmp/ansibletestowner=root/",
"src": "/etc/ansible"
}
127.0.0.1 | SUCCESS => {
"changed": true,
"dest": "/tmp/ansibletestowner=root/",
"src": "/etc/ansible"
}
|
如发现以下问题,先在目标机器上安装一个包就哦了
1
2
3
4
5
6
7
8
9
| [iyunv@web9 ~]# ansible web10.gz.com -m copy -a "src=/etc/passwd dest=/tmp/1.txt"
web10.gz.com | FAILED! => {
"changed": false,
"checksum": "94c290ba39362aba4abe1b85ad4ede97672f610e",
"failed": true,
"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"
}
[iyunv@web10 ~]# yum install -y libselinux-python
|
在web10上查看刚刚创建的文件
1
2
| [iyunv@web10 ~]# ls -lt /tmp/1.txt
-rw-r--r--. 1 root root 1273 4月 22 01:17 /tmp/1.txt
|
如果绿色表示执行成功,红色是有问题的。
|
|
|