nsidc / vagrant-vsphere

VMware vSphere provider for Vagrant
Other
607 stars 166 forks source link

Password prompt after setting it in the environment #207

Open ggascoigne opened 8 years ago

ggascoigne commented 8 years ago

We had a Vagrantfile that configured a VM using the vsphere plugin. It would boot the VM correctly, but every time we tried to access it, run a status or destroy it, we’d get asked for the VSphere password, the same one that was already in the environment. More to the point, entering the correct password then resulted in an error.

The root of the problem is an odd misconfiguration in the Vagrantfile.

The broken version:

Vagrant.configure(2) do |config|
  config.vm.define 'centos' do |node|
    config.vm.provider :vsphere do |vsphere, override|
      override.vm.box = 'perf-centos7-x64-patched'
      vsphere.memory_mb = 2048
      vsphere.cpu_count = 1
    end
  end
end

And the fixed version:

Vagrant.configure(2) do |config|
  config.vm.define 'centos' do |node|
    node.vm.provider :vsphere do |vsphere, override|
      override.vm.box = 'perf-centos7-x64-patched'
      vsphere.memory_mb = 2048
      vsphere.cpu_count = 1
    end
  end
end

The difference is on the third line.

In the first the global config variable is used, in the second the scoped node variable is used. That’s it.

I've got to assume that this is a plugin bug where the wrong value is being resolved.

ghost commented 8 years ago

I don't think I've worked with config.vm.define before.

Does it work if you do that configuration outside of the machine-specific block?

Vagrant.configure(2) do |config|
  config.vm.provider :vsphere do |vsphere, override|
    override.vm.box = 'perf-centos7-x64-patched'
    vsphere.memory_mb = 2048
    vsphere.cpu_count = 1
  end

  config.vm.define 'centos' do |node|
  end
end

The Vagrant docs on multiple machines do say you can continue to use the config object, but they don't have any examples where they use the config object inside of a config.vm.define block.