我正在使用 Vagrant 创建一个厨师节点,它会启动图像,然后初始厨师客户端运行失败。当我 ssh 进入机器,删除/etc/chef/client.pem
并sudo chef-client
再次运行时,它成功了,但是没有我从 vagrant 传入的 run_list。这是失败的样子:
$ vagrant up
Bringing machine 'default' up with 'vsphere' provider...
==> default: Calling vSphere CloneVM with the following settings:
==> default: -- Template VM: myOrg/vm/myFolder/vagrantchefnode
==> default: -- Target VM: myOrg/vm/myFolder/test2
==> default: Waiting for SSH to become available...
==> default: New virtual machine successfully cloned and started
==> default: Rsyncing folder: /home/user/.vagrant.d/boxes/test2/ => /vagrant
==> default: Running provisioner: chef_client...
==> default: Creating folder to hold client key...
==> default: Uploading chef client validation key...
Generating chef JSON and uploading...
==> default: Running chef-client...
==> default: stdin: is not a tty
==> default: [2014-10-02T16:11:19-05:00] INFO: Forking chef instance to converge...
==> default: [2014-10-02T16:11:19-05:00] INFO: *** Chef 11.16.2 ***
==> default: [2014-10-02T16:11:19-05:00] INFO: Chef-client pid: 6080
==> default: [2014-10-02T16:11:21-05:00] INFO: HTTP Request Returned 401 Unauthorized: error
==> default: Failed to authenticate to the chef server (http 401).
==> default: Failed to authenticate as 'test2'. Ensure that your node_name and client key are correct.
==> default: chef_server_url "https://server.myorg.com"
==> default: node_name "test2"
==> default: client_key "/etc/chef/client.pem"
这些是我的 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) 我的主目录 (~/.vagrant.d) 中的 Vagrantfile:
# -*- 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
我尝试在第二个 Vagrantfile 中取消注释 chef.client_key_path,但没有任何效果。当我将所有内容都放在一个 Vagrantfile 中时,这似乎工作得很好,但是我想运行多台机器而不将所有设置复制到每个 Vagrantfile 中。
如果有人想要的话,我有一个带有 --debug 标签的完整日志。