[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 指定模塊的參數