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?
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'
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With