0

我正在使用 Vagrant 创建一个厨师节点,它会启动图像,然后初始厨师客户端运行失败。当我 ssh 进入机器,删除/etc/chef/client.pemsudo 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 标签的完整日志。

4

1 回答 1

4

你有两个问题正在发生

/etc/chef/client.pem

听起来您的基本映像已经存在一个/etc/chef/client.pem文件,该文件将无法进行身份验证。您需要从基本映像中删除它,以便在首次运行时使用 chef 创建一个新节点/客户端。

或者(但我不建议这样做),您可以在主厨客户端配置器之前使用外壳配置器,然后将其删除。缺点是每次调用 vagrant provision 都会导致尝试使用 chef-server 创建客户端。

空运行列表

至于run-list的变化,当一个新的chef节点被创建时,它的runlist只有在chef run成功的情况下才会被保存。由于失败,您的 chef-server 没有存储运行列表。然后,当您直接登录并运行 chef-client 时,它会向服务器询问您的运行列表,该运行列表不存在,因此您运行了一个空的运行列表。

于 2014-10-02T21:36:59.353 回答