[root@ansible ~]# vim hosts[ceshii]192.168.6.141[docker]192.168.6.142
常用模块
shell模块
[root@ansible ~]# ansible -i hosts docker -m shell -a "ifconfig ens33 | grep inet "
192.168.6.142 | SUCCESS | rc=0 >>
inet 192.168.6.142 netmask 255.255.255.0 broadcast 192.168.6.255
inet6 fe80::20c:29ff:fe4a:d6e4 prefixlen 64 scopeid 0x20<link>
copy模块
[root@ansible ~]# ansible -i hosts docker -m copy -a "src=/etc/hostname dest=/tmp/hosts"
192.168.6.142 | SUCCESS => {
"changed": true,
"checksum": "e63dddd358e9693e876f838bf17984a6680a5a0f",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "d32760b1ceec24f0b67e97665d36ac22",
"mode": "0644",
"owner": "root",
"size": 8,
"src": "/root/.ansible/tmp/ansible-tmp-1501433058.73-181136839498261/source",
"state": "file",
"uid": 0
}
file模块
[root@ansible ~]# ansible -i hosts docker -m file -a "dest=/tmp/hosts mode=777"
192.168.6.142 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"path": "/tmp/hosts",
"size": 8,
"state": "file",
"uid": 0
}
yum 模块
[root@ansible ~]# ansible -i hosts docker -m yum -a "name=lrzsz state=present"
192.168.6.142 | SUCCESS => {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"lrzsz-0.12.20-36.el7.x86_64 providing lrzsz is already installed"
]
}
user模块
[root@ansible ~]# ansible -i hosts docker -m user -a "name=user comment='I am user ' uid=1040 group=root"
192.168.6.142 | SUCCESS => {
"changed": true,
"comment": "I am user ",
"createhome": true,
"group": 0,
"home": "/home/user",
"name": "user",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1040
}
service模块
[root@ansible ~]# ansible -i hosts docker -m service -a "name=network state=restarted"
192.168.6.142 | SUCCESS => {
"changed": true,
"name": "network",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Sun 2017-07-30 21:16:21 CST",
"ActiveEnterTimestampMonotonic": "35036536",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
等等模块,自行探索