hashicorp / vagrant

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

Vagrant hanging during chef-client runs with windows guests #8265

Closed axos88 closed 7 years ago

axos88 commented 7 years ago

When using vagrant with the chef-zero provisioner, during the provisioning of a windows guest, the provisioning hangs around 20-30% of the time during the "resolving dependencies" phase.

This never happens when vagrant is out of the picture, so I'm pretty confident something is up with Vagrant itself.

After the hang, the vagrant does not clean up (when stopped with CTRL+C), and it seems that there is a powershell process on the guest that hangs. Stopping that service (whenever windows lets us to) makes the vagrant clean up. I have a suspicion that something is up with filesharing, and that may cause the process to hang on I/O maybe?

We usually try working around the issue by reload --provision-ing, but this a pretty bad workaround.

Vagrant version

1.8.6

Host operating system

Windows & Linux

Guest operating system

Windows

Vagrantfile


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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.

def host_memory
  host = RbConfig::CONFIG['host_os']

  if host =~ /darwin/
    # sysctl returns Bytes and we need to convert to MB
    `sysctl -n hw.memsize`.to_i / 1024
  elsif host =~ /linux/
    # meminfo shows KB and we need to convert to MB
    `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i
  elsif host =~ /mswin|mingw|cygwin/
    # Windows code via https://github.com/rdsubhas/vagrant-faster
    `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i / 1024
  end
end

Vagrant.configure("2") do |config|

  config.vm.box = "mwrock/Windows2012R2"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  config.vm.box_check_update = true

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.

  [443, 80, 4443, 3210, 40777, 4848, 8181, 9009].each do |port|
    config.vm.network "forwarded_port", guest: port, host: 10000 + port
  end

  config.vm.boot_timeout = 600

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "sync", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    vb.gui = true

    #4GB, but 1/3 of total memory max
    vb.memory = [4096, host_memory / 1024 / 3].min
  end

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  config.ssh.forward_agent = true
  config.berkshelf.enabled = true if Vagrant.has_plugin?("vagrant-berkshelf")

  unless Vagrant.has_plugin?("vagrant-berkshelf")
    puts "Executing berks vendor..."
    system('berks vendor')
    puts "Done."
  end

  config.vm.provision "chef_zero" do |chef|
    # Specify the local paths where Chef data is stored
    chef.node_name = "localhost"

    chef.cookbooks_path = ["berks-cookbooks"] unless Vagrant.has_plugin?("vagrant-berkshelf")
    chef.nodes_path = "vagrant-nodes"
    chef.roles_path = ["../chef-kitchen/roles", "vagrant-roles"]
    chef.environments_path = "../chef-kitchen/environments"
    # chef.log_level = "debug"

    chef.add_role "vagrant"
  end

end

### Debug output

### Expected behavior

Should not hang

### Actual behavior

Hangs about 20-30% of the time

### Steps to reproduce

1. vagrant provision

### References
chrisroberts commented 7 years ago

Hi there. Please provide the --debug output of a vagrant provision that hangs so we can better attempt to determine the root cause. Thanks!

axos88 commented 7 years ago

Will do, as soon as it occurs again

chrisroberts commented 7 years ago

Hey there,

I am going to close this due to lack of response. If this is still occurring, please open a new issue and follow the provided issue template that appears when you click the "New Issue" button. This will help us in getting a reproduction and fix. Thanks! 😄

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.