[root@ha ~]# ls
anaconda-ks.cfg ansible har1.sh har.sh install.log install.log.syslog purge_relay_logs.sh shell
[root@ha ~]# cd ansible/
[root@ha ansible]# ls
book host
[root@ha ansible]# pwd
/root/ansible
[root@ha ansible]# ls
book host
[root@ha ansible]#
我的host主机 和play-book是在单独的地方 机器列表如下
[root@ha host]# cat test
[test1]
192.168.1.63
192.168.1.76
[test2]
192.168.1.13
192.168.1.16
[root@ha host]# ansible -i /root/ansible/host/test test1 -a "ifconfig"
192.168.1.63 | success | rc=0 >>
eth0 Link encap:Ethernet HWaddr 52:54:00:C7:7D:D5
inet addr:192.168.1.63 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fec7:7dd5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31277966 errors:0 dropped:238 overruns:0 frame:0
TX packets:5102819 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2491034144 (2.3 GiB) TX bytes:413723846 (394.5 MiB)
Interrupt:11 Base address:0xe000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1265363 errors:0 dropped:0 overruns:0 frame:0
TX packets:1265363 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:109943239 (104.8 MiB) TX bytes:109943239 (104.8 MiB)
192.168.1.76 | success | rc=0 >>
eth0 Link encap:Ethernet HWaddr 52:54:00:58:F9:DB
inet addr:192.168.1.76 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe58:f9db/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3300490 errors:0 dropped:0 overruns:0 frame:0
TX packets:374887 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:381618281 (363.9 MiB) TX bytes:88607956 (84.5 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5075999 errors:0 dropped:0 overruns:0 frame:0
TX packets:5075999 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:299373104 (285.5 MiB) TX bytes:299373104 (285.5 MiB)
i:指定 inventory 文件 我是使用的自己的host文件。默认情况下是在/etc/ansible/host下。我的好像是源码安装的 木有这个路径。
all:针对 hosts 定义的所有主机执行,这里也可以指定组名或模式 这里我用的test1组
-m:指定所用的模块,我们这里没有指定,以为默认的是command模块
-u:指定远端机器的用户
-a 指定模块的参数
本文出自 “迎接喜洋洋” 博客,谢绝转载!
原文:http://ghnhl.blog.51cto.com/1630025/1598924