2

Chef is really confusing me. Can you help me understand why it's not working?

Cliff Notes

  • I'm using Chef-Solo (not Berkshelf or anything else)
  • Everything works when I set it up from scratch, I can vagrant provision
  • But if I reboot the HOST (My main operating system) it breaks!
  • It appears to be looking inside a .chef folder which I did not specify in my vagrant configuration.
  • I have to do a vmboxmanage box destroy ubuntu/trusty64 and redownload everything and redo vagrant up if I reboot.
  • Vagrant Version 1.7.2
  • Virtual Box Version 4.3.20r96996

Inside Vagrant SSH Error:

Note: The files are not pointing to the .chef folder, but they are here?

[2015-01-30T16:23:44+00:00] WARN: Did not find config file: 
/etc/chef/solo.rb, using command line options.

[2015-01-30T16:23:50+00:00] FATAL: None of the cookbook paths set in
Chef::Config[:cookbook_path], 
["/vagrant/.chef/cookbooks", "/vagrant/.chef/site-cookbooks"], 
contain any cookbooks

$vagrant up and $ vagrant provision error:

==> default: Mounting shared folders...
default: /vagrant => /home/jesse/if/indieflix/vagrant
default: /home/vagrant/chef-recipes => /home/jesse/projects/if/vagrant/chef-recipes
default: /home/vagrant/chef-resources => /home/jesse/projects/if/vagrant/chef-resources

==> default: Running provisioner: chef_solo...
==> default: Detected Chef (latest) is already installed
Shared folders that Chef requires are missing on the virtual machine.
This is usually due to configuration changing after already booting the
machine. The fix is to run a `vagrant reload` so that the proper shared
folders will be prepared and mounted on the VM.

And, vagrant reload does nothing.

Vagrantfile

# ...
config.vm.synced_folder "chef-recipes", "/vagrant/chef-recipes"
config.vm.synced_folder "chef-resources", "/vagrant/chef-resources"
# ...
config.vm.provision "chef_solo" do |chef|
    # Relevant to the Vagrantfile path
    chef.cookbooks_path = ["chef-recipes"]

    # This is just required by Chef, so it's minimal
    chef.environments_path = "chef-resources/environments"

    # This is the internal flag.
    chef.environment = "development"

    # This defines the cookbooks to run
    chef.roles_path = "chef-resources/roles"
    chef.add_role("development")
end

Folder Structure

chef-recipes/    (Git Submodule)
----python/
--------recipes/
------------default.rb
------------pip.rb
chef-resouces/   (Git Submodule)
----environments/
--------development.json
----roles/
--------development.json
Vagranfile
JREAM
  • 5,741
  • 11
  • 46
  • 84
  • 1
    When you reboot the host ? which host ? the vm or the host machine ? Could it be the reference of the machine in virtualbox changed after reboot ? – Tensibai Jan 30 '15 at 16:52
  • If I reboot the OS/Physical Computer (Linux), My Guest is Linux also for Vagrant. The Guest (Virtualbox/Vagrant) doesn't seem to work after a reboot. – JREAM Jan 30 '15 at 17:02
  • 1
    I'm not sure, but I suspect the id stored in the .vagrant directory for the machine is not the id of the guest in virtualbox after the reboot, that's why vagrant can't mount the shared folder with vagrant reload. You should restart the VM via vagrant after a reboot (with `vagrant up`, it will search the vm and power it on, getting the new id and mounting the correct folders I think) – Tensibai Jan 30 '15 at 17:05
  • I will add that: I can `vagrant ssh` into `/vagrant/chef-recipes` and see everything though. Does that make sense? I am not sure why its trying to look for `/vagrant/.chef/chef-recipes` though. Am I required to have a `solo.rb` file? – JREAM Jan 30 '15 at 17:08
  • 1
    When you do a vagrant provision, it will generate a solo.rb file, a json file and some other things and then run chef-solo with some parameters. When you simply run chef-solo at command line it will search the default config file which is not there as vagrant does not create it. I'm not using chef-solo so I may be wrong, but the path seems to be: `vagrant up; vagrant reload; vagrant provision` (maybe the up is not needed) But you have to let vagrant mount the shared folder and manage the chef run, or you'll have to mimic it in the ssh session. – Tensibai Jan 30 '15 at 17:12
  • I think since I'm not using Omnibus but rather a install script `sudo curl -L https://www.opscode.com/chef/install.sh | bash` which runs once -- the following has to be made 'sudo ln -s /vagrant/environments/ /var/chef/environments' I'll try a reboot now. – JREAM Jan 30 '15 at 17:34
  • Rats, it didn't fix it. – JREAM Jan 30 '15 at 17:38
  • Okay so I added `$ vagrant plugin install vagrant-omnibus` and removed the `curl | bash installation` of chef. This appears to fix it at this juncture. Thanks fo much for your comments Tensibai I upvoted them :) – JREAM Jan 31 '15 at 00:34
  • Glad it has helped you ;) – Tensibai Jan 31 '15 at 10:13
  • 1
    I want to add if anyone encounters this problem it appears there is a bug in Chef-Solo/Vagrant with mounting files on the Host. The only workaround I have found is: `rm .vagrant/machines/default/virtualbox/synced_folders vagrant reload --provision` – JREAM Feb 02 '15 at 18:25
  • 1
    @JREAM Your comment is the answer. I suggest you should answer your own question and accept that as the answer. It will help other fellow SOers – Anthony Kong Feb 26 '15 at 23:49
  • @AnthonyKong Good idea! I did it! – JREAM Feb 27 '15 at 04:46

1 Answers1

4

Anthony suggested in a comment I answer my question since it was answered in comments. Here it is!

Instead of using curl to install, I used omnibus which adds another step before provisioning:

$ vagrant plugin install vagrant-omnibus 

Second, Chef-Solo/Vagrant has an issue with mounting files from the Host. The only workaround I have found is:

$ rm .vagrant/machines/default/virtualbox/synced_folders vagrant reload --provision 

Optional: I created a bash script to make the above a little quicker:

reprovision.sh

#/bin/bash
rm .vagrant/machines/default/virtualbox/synced_folders
vagrant reload --provision

And of course chmod +x reprovision.sh and to run ./reprovision.sh

JREAM
  • 5,741
  • 11
  • 46
  • 84