如果我vboxmanage list hostonlyifs
在 shell 中运行,我会得到以下输出:
$ vboxmanage list hostonlyifs
Name: vboxnet0
GUID: 786f6276-656e-4074-8000-0a0027000000
DHCP: Disabled
IPAddress: 192.168.56.1
NetworkMask: 255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType: Ethernet
Wireless: No
Status: Down
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
这正是我所期望的:单一界面。
现在,如果我在 Ansible 剧本中运行完全相同的命令:
$ cat prepare_virtualbox.yml
- hosts: localhost
gather_facts: false
connection: local
tasks:
- name: check if the host only interface already exists
shell: vboxmanage list hostonlyifs
register: hostonlyifs
changed_when: false
$ ansible-playbook prepare_virtualbox.yml
PLAY [localhost] *****************************************************************
TASK [check if the host only interface already exists] ***************************
ok: [localhost]
PLAY RECAP ***********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
奇怪的事情发生了:创建了额外的主机专用接口!如果我vboxmanage list hostonlyifs
再次运行,它会列出三个接口:
$ vboxmanage list hostonlyifs
Name: vboxnet0
GUID: 786f6276-656e-4074-8000-0a0027000000
DHCP: Disabled
IPAddress: 192.168.56.1
NetworkMask: 255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType: Ethernet
Wireless: No
Status: Down
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
Name: vboxnet1
GUID: 786f6276-656e-4174-8000-0a0027000001
DHCP: Disabled
IPAddress: 192.168.57.1
NetworkMask: 255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:01
MediumType: Ethernet
Wireless: No
Status: Down
VBoxNetworkName: HostInterfaceNetworking-vboxnet1
Name: vboxnet2
GUID: 786f6276-656e-4274-8000-0a0027000002
DHCP: Disabled
IPAddress: 192.168.58.1
NetworkMask: 255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:02
MediumType: Ethernet
Wireless: No
Status: Down
VBoxNetworkName: HostInterfaceNetworking-vboxnet2
如果我再次运行剧本,则不会创建新的接口。但是,如果我删除上述三个中的任何一个(例如,删除vboxmanage hostonlyif remove vboxnet1
),则当我再次运行剧本时,它会重新创建。
什么原因导致这种情况发生?我该如何进一步排除故障?