我正在使用Vagrant创建一个厨师节点,它会旋转图像然后初始的厨师 - 客户端运行失败。当我进入机器时,删除/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)我的主目录中的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
我已尝试取消注释第二个Vagrantfile中的chef.client_key_path,但没有效果。当我在一个Vagrantfile中拥有它时,这似乎工作正常,但我想运行多台机器而不将所有设置复制到每个Vagrantfile中。
我有一个带有--debug标记的完整日志,如果有人想要的话。
答案 0 :(得分:4)
你有两个问题正在进行中
听起来您的基本图像已经存在/etc/chef/client.pem
文件,无法进行身份验证。您需要从基本映像中删除它,以便在首次运行时使用chef创建新节点/客户端。
或者(但我不建议),您可以在Chef-client provisioner之前使用shell配置程序,然后将其删除。缺点是每次调用vagrant配置都会导致尝试使用chef-server创建客户端。
对于运行列表更改,当创建新的Chef节点时,只有在Chef运行成功时才会保存其运行列表。由于失败,您的厨师服务器没有存储运行列表。当您直接登录并运行chef-client时,它会向服务器询问您的运行列表,该运行列表不存在,因此您运行了一个空的运行列表。