chef-client cannot find cookbooks using berkshelf

have_a_question picture have_a_question · Oct 25, 2014 · Viewed 8k times · Source

I'm new to chef and ran into problems with berkshelf and chef-client. I want to have my own cookbook with dependencies and apply it. My initial cookbook looks like this:

.
├── Berksfile
├── Berksfile.lock
├── chefignore
├── client.rb
├── Gemfile
├── Gemfile.lock
├── metadata.rb
├── README.md
└── recipes
    └── default.rb

#./Berksfile
source 'https://supermarket.getchef.com'

metadata

cookbook 'znc'


#./client.rb
cookbook_path '~/.berkshelf/cookbooks'

and when I run sudo bundle exec chef-client -z -o znc --config=client.rb the chef-client cannot find the cookbook:

Starting Chef Client, version 11.16.4
[2014-10-25T15:34:59+02:00] WARN: Run List override has been provided.
[2014-10-25T15:34:59+02:00] WARN: Original Run List: []
[2014-10-25T15:34:59+02:00] WARN: Overridden Run List: [recipe[znc]]
resolving cookbooks for run list: ["znc"]

================================================================================
Error Resolving Cookbooks for Run List:
================================================================================

Missing Cookbooks:
------------------
No such cookbook: znc

Expanded Run List:
------------------
* znc


Running handlers:
[2014-10-25T15:34:59+02:00] ERROR: Running exception handlers
Running handlers complete
[2014-10-25T15:34:59+02:00] ERROR: Exception handlers complete
[2014-10-25T15:34:59+02:00] FATAL: Stacktrace dumped to /home/sebastian/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 3.474758165 seconds
[2014-10-25T15:34:59+02:00] ERROR: 412 "Precondition Failed "
[2014-10-25T15:34:59+02:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

also note:

ls ~/.berkshelf/cookbooks 
build-essential-2.1.2  znc-0.0.1

Any suggestions why the cookbooks cannot be found?

EDIT:

Thanks for the quick answer. The solution was as John Bellone said to bundle exec berks vendor and change my client.rb configuration to:

# ./client.rb
cookbook_path File.dirname(File.expand_path(__FILE__)) + '/berks-cookbooks'

Answer

John Bellone picture John Bellone · Oct 25, 2014

There are a few directories that Chef Client will look for cookbooks by default. One of which is the $CWD/cookbooks which we can take advantage of using the berks vendor cookbooks command. I find it much easier to do this during my testing (especially with an automated process) as it ensures that I get a fresh copy of the cookbooks and not a cached, stale one.

If you are looking to simply get an environment up and running I would suggest using a Vagrantfile with the vagrant-berkshelf plugin. This will automatically vendor all of the cookbooks in a cache directory and upload it to the guest machine. It will even work if the provider that you are using is a cloud one, e.g. Amazon, Backspace, as it will use rsync instead of the shared directories.