From ed708645b2129c3ce83e90a81a8828db9b9558ba Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Thu, 5 May 2016 14:41:03 +0100 Subject: [PATCH] prepare_nfs_settings: Try harder to get all machine IPs. Vagrant was not behaving correctly in configurations where there was a static IP on a VirtualBox `intnet` interface and a DHCP `:hostonly` interface configured. Since `machine_ip` attempted to get static addresses `||` dynamic addresses, it would simply use the static machine address and continue. This commit corrects this behaviour by collecting all static and dynamic addresses into the `machine_ip` array instead of just one or the other. The result of this is a correctly generated `/etc/exports` on the host machine, allowing NFS mounts to work correctly in this type of environment. --- .../virtualbox/action/prepare_nfs_settings.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb index d3edf3e93..0abf5ab4e 100644 --- a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb +++ b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb @@ -36,8 +36,19 @@ module VagrantPlugins # # The ! indicates that this method modifies its argument. def add_ips_to_env!(env) - adapter, host_ip = find_host_only_adapter - machine_ip = read_static_machine_ips || read_dynamic_machine_ip(adapter) + adapter, host_ip = find_host_only_adapter + machine_ip = read_static_machine_ips + dynamic_machine_ip = read_dynamic_machine_ip(adapter) + + if machine_ip.nil? + # If there were no static IPs, attempt to use the dynamic IP + # instead. + machine_ip = dynamic_machine_ip + else + # If we did get some static machine IPs, add the dynamic IPs to + # that list too. + machine_ip.push(dynamic_machine_ip) unless dynamic_machine_ip.nil? + end raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip