hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.26k stars 4.43k forks source link

After Vagrant Desktop VMware update, box won't up/reload without manually clearing nat.conf incoming TCP each time #9716

Closed stephenvoisey closed 6 years ago

stephenvoisey commented 6 years ago

Do I win award for most descriptive title? šŸ˜€

So after updating to the new Vagrant Desktop VMware plugin, I ran into a series of issues, mainly with the port conflicting. It started with 8080 even though nothing was mapped to it and there was no PID to kill.

After a little googling I came across #8489

This wouldn't work until I destroyed my box and then vagrant up again, always having to go into nat.cf and removing the mapped ports as described in #8489.

Any help, much appreciated.

Vagrant version

2.0.4

Host operating system

10.13.4 High Sierra

Guest operating system

Ubuntu 16.04 from the latest Bento box

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Specify minimum Vagrant version and Vagrant API version
Vagrant.require_version ">= 2.0.2"
VAGRANTFILE_API_VERSION = "2"

# Require YAML module
require 'yaml'

# Setup different servers
servers = YAML.load_file('servers.yaml')

# Create boxes
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Iterate through entries in YAML file
  servers.each do |servers|
    config.vm.define servers["name"] do |srv|

      srv.vm.hostname = servers["name"]
      srv.vm.box = servers["box"]
      #srv.vm.network "private_network", type: "dhcp" #Let DHCP assign an IP
      srv.vm.network "private_network", ip: servers["ip"]
      if servers["guest_port"] # And may not be supported in this syntax. Multiple ports will need a for loop on array length.
        srv.vm.network "forwarded_port", guest: servers["guest_port"], host: servers["host_port"], auto_correct: true #, disabled: true # Added to test live reload, but long haul and not worth figuring out at the moment.
      end
      srv.vm.provider :vmware_fusion do |vb|
        vb.name = servers["name"]
        vb.vmx["memsize"] = servers["ram"]
        vb.vmx["numvcpus"] = servers["cpus"]
        # Fix symbolic links from not working in npm - Not sure if needed anymore thanks to Samba instead of NFS
        # vb.vmx["sharedFolder0.followSymlinks"] = "TRUE"
      end

      # Synced folders options, now SMB at long last! Yay! No more crappy NFS.
      # Old NFS version below if needed, but ideally not.
      #    srv.vm.synced_folder servers["hostfolder"], servers["vmfolder"],
      #            :type => "nfs",
      #            :nfs => true,
      #            :mount_options =>  ['nolock','vers=3','udp','noatime,actimeo=1'] #was what seemed to be best

      srv.vm.synced_folder servers["hostfolder"], servers["vmfolder"], owner: "serverpilot", group: "serverpilot",
            :type => "smb"

      # Fix for no tty error
      srv.vm.provision "fix-no-tty", type: "shell" do |s|
        s.privileged = false
        s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
      end
      # Call individual provision files
      srv.vm.provision :shell, :path => servers["provision_file"]
    end
  end
end

Also the Yaml file for reference.

---
- name: web
  box: bento/ubuntu-16.04
  ram: 512
  cpus: 1
  guest_port: 80
  host_port: 8080
  ip: 192.168.56.101 #was 192.168.55.13
  provision_file: "web_provision.sh"
  hostfolder: "/Users/Home/Sites/Compass"
  vmfolder: "/srv/users/serverpilot/apps/compassdev/public"

Please note, if you are using Homestead or a different Vagrantfile format, we may be unable to assist with your issue. Try to reproduce the issue using a vanilla Vagrantfile first.

What actually happened

Error I get the first time I run vagrant up --no-provision or reload --no-provision (And the no provision flag doesn't change the following issue, simply what I generally do)

Vagrant encountered an error while attempting to prune unused port forward entries:

Failed to start NAT service

Second time I run vagrant up

Some of the defined forwarded ports would collide with existing forwarded ports on VMware network devices. This can be due to existing Vagrant-managed VMware machines, or due to manually configured port forwarding with VMware. Please fix the following port collisions and try again:

2222

When I clear out the nat.conf incoming TCP vagrant will then up/reload but each time I want to do this, I have to manually clear the nat.conf incoming TCP settings. A bit of a drag!

Adding Auto correct to the ports in the vagrant file doesn't fix the issue.

Expected behavior

What should have happened?

Vagrant shouldn't have a port conflict as nothing is using the ports and simply ran.

References

8489

Lesvek commented 6 years ago

I've got the same problem with:

Host Operating System: Windows 8.1

Guest Operating System: Windows 7

chrisroberts commented 6 years ago

@stephenvoisey Hi there. Thanks for reporting the issue and my apologies for the problems. The underlying issue is the unexpected rewrite of the networking configuration file VMware uses causing Vagrant to lose track of ports. A new version of the Vagrant VMware utility has been released which resolves this issue by keeping an isolated global registry. Please upgrade the utility and do let me know if you still have any issue.

https://www.vagrantup.com/vmware/downloads.html

Cheers!

mpepping commented 6 years ago

@chrisroberts Was experiencing the same port conflict issue on macOS (10.13.4/High Sierra). Updating to Vagrant VMware utility 1.0.1 seems to resolved the issue in a consistent way.

Since this relatively new Vagrant VMware utility is an important part of using Vagrant with Fusion/Workstation: Are the release-notes published somewhere, and wouldn't it be nice if vagrant version (or something else) would also report on the Vagrant VMware utility version?

chrisroberts commented 6 years ago

@mpepping Hi!

Vagrant VMware Desktop Changelog: https://github.com/hashicorp/vagrant-plugin-changelog/blob/master/vagrant-vmware-desktop-changelog.md

Vagrant VMware Utility Changelog: https://github.com/hashicorp/vagrant-plugin-changelog/blob/master/vagrant-vmware-utility-changelog.md

The plugin will report on new versions of the utility when they are available. There was an issue with the utility check that was fixed in the last plugin update. Otherwise, the desktop plugin does report on availability of new desktop plugin versions, and new utility versions.

Cheers!

mpepping commented 6 years ago

@chrisroberts thanks for the link to the changelog repo!

lfolco commented 5 years ago

Is there a way to downgrade? I just updated vmware and the plugin and I'm getting this error. The changelog indicates that they "Optimize port forward pruning behavior" on the latest version, which seems to point to this issue.

stephenvoisey commented 5 years ago

It might be possible to downgrade to vagrant, pretty easy to remove. However removing VMware to downgrade is something of a nightmare. At least on Mac, there is no proper uninstalled. There are some details on VMwares site regarding files, but after failing to resolve it this way I ended up completely flattening my box and starting again.

lfolco commented 5 years ago

Is this an issue in the Vagrant plugin, though, or in Vmware?

lfolco commented 5 years ago

This issue is not fixed with the latest VMware utility.

fasmat commented 5 years ago

I'm still experiencing this issue on macOS 10.14.6 with vagrant 2.2.5, vagrant-vmware-desktop 2.0.3, vagrant-vmware-utility 1.0.7 and VMware 11.1.1. Every few days I have to manually edit the nat.conf file to resolve this issue.

stephenvoisey commented 5 years ago

I'm still experiencing this issue on macOS 10.14.6 with vagrant 2.2.5, vagrant-vmware-desktop 2.0.3, vagrant-vmware-utility 1.0.7 and VMware 11.1.1. Every few days I have to manually edit the nat.conf file to resolve this issue.

Yes, I've had lots of issues with Vagrant as well. I can't successfully create new boxes as web servers like I used to with Serverpilot. Connection is always refused. After a complete reinstall of MacOS 10.14.6. I am using VMware Fusion 10, because I refuse to keep paying upgrade licensing costs to both HashiCorp and VMware given all the issues Vagrant keeps having.

I'm now getting this same error again:

`Some of the defined forwarded ports would collide with existing forwarded ports on VMware network devices. This can be due to existing Vagrant-managed VMware machines, or due to manually configured port forwarding with VMware. Please fix the following port collisions and try again:

2222`

# vi: set ft=ruby :

# Specify minimum Vagrant version and Vagrant API version
Vagrant.require_version ">= 2.0.5"
VAGRANTFILE_API_VERSION = "2"

# Require YAML module
require 'yaml'

# Setup different servers
servers = YAML.load_file('servers.yaml')

# Create boxes
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Iterate through entries in YAML file
  servers.each do |servers|
    config.vm.define servers["name"] do |srv|
      srv.vm.hostname = servers["name"]
      srv.vm.box = servers["box"]
      srv.vm.network "private_network", ip: servers["ip"],  auto_correct: true
      if servers["guest_port"] & servers["host_port"]
        srv.vm.network "forwarded_port", guest: servers["guest_port"], host: servers["host_port"], auto_correct: true
      end
      srv.vm.provider :vmware_desktop do |vb|
        vb.vmx["memsize"] = servers["ram"]
        vb.vmx["numvcpus"] = servers["cpus"]
      end
      srv.vm.synced_folder servers["hostfolder"], servers["vmfolder"], owner: "serverpilot", group: "serverpilot",
            :type => "smb"
      # Fix for no tty error
      srv.vm.provision "fix-no-tty", type: "shell" do |s|
        s.privileged = false
        s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
      end
      # Call individual provision files
      srv.vm.provision :shell, :path => servers["provision_file"]
    end
  end
end

Yaml file:

- name: web
  box: bento/ubuntu-18.04
  ram: 512
  cpus: 1
  ip: 192.168.55.14
  provision_file: "web_provision.sh"
  hostfolder: "/Users/stephenvoisey/Sites/Echo"
  vmfolder: "/srv/users/serverpilot/apps/echo/public"
ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ā³. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.