Vagrant vsphere - 未定义的方法`[]'为nil:NilClass

时间:2014-10-02 21:44:17

标签: vagrant vagrantfile vsphere

这是一个非常奇怪的heisenbug。有时,在致电vagrant up时,我会得到类似的结果:

Bringing machine 'default' up with 'vsphere' provider...
==> default: Calling vSphere CloneVM with the following settings:
==> default:  -- Template VM: COLUMBIA/vm/DirectChannel/vagrantchefnode
==> default:  -- Target VM: COLUMBIA/vm/DirectChannel/dirchantsrv1
==> default: Waiting for SSH to become available...
undefined method `[]' for nil:NilClass

(我完全忘记了最后一行的样子,我正在尝试从使用--debug标签运行的日志中重新创建它。)

在我设置了Vagrantfiles之后,它第一次就这样做了,然后在vagrant destroy之后,正确地通过它而没有任何问题。有一次我让它每次都这样做,所以我将调试输出发送到日志文件。然后我编辑了Vagrantfile并停止了。然后我将Vagrant文​​件编辑回原来的状态,但仍然没有再发生。我需要知道是什么导致它,以便我可以确保它不会再次发生。

以下是日志文件中包含“nil”的行:

DEBUG command:  -- options: {:provider=>nil}
 INFO batch_action: Starting action: #<Vagrant::Machine:0x000000018bb658> up {:destroy_on_error=>true, :parallel=>true, :provision_ignore_sentinel=>false, :provision_types=>nil}
 INFO machine: New machine ID: nil
ERROR warden: Error occurred: undefined method `[]' for nil:NilClass
ERROR warden: Error occurred: undefined method `[]' for nil:NilClass
ERROR warden: Error occurred: undefined method `[]' for nil:NilClass
ERROR warden: Error occurred: undefined method `[]' for nil:NilClass
ERROR vagrant: #<VagrantPlugins::VSphere::Errors::VSphereError: undefined method `[]' for nil:NilClass>
ERROR vagrant: undefined method `[]' for nil:NilClass
 INFO interface: error: undefined method `[]' for nil:NilClass
undefined method `[]' for nil:NilClass
 INFO interface: Machine: error-exit ["VagrantPlugins::VSphere::Errors::VSphereError", "undefined method `[]' for nil:NilClass"]

以下是Vagrantfiles:

1)随包装盒打包的Vagrantfile:

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

Vagrant.configure("2") do |config|
  config.vm.provider :vsphere do |vsphere|
    vsphere.host = 'vsphereserver.myorg.com'
    vsphere.compute_resource_name = 'TestDev'
    vsphere.user = 'vagrantadmin'
    vsphere.password = 'password'
    vsphere.insecure = true
  end

  config.ssh.username = 'auto'
  config.ssh.private_key_path = '~/.vagrant.d/id_rsa'
end

2)我的主目录中的Vagrantfile(〜/ .vagrant.d):

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

Vagrant.configure("2") do |config|
  config.vm.box = 'vsphere'

  config.vm.provider :vsphere do |vsphere|
    vsphere.template_name = 'vagrantchefnode'
  end

  config.vm.provision "chef_client", id: "chef" do |chef|
    chef.provisioning_path = "/etc/chef"
    chef.chef_server_url = "https://chefserver.myorg.com"
    chef.validation_key_path = "/home/user/.vagrant.d/chef/validation.pem"
#    chef.client_key_path = "/etc/chef/client.pem"
    chef.validation_client_name = "chef-validator"
    chef.custom_config_path = "/home/user/.vagrant.d/Vagrantfile.chef"
    chef.delete_node = true
    chef.delete_client = true
    chef.add_role "base"
  end
end

3)项目目录中的Vagrantfile(〜/ .vagrant.d / boxes / chefnode1):

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

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

  config.vm.provider :vsphere do |vsphere|
#    vsphere.template_name = 'chefnode'
    vsphere.customization_spec_name = 'test2'
    vsphere.name = 'test2'
  end

  config.vm.provision "chef_client", id: "chef" do |chef|
    chef.node_name = "test2"
    chef.add_role "dev"
  end
end

在VMware方面,我觉得有些事情出了问题,但我没有对VMware主机的完全访问权限。有什么想法吗?

0 个答案:

没有答案