【问题标题】:Vagrant creating an incorrect client.pem on chef node (I think)Vagrant 在 Chef 节点上创建了不正确的 client.pem(我认为)
【发布时间】:2014-10-02 21:23:43
【问题描述】:

我正在使用 Vagrant 创建一个 chef 节点,它启动了图像,然后初始 chef-client 运行失败。当我 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 标记的完整日志。

【问题讨论】:

    标签: vagrant chef-infra vagrantfile vsphere


    【解决方案1】:

    你有两个问题发生

    /etc/chef/client.pem

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

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

    空运行列表

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

    【讨论】:

    • 我认为空运行列表是因为它失败了。但是,我非常确定我已经删除了基础映像上的 client.pem。我必须等待网络管理员明天再次打开它,以便我检查(呃)。
    • 看起来你可能是对的,我跑了vagrant up --no-provision,机器上确实有一个client.pem。我明天会破解它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-06
    • 2020-04-20
    • 1970-01-01
    • 2015-12-18
    • 2014-04-23
    • 2018-05-04
    • 1970-01-01
    相关资源
    最近更新 更多