2

我正在尝试为厨师零提供一个流浪者盒子。当我运行vagrant up myboxname它时,它会在 Chef URL 上出现 404 错误并退出并出现错误。如果我然后运行vagrant provision myboxname它成功。本地厨师服务器的启动是否存在某种延迟,并且需要在 vagrant 配置中以某种方式满足?我在两次运行中都没有找到一个对象,但是第二次运行,为什么会发生这种情况?

流浪文件:

Vagrant.configure("2") do |config|
  config.chef_zero.enabled = true
  config.chef_zero.environments = "./environments/_default.json"
  config.chef_zero.data_bags = "./data_bags/"
  config.chef_zero.roles = "./roles/"

  config.vm.define "myboxname" do |machine|
    machine.chef_zero.cookbooks = ["./cookbooks/mycookbook/"]
    machine.chef_zero.log_level = "debug"
    machine.vm.provider "virtualbox" do |vbox|
      vbox.name = "myboxname"
    end
    machine.vm.provision :chef_zero do |chef|
      chef.data_bags_path = "./data_bags/"
      chef.run_list = ['recipe[mycookbook::default]']
    end
  end
end

其他信息:

$ vagrant version
Installed Version: 1.7.4
$ vagrant plugin list
vagrant-chef-zero (1.0.1)
vagrant-share (1.1.4, system)

运行,例如使用 trusty64:

$ vagrant up myboxname
Bringing machine 'myboxname' up with 'virtualbox' provider...
==> myboxname: Importing base box 'ubuntu/trusty64'...
==> myboxname: Setting the name of the VM: myboxname
<virtualbox init stuff>
==> myboxname: Running 'pre-boot' VM customizations...
==> myboxname: Booting VM...
==> myboxname: Waiting for machine to boot. This may take a few minutes...
    myboxname: SSH address: 127.0.0.1:2222
    myboxname: SSH username: vagrant
    myboxname: SSH auth method: private key
    myboxname: Inserting generated public key within guest...
==> myboxname: Machine booted and ready!
==> myboxname: Checking for guest additions in VM...
==> myboxname: Configuring and enabling network interfaces...
==> myboxname: Mounting shared folders...
    myboxname: /vagrant => /path/to/my/chef-repo
    myboxname: /tmp/vagrant-chef/8d6a2619e17bfa48a2eba11cea21e6c6/cookbooks => /path/to/my/chef-repo/cookbooks
==> myboxname: Running provisioner: chef_zero...
    myboxname: Installing Chef (latest)...
Generating chef JSON and uploading...
==> myboxname: Running chef-client (local-mode)...
==> myboxname: [2015-08-26T06:26:24+00:00] INFO: Started chef-zero at chefzero://localhost:8889 with repository at /tmp/vagrant-chef/8d6a2619e17bfa48a2eba11cea21e6c6, /tmp/vagrant-chef/cookbooks
==> myboxname:   One version per cookbook
==> myboxname:   data_bags at /tmp/vagrant-chef/d63293c35eb5900ffff1cf7d76ac6fdd/data_bags
==> myboxname: [2015-08-26T06:26:24+00:00] INFO: Forking chef instance to converge...
==> myboxname: Starting Chef Client, version 12.4.1
==> myboxname: [2015-08-26T06:26:24+00:00] INFO: *** Chef 12.4.1 ***
==> myboxname: [2015-08-26T06:26:24+00:00] INFO: Chef-client pid: 3080
==> myboxname: [2015-08-26T06:26:25+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: chefzero://localhost:8889/nodes/vagrant-ubuntu-trusty-64
==> myboxname: [2015-08-26T06:26:25+00:00] ERROR: #<Errno::ENOENT: No such file or directory @ dir_s_mkdir - /tmp/vagrant-chef/cookbooks/nodes>
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:97:in `mkdir'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:97:in `block in create_child'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:95:in `each'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:95:in `create_child'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/chef_fs_data_store.rb:469:in `get_dir'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/chef_fs_data_store.rb:456:in `with_dir'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/chef_fs_data_store.rb:123:in `create'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/data_store/v1_to_v2_adapter.rb:34:in `block in create'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/data_store/v1_to_v2_adapter.rb:113:in `fix_exceptions'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/data_store/v1_to_v2_adapter.rb:33:in `create'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/rest_base.rb:150:in `create_data'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/endpoints/rest_list_endpoint.rb:31:in `post'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/rest_base.rb:30:in `call'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/rest_router.rb:24:in `call'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/server.rb:589:in `block in app'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/server.rb:305:in `call'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/server.rb:305:in `handle_socketless_request'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/socketless_server_map.rb:87:in `request'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/socketless_server_map.rb:33:in `request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http/socketless_chef_zero_client.rb:153:in `request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:266:in `block in send_http_request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:298:in `block in retrying_http_errors'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:296:in `loop'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:296:in `retrying_http_errors'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:260:in `send_http_request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:143:in `request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:126:in `post'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/node.rb:545:in `create'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/node.rb:506:in `rescue in find_or_create'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/node.rb:502:in `find_or_create'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/policy_builder/expand_node_object.rb:106:in `load_node'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/client.rb:443:in `load_node'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/client.rb:255:in `run'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:270:in `block in fork_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:258:in `fork'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:258:in `fork_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:224:in `block in run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/local_mode.rb:39:in `with_server_connectivity'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:212:in `run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:402:in `block in interval_run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:392:in `loop'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:392:in `interval_run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:382:in `run_application'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:60:in `run'
==> myboxname: /opt/chef/embedded/apps/chef/bin/chef-client:26:in `<top (required)>'
==> myboxname: /usr/bin/chef-client:55:in `load'
==> myboxname: /usr/bin/chef-client:55:in `<main>'
==> myboxname: [2015-08-26T06:26:25+00:00] INFO: HTTP Request Returned 500 Internal Server Error: error
==> myboxname: ================================================================================
==> myboxname: Chef encountered an error attempting to load the node data for "vagrant-ubuntu-trusty-64"
==> myboxname: ================================================================================
==> myboxname: Unknown Server Error:
==> myboxname: ---------------------
==> myboxname: The server had a fatal error attempting to load the node data.
==> myboxname: Server Response:
==> myboxname: ----------------
==> myboxname: Exception raised!  #<Errno::ENOENT: No such file or directory @ dir_s_mkdir - /tmp/vagrant-chef/cookbooks/nodes>
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:97:in `mkdir'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:97:in `block in create_child'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:95:in `each'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb:95:in `create_child'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/chef_fs_data_store.rb:469:in `get_dir'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/chef_fs_data_store.rb:456:in `with_dir'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/chef_fs/chef_fs_data_store.rb:123:in `create'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/data_store/v1_to_v2_adapter.rb:34:in `block in create'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/data_store/v1_to_v2_adapter.rb:113:in `fix_exceptions'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/data_store/v1_to_v2_adapter.rb:33:in `create'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/rest_base.rb:150:in `create_data'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/endpoints/rest_list_endpoint.rb:31:in `post'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/rest_base.rb:30:in `call'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/rest_router.rb:24:in `call'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/server.rb:589:in `block in app'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/server.rb:305:in `call'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/server.rb:305:in `handle_socketless_request'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/socketless_server_map.rb:87:in `request'
==> myboxname: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-zero-4.2.3/lib/chef_zero/socketless_server_map.rb:33:in `request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http/socketless_chef_zero_client.rb:153:in `request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:266:in `block in send_http_request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:298:in `block in retrying_http_errors'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:296:in `loop'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:296:in `retrying_http_errors'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:260:in `send_http_request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:143:in `request'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/http.rb:126:in `post'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/node.rb:545:in `create'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/node.rb:506:in `rescue in find_or_create'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/node.rb:502:in `find_or_create'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/policy_builder/expand_node_object.rb:106:in `load_node'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/client.rb:443:in `load_node'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/client.rb:255:in `run'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:270:in `block in fork_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:258:in `fork'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:258:in `fork_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:224:in `block in run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/local_mode.rb:39:in `with_server_connectivity'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:212:in `run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:402:in `block in interval_run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:392:in `loop'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:392:in `interval_run_chef_client'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:382:in `run_application'
==> myboxname: /opt/chef/embedded/apps/chef/lib/chef/application.rb:60:in `run'
==> myboxname: /opt/chef/embedded/apps/chef/bin/chef-client:26:in `<top (required)>'
==> myboxname: /usr/bin/chef-client:55:in `load'
==> myboxname: /usr/bin/chef-client:55:in `<main>'

然后立即运行vagrant provision myboxname(我总结了日志)

$ vagrant provision myboxname
==> myboxname: Running provisioner: chef_zero...
==> myboxname: Detected Chef (latest) is already installed
Generating chef JSON and uploading...
==> myboxname: Running chef-client (local-mode)...
==> myboxname: [2015-08-24T11:13:02+00:00] INFO: Started chef-zero at chefzero://localhost:8889 with repository at /tmp/vagrant-chef/8d6a2619e17bfa48a2eba11cea21e6c6, /tmp/vagrant-chef/cookbooks
==> myboxname:   One version per cookbook
==> myboxname: [2015-08-24T11:13:02+00:00] INFO: Forking chef instance to converge...
==> myboxname: Starting Chef Client, version 12.4.1
==> myboxname: [2015-08-24T11:13:02+00:00] INFO: *** Chef 12.4.1 ***
==> myboxname: [2015-08-24T11:13:02+00:00] INFO: Chef-client pid: 3457
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: chefzero://localhost:8889/nodes/vagrant-ubuntu-trusty-64
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: Setting the run_list to ["recipe[mycookbook::default]"] from CLI options
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: Run List is [recipe[mycookbook::default]]
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: Run List expands to [mycookbook::default]
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: Starting Chef Run for vagrant-ubuntu-trusty-64
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: Running start handlers
==> myboxname: [2015-08-24T11:13:03+00:00] INFO: Start handlers complete.
==> myboxname: resolving cookbooks for run list: ["mycookbook::default"]
==> myboxname: [2015-08-24T11:13:12+00:00] INFO: Loading cookbooks [mycookbook@0.1.0]
==> myboxname: Synchronizing Cookbooks:
==> myboxname: [2015-08-24T11:13:20+00:00] INFO: Storing updated cookbooks/mycookbook/README.md in the cache.
==> myboxname: [2015-08-24T11:13:20+00:00] INFO: Storing updated cookbooks/mycookbook/recipes/default.rb in the cache.
==> myboxname: [2015-08-24T11:13:20+00:00] INFO: Storing updated cookbooks/mycookbook/CHANGELOG.md in the cache.
<more INFO storing messages>
==> myboxname: Compiling Cookbooks...
==> myboxname: Recipe: mycookbook::default
<compile stuff>
==> myboxname: Converging X resources
<converge stuff>
<successful chef run>
4

2 回答 2

2

这似乎与 vagrant bug有关。

对我有用的解决方法是将此行放在主厨供应商上方Vagrantfile

config.vm.provision :shell, inline: 'mkdir -p /tmp/vagrant-chef/cookbooks/nodes'
于 2015-10-30T20:58:05.827 回答
1

不是一个明确的答案,因为我仍然不确定某些观点。

引用关于环境的文档(重点是我的)

environments_path(字符串)- 环境定义所在的路径。默认情况下,未设置环境文件夹。

environment(字符串)- 您希望 Chef 运行的环境成为其中的一部分。这需要 Chef 11.6.0 或更高版本,并且设置了 environment_path。

并从您的实际文件中猜测,我会像这样编写 vagrantfile:

Vagrant.configure("2") do |config|
  # config.chef_zero.enabled = true # I see no use of this, sounds not an available property for chef_zero provider
  # I'm unsure this works, I would move them in the provision block.
  config.chef_zero.environments_path = "./environments/" # Define where the environments files are, not the file itself
  config.chef_zero.environment = "_default" # the default env (should match the name attribute in the _default.json file IIRC.
  config.chef_zero.data_bags_path = "./data_bags/" # added _path to the property name
  config.chef_zero.roles_path = "./roles/" # same as above

  config.vm.define "myboxname" do |machine|
    machine.vm.provider "virtualbox" do |vbox|
      vbox.name = "myboxname"
    end
    machine.vm.provision :chef_zero do |chef|
      # Removed the data_bags_path as it's already defined config wise, but could be overridden here for a machine.
      chef.log_level = "debug" # moved into the provision block, I can't see how it could work on the machine level (and your log seems to confirm this as there's no debug entry in the log)
      chef.cookbooks_path = "./cookbooks/" # don't give the path to the cookbook, just give the path where the cookbook is 
      chef.run_list = ['recipe[mycookbook::default]']
    end
  end
end
于 2015-08-26T07:55:13.053 回答