2

I am trying to provision a vagrant box with Chef Zero. When I run vagrant up myboxname it fails with a 404 error on the Chef URL and exits with an error. If I then run vagrant provision myboxname it succeeds. Is there some sort of delay for the local chef server to start up, and needs to be catered for somehow in the vagrant config? I get an object not found in both runs, but the 2nd works, why would this be happening?

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

Other info:

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

The run, for example with 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>'

And then immediately after that, I run vagrant provision myboxname (i've summarized logs)

$ 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>
Brett
  • 5,690
  • 6
  • 36
  • 63
  • You may instruct chef to run in debug logging mode to have more details on what's done under the hood by adding a `machine.chef_zero.log_level = "debug"` in your vagrant file [more in this doc](http://docs.vagrantup.com/v2/provisioning/chef_common.html) – Tensibai Aug 24 '15 at 16:29
  • And I don't get how your vagrant provision command can know which run list to give to your node as there's no `provision`block in your vagrant file, did you strip things from you vagrant file while posting here ? I can't find any `enabled` or `cookbooks` property for [chef_zero](https://docs.vagrantup.com/v2/provisioning/chef_zero.html) in vagrant documentation. – Tensibai Aug 24 '15 at 16:40
  • You're right @Tensibai I cut out a whole lot of stuff to give the pertinent info, but left out the provision block. Have added it in now. – Brett Aug 25 '15 at 12:54
  • 1
    I'm pretty sure you can shed some light (and improve your question so we don't have to use divination skills) by reading my two comments with more attention (I mean, use log level, give what's above the error in the question, explain why you're using undefined properties, etc.) – Tensibai Aug 25 '15 at 13:02
  • Didn't have a chance to re-run vagrant yesterday. I have added `log_level` and added the full output from `Running chef-client (local-mode)...` line on the first run. chef_zero.enable is now set to true at a `config` level and `cookbooks` are shown. Vagrantfile and 1st run output have been updated to reflect changes. – Brett Aug 26 '15 at 06:42
  • Seems to be an open bug in Vagrant: https://github.com/mitchellh/vagrant/issues/6110 – Torben Knerr Sep 20 '15 at 22:46

2 Answers2

2

This appears to be related to a vagrant bug.

A workaround that works for me is to place this line above the chef provisioner in Vagrantfile:

config.vm.provision :shell, inline: 'mkdir -p /tmp/vagrant-chef/cookbooks/nodes'
phs
  • 10,687
  • 4
  • 58
  • 84
1

Not a definitive answer as I'm still unsure of some points.

Quoting the doc about environment (emphasis is mine)

environments_path (string) - A path where environment definitions are located. By default, no environments folder is set.

environment (string) - The environment you want the Chef run to be a part of. This requires Chef 11.6.0 or later, and that environments_path is set.

and guessing from your actual file I would write the vagrantfile like this:

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
Tensibai
  • 15,557
  • 1
  • 37
  • 57