首先我得到的错误是:

There are errors in the configuration of this machine. Please fix
the following errors and try again:

chef client provisioner:
* Chef server URL must be populated.
* Validation key path must be valid path to your chef server validation key.

chef服务器url似乎已填充,并且验证密钥路径有效。
我已经有3个流浪者文件生效了,我正在使用documentation试图得到正确的顺序。
当我将所有内容都粘贴到项目目录中的一个Vagrantfile中时,这很好,但我希望设置默认值,而不必复制粘贴所有内容。
1)随箱包装的流浪档案:
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.provider :vsphere do |vsphere|
    vsphere.host = 'vsphereserver.example.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)我的主目录中的流浪者文件(~/.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" do |chef|
    chef.add_role "base"
    chef.provisioning_path = "/etc/chef"
    chef.chef_server_url = "https://chefserver.example.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
  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 = 'chefnode1'
    vsphere.name = 'chefnode1'
  end

  config.vm.provision "chef_client" do |chef|
    chef.node_name = "chefnode1"
    chef.add_role "test"
  end

end

它是否以某种方式覆盖了整个chef_客户端配置如果是这样的话,我该如何让它像预期的那样粘在一起?
更新:
我有一些东西在处理Tejay的答案和this doc,但是它需要翻译成不同的语法,我不知道如何翻译像add_role这样的方法我得到的是:
2个)
  config.vm.provision "chef_client",
    id: "chef",
    provisioning_path: "/etc/chef",
    chef_server_url: "https://chefserver.example.com",
    validation_key_path: "/home/user/.vagrant.d/chef/validation.pem",
    client_key_path: "/etc/chef/client.pem",
    validation_client_name: "chef-validator",
    custom_config_path: "/home/user/.vagrant.d/Vagrantfile.chef",
    delete_node: true,
    delete_client: true

三)
  config.vm.provision "chef_client",
    id: "chef",
    node_name: "chefnode1"

所以这会启动机器,但我不能指定运行列表。

最佳答案

实际上,您正在创建两个provisioner,每个文件中一个,因此项目目录中的provisioner没有url或验证密钥。Vavrand的文档说明,为了修改现有的提供者,需要使用id。查看此页上的“重写PROVISIONER设置”部分:
https://docs.vagrantup.com/v2/provisioning/basic_usage.html
所以试试这个(未测试):
我家目录中的流浪者文件(~/.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: 'someID') do |chef|
    chef.add_role "base"
    chef.provisioning_path = "/etc/chef"
    chef.chef_server_url = "https://chefserver.example.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
  end
end

项目目录中的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 = 'chefnode1'
    vsphere.name = 'chefnode1'
  end

  config.vm.provision("chef_client", id: 'someID') do |chef|
    chef.node_name = "chefnode1"
    chef.add_role "test"
  end
end

关于ruby - Vagrant显然未正确合并Vagrantfile,Chef配置丢失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26152306/

10-16 00:41