diff --git a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb index 0abf5ab4e..2ee5e9c54 100644 --- a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb +++ b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb @@ -36,18 +36,27 @@ 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 - dynamic_machine_ip = read_dynamic_machine_ip(adapter) + adapter, host_ip = find_host_only_adapter + machine_ip = read_static_machine_ips - if machine_ip.nil? - # If there were no static IPs, attempt to use the dynamic IP - # instead. - machine_ip = dynamic_machine_ip + if !machine_ip + # No static IP, attempt to use the dynamic IP. + machine_ip = read_dynamic_machine_ip(adapter) 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? + # We have static IPs, also attempt to read any dynamic IPs. + # If there is no dynamic IP on the adapter, it doesn't matter. We + # already have a static IP. + begin + dynamic_ip = read_dynamic_machine_ip(adapter) + rescue Vagrant::Errors::NFSNoGuestIP + dynamic_ip = nil + end + + # If we found a dynamic IP and we didn't include it in the + # machine_ip array yet, do so. + if dynamic_ip && !machine_ip.include?(dynamic_ip) + machine_ip.push(dynamic_ip) + end end raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip