我无法击败 Vagrant/VirtualBox 和 Ansible,请帮忙。这是我在 Vagrant 中的网络配置:
config.vm.define "mesosnode01" do |node1|
node1.vm.box = "ubuntu/trusty64"
node1.vm.hostname = "mesosnode01"
node1.vm.network "private_network", ip: "192.168.56.10"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "3072"]
end
end
我预计默认的 eth 设备会有192.168.56.10地址。但我错了。输出如下:
对于 IP 路由列表:
vagrant@mesosnode01:~$ sudo ip route list
default via 10.0.2.2 dev eth0
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.10
对于虚拟机端的 ifconfig:
vagrant@mesosnode01:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:84:06:a3
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe84:6a3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1922 errors:0 dropped:0 overruns:0 frame:0
TX packets:1247 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:191345 (191.3 KB) TX bytes:163962 (163.9 KB)
eth1 Link encap:Ethernet HWaddr 08:00:27:fc:bb:de
inet addr:192.168.56.10 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fefc:bbde/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:132 errors:0 dropped:0 overruns:0 frame:0
TX packets:91 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:109552 (109.5 KB) TX bytes:23202 (23.2 KB)
所以我的部分服务开始于10.0.2.15,另一部分按预期开始192.168.56.10。
问题是我的 Ansible 角色(取自 galaxy/github)使用ansible_default_ipv4并且它指向“错误”的接口。
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"10.0.2.15",
"192.168.56.10"
],
"ansible_default_ipv4": {
"address": "10.0.2.15",
"alias": "eth0",
"gateway": "10.0.2.2",
"interface": "eth0",
"macaddress": "08:00:27:84:06:a3",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "10.0.2.0",
"type": "ether"
},
我做错了什么?
答案1
请查看@techraf 的回答。我使用该答案中的信息创建了一个任务:
- name: set eth1 to default interface
shell: route add -net 8.8.8.8 netmask 255.255.255.255 eth1
when : ansible_default_ipv4.alias != "eth1"
此命令是幂等的,您可以根据需要多次运行它。