How run cookbook with dependencies in chef?

空扰寡人 提交于 2019-12-02 05:13:41

See here

Or just type knife cookbook upload --help and it will show you the following line (along others):

--include-dependencies Also upload cookbook dependencies

So knife cookbook upload myCookbook --include-dependencies is your answer

You'll need to have the maven cookbook on your workstation too, by knife cookbook site install maven or any other way to have a directory called maven in your local cookbook_path containing a cookbook where the metatada.rb file as a key name with value maven

@rastasheep has described how the berkshelf tool is now bundled with the chefdk package.

It's really easy to use and worth learning. It's designed to work like the gem bundler tool.

Example

└── myCookbook
    ├── Berksfile       <-- Berkshelf configuration file
    ├── Berksfile.lock  <-- Lock file generated by Berkshelf
    ├── metadata.rb
    ├── README.md
    └── recipes
        └── default.rb

Berksfile

source "https://supermarket.getchef.com"

metadata

The "source" directive tells berkshelf where to download dependencies from. The "metadata" directive tells berkshelf to take dependencies from the cookbook metadata.

Using Berkshelf

The "install" command will download the cookbook dependencies (Cached under ~/.berkshelf)

$ cd myCookbook
$ berks install
Resolving cookbook dependencies...
Fetching 'myCookbook' from source at .
Fetching cookbook index from https://supermarket.getchef.com...
Installing maven (1.2.0)
Installing 7-zip (1.0.2)
Installing ark (0.9.0)
Installing chef_handler (1.1.6)
Installing java (1.29.0)
Installing windows (1.34.8)
Using myCookbook (0.1.0) from source at .

Berkshelf can also upload all the cookbooks into your chef server

$ berks upload
Uploaded 7-zip (1.0.2) to: 'http://127.0.0.1:8889/'
Uploaded ark (0.9.0) to: 'http://127.0.0.1:8889/'
Uploaded chef_handler (1.1.6) to: 'http://127.0.0.1:8889/'
Uploaded java (1.29.0) to: 'http://127.0.0.1:8889/'
Uploaded maven (1.2.0) to: 'http://127.0.0.1:8889/'
Uploaded myCookbook (0.1.0) to: 'http://127.0.0.1:8889/'
Uploaded windows (1.34.8) to: 'http://127.0.0.1:8889/'

There is a few other options for managing cookbook cookbook and dependencies, such Berkshelf or Librarian-chef, where Berkshelf is more popular, and it's even included in Chef Development Kit, so if you use it you do not need to install it separately.

After defining sources you just need to define which cookbooks you want their versions and cookbook manager will resolve dependencies for all defined cookbooks and it will install them for you, and if you want you can vendor them too. Beside that they have an option to upload specific cookbook, without worrying about upload dependencies.

For more info how to use those tools consult official websites:

In general for managing small projects you can use knife's upload flag for uploading dependencies.

-d, --include-dependencies
    Use to ensure that when a cookbook has a dependency on one (or more) cookbooks, those cookbooks will also be uploaded.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!