【ansible】playbook 主机变量1
hosts 配置后可以支持指定 端口,密码等其他变量
[root@10_1_162_39 host_vars]# ll total 12 -rw-r--r-- 1 root root 236 May 5 09:11 hosts -rw-r--r-- 1 root root 205 May 4 21:08 test1.yaml -rw-r--r-- 1 root root 146 May 5 09:09 test.playbook [root@10_1_162_39 host_vars]# cat hosts [web] 10.1.167.36 [web:vars] ansible_ssh_port=32200 [web1] 10.1.167.18 [web1:vars] ansible_ssh_port=322 [test] 10.1.162.18 ansible_ssh_port=322 ansible_ssh_pass=test*
10.1.167.36 ansible_ssh_port=32200 ansible_ssh_pass=test***
[root@10_1_162_39 host_vars]# cat test.playbook --- - hosts: test gather_facts: false remote_user: root tasks: - shell: ifconfig register: output - debug: var=output.stdout
[root@10_1_162_39 host_vars]# ansible-playbook test.playbook -i hosts PLAY [test] ******************************************************************** TASK [command] ***************************************************************** changed: [10.1.162.18] changed: [10.1.167.36] TASK [debug] ******************************************************************* ok: [10.1.167.36] => { "output.stdout": "eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500\n inet 192.168.142.129 netmask 255.255.255.0 broadcast 192.168.142.255\n inet6 fe80::20c:29ff:fe9e:335f prefixlen 64 scopeid 0x20<link>\n ether 00:0c:29:9e:33:5f txqueuelen 1000 (Ethernet)\n RX packets 32739 bytes 2492311 (2.3 MiB)\n RX errors 0 dropped 0 overruns 0 frame 0\n TX packets 1943 bytes 231372 (225.9 KiB)\n TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0\n\nlo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536\n inet 127.0.0.1 netmask 255.0.0.0\n inet6 ::1 prefixlen 128 scopeid 0x10<host>\n loop txqueuelen 1 (Local Loopback)\n RX packets 4 bytes 340 (340.0 B)\n RX errors 0 dropped 0 overruns 0 frame 0\n TX packets 4 bytes 340 (340.0 B)\n TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0\n\nvirbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500\n inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255\n ether 52:54:00:2b:6f:35 txqueuelen 1000 (Ethernet)\n RX packets 0 bytes 0 (0.0 B)\n RX errors 0 dropped 0 overruns 0 frame 0\n TX packets 0 bytes 0 (0.0 B)\n TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0" } ok: [10.1.162.18] => { "output.stdout": "eth0 Link encap:Ethernet HWaddr 00:0C:29:21:BD:17 \n inet addr:192.168.238.129 Bcast:192.168.238.255 Mask:255.255.255.0\n inet6 addr: fe80::20c:29ff:fe21:bd17/64 Scope:Link\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:299606 errors:0 dropped:0 overruns:0 frame:0\n TX packets:120969 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000 \n RX bytes:363277194 (346.4 MiB) TX bytes:6698174 (6.3 MiB)\n Interrupt:19 Base address:0x2000 \n\nlo Link encap:Local Loopback \n inet addr:127.0.0.1 Mask:255.0.0.0\n inet6 addr: ::1/128 Scope:Host\n UP LOOPBACK RUNNING MTU:65536 Metric:1\n RX packets:8 errors:0 dropped:0 overruns:0 frame:0\n TX packets:8 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:0 \n RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)" } PLAY RECAP ********************************************************************* 10.1.162.18 : ok=2 changed=1 unreachable=0 failed=0 10.1.167.36 : ok=2 changed=1 unreachable=0 failed=0 [root@10_1_162_39 host_vars]#