Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chef-client cannot find cookbooks using berkshelf

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'
like image 916
have_a_question Avatar asked Oct 25 '14 13:10

have_a_question


People also ask

What is Berks in Chef?

Berkshelf is the tool which makes 'the management' & dependency management between cookbooks easy. Let's first talk about how a cookbook is used in Chef, for example, Nginx. Cookbooks are fed into the Chef-Client or Chef-Solo. It contains how to configure your application or service on your server.

What is Berks file?

Berksfile is for dependency management for cookbooks. Consider a case where my cookbook is using a community cookbook from chef supermarket. In this case, first I need to download that community cookbook from supermarket and upload it along with my own cookbook to chef server.

What is chef workstation?

Chef Workstation is Chef's modern developer tool kit that includes Chef Infra, InSpec and Habitat plus a host of resources, helpers and testing tools that make automating infrastructure, application and security testing easier than ever.


1 Answers

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.

like image 124
John Bellone Avatar answered Oct 01 '22 15:10

John Bellone