Resolving and downloading chef cookbook dependencies
Asked Answered
B

3

10

Let's say I want to use a community cookbook (i.e. http://community.opscode.com/cookbooks/gerrit). So I will download it using 'knife cookbook site download ' and upload to my local chef server. I need to repeat this step for every direct and transient dependency.

Is there a single command or tool to resolve/download all direct and transient dependencies of a cookbook?

Bakerman answered 16/5, 2014 at 15:19 Comment(1)
Thanks for your interest in my Gerrit cookbook :-) I would recommend you to use the state from GitHub.Ashworth
M
15

Just to expand the answers here about using Berkshelf which is included in ChefDk. The pointer to using Bershelf is great but missing the how part so hopefully somebody might find this answer helpful.

Take for example the wordpress cookbook which has dependencies: https://supermarket.chef.io/cookbooks/wordpress

In order to upload this to your chef-server, what you can do is create a Berksfile which Berkshelf will use as a configuration as to what Cookbooks to retrieve and where to get them. Just copy the one-liner from the Supermarket berkshelf section

chef-dev]$ cat Berksfile
source "https://supermarket.chef.io"

cookbook 'wordpress', '~> 3.0.0'

And then do a berks install

[chef-dev]$ berks install
Resolving cookbook dependencies...
Fetching cookbook index from https://supermarket.chef.io...
Installing 7-zip (1.0.2)
Installing apache2 (3.2.2)
Installing apt (2.9.2)
Installing bluepill (2.4.3)
Installing build-essential (2.4.0)
Installing chef-sugar (3.3.0)
Installing chef_handler (1.4.0)
Installing compat_resource (12.10.6)
Installing database (5.1.2)
Installing iis (4.1.10)
Installing mariadb (0.3.1)
Installing mysql (7.2.0)
Installing mysql2_chef_gem (1.0.1)
Installing nginx (2.7.6)
Installing ohai (2.1.0)
Installing openssl (4.4.0)
Installing packagecloud (0.2.4)
Installing php (1.9.0)
Installing php-fpm (0.6.10)
Installing postgresql (4.0.6)
Installing rbac (1.0.3)
Installing rsyslog (4.0.0)
Installing runit (1.7.8)
Installing selinux (0.9.0)
Installing smf (2.2.8)
Installing tar (0.7.0)
Installing windows (1.44.1)
Installing wordpress (3.0.0)
Installing xml (2.0.0)
Installing yum (3.11.0)
Installing yum-epel (0.7.0)
Installing yum-mysql-community (0.2.0)

Once the cookbooks are available locally, you can then upload the cookbook and its dependencies using berks upload. During the upload, it will also take care in resolving dependencies similar to download.

[chef-dev]$ berks upload

Also FYI, the cookbooks will be download and available in

~/.berkshelf/cookbooks/
Mccarty answered 7/7, 2016 at 10:21 Comment(2)
Very informative, thanks! Is there also a berks equivalent to chef-solo -c solo.rb -j solo.json for deploying the infrastructure to a machine?Outsmart
hi, i just tried this but i am getting error as follow Resolving cookbook dependencies... Fetching 'wp_test' from source at . Fetching cookbook index from supermarket.chef.io... The dependency constraints could not be solved in the time allotted. Unable to find a solution for demands: wordpress (~> 3.0.0), wp_test (0.1.0)Principalities
A
6

The tool that you are looking for is Berkshelf which provides a berks command.

It is also included in ChefDK.

Ashworth answered 16/5, 2014 at 16:26 Comment(0)
F
5

Things are in a a bit of a transition right now. Berkshelf is probably the way to go in the future, but if you need something that works now (or you're on a platform not yet supported by the ChefDK), you should be able to do something like:

knife cookbook site install gerrit
knife cookbook upload gerrit --include-dependencies

Personally, I've found creating wrapper cookbooks and managing the dependencies via berkshelf to be the most convenient. But I've used the above to do a few one-off tests with new cookbooks.

Farmyard answered 16/5, 2014 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.