diff --git a/lib/vagrant-hostsupdater/HostsUpdater.rb b/lib/vagrant-hostsupdater/HostsUpdater.rb index 45ec37a..1f9f21c 100644 --- a/lib/vagrant-hostsupdater/HostsUpdater.rb +++ b/lib/vagrant-hostsupdater/HostsUpdater.rb @@ -7,7 +7,7 @@ def getIps ips = [] @machine.config.vm.networks.each do |network| key, options = network[0], network[1] - ip = options[:ip] if key == :private_network + ip = options[:ip] if key == :private_network || key == :public_network ips.push(ip) if ip end return ips @@ -75,7 +75,7 @@ def getHostEntries(ip, hostnames, name, uuid = self.uuid) def addToHosts(entries) return if entries.length == 0 content = entries.join("\n").strip - if !File.writable?(@@hosts_path) + if !File.writable_real?(@@hosts_path) sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path')) else content = "\n" + content @@ -88,7 +88,7 @@ def addToHosts(entries) def removeFromHosts(options = {}) uuid = @machine.id || @machine.config.hostsupdater.id hashedId = Digest::MD5.hexdigest(uuid) - if !File.writable?(@@hosts_path) + if !File.writable_real?(@@hosts_path) sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path)) else hosts = ""