Vagrant с Chef Zero завершается неудачно при начальном запуске, но успешно с последующим предоставлением

Я пытаюсь снабдить бродячую коробку шеф-поваром Зеро. Когда я бегу vagrant up myboxname он завершается с ошибкой 404 по URL-адресу Chef и завершается с ошибкой. Если я тогда бегу vagrant provision myboxname это успешно. Есть ли какая-то задержка для запуска локального сервера chef, и его необходимо каким-то образом учесть в конфигурации vagrant? Я получаю объект, не найденный в обоих прогонах, но 2-й работает, с чего бы это случилось?

Vagrantfile:

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>

2 ответа

Похоже, это связано с бродячей ошибкой.

Обходной путь, который мне подходит, - поместить эту строку над шеф-поваром в Vagrantfile:

config.vm.provision :shell, inline: 'mkdir -p /tmp/vagrant-chef/cookbooks/nodes'

Не точный ответ, так как я до сих пор не уверен в некоторых моментах.

Цитирую документ об окружающей среде (акцент мой)

environments_path (строка) - путь, в котором находятся определения среды. По умолчанию папка окружений не установлена.

environment (строка) - Среда, частью которой вы хотите управлять. Для этого требуется 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
Другие вопросы по тегам