1

I kinda fell into chef and now I have a few nodes running and would like to clean up how I manage my cookbooks and dependencies.

Historically, I would often search the chef supermarket to find a cookbook that suited my needs and use knife to install that cookbook. knife cookbook site install foo. Which put the cookbook into my cookbooks directory chef-repo/cookbooks/foo.

When I couldn't find exactly what I was looking for, I'd create my own namespaced cookbook in that same directory chef-repo/cookbooks/mycompany-bar

Now that I have a nice little collection of community cookbooks and custom cookbooks I find it difficult to manage the dependencies and want to migrate to berkshelf.

My question is:

A lot of my roles simply use the community cookbooks that I installed w/out any sort of wrapper cookbook that "includes" them.

ie:

run_list "recipe[hostname]", "recipe[user::data_bag]", "recipe[chef-client::delete_validation]", "recipe[chef-client]", etc....

I'm not sure how to install and use any community cookbook with berkshelf w/out first creating my own cookbook and then having a dependency to a community cookbook. Is that the correct way I should be doing things?

Do I need to write a bunch of wrappers for these existing cookbooks? ie: Have my own mycompany-hostname cookbook that depends on the community hostname cookbook?

veilig
  • 5,085
  • 10
  • 48
  • 86

2 Answers2

0

You can just list the cookbooks that you need directly in your Berksfile

metadata # this will get anything in your metadata.rb (and recursive dependenceis)
cookbook 'cookbookname', '1.3.5' #OR
cookbook 'cookbookname' # OR
cookbook 'cookbookname' '>= 1.5.2'

This will get them pulled in when you do berks install and berks upload

Tejay Cardon
  • 4,193
  • 2
  • 16
  • 31
0

Berkshelf is the best way to manage cookbooks and dependencies.

You can mention your wrapper cookbooks and its dependencies in same berksfile. Cookbook source in "Beksfile", can be from "Chef Supermarket", GIT source, and system local path.

Consider cookbook "mysql_wrapper" is the cookbook developed by you and it uses "mysql" community cookbook. Also consider the wrapper is located in system local path.

Here is sample berksfile content for above scenario.

source "https://supermarket.chef.io"

cookbook 'mysql'
cookbook 'mysql_wrapper', path: '/system/local/path/to/wrapper-cookbooks/mysql_wrapper'

How it works?

When you run "berks install" or "berks upload", Berkshelf resolves the cookbooks mentioned in berksfile.

Dependent community cookbook will be downloaded from "Supermarket", because we referenced it in first line. While the wrapper cookbook will be referenced by local path.

Setting up a project for managing cookbooks, roles and data_bags

  • You need to create a project repository with your cookbooks and other stuff.
  • Project repo is nothing but, a directory contains other directories for 1. Roles, 2. Databags, 3. Cookbooks and 4. Environments. According to your requirement create repository.
  • Place your cookbooks inside cookbooks directory.
  • Create a directory as "roles". Add roles as ".json" files.
  • In case of data_bag/data_bag_item, create a directory as data_bags. Create a directory for each data_bag and add items as ".json" files.
  • Create the bersfile inside the repo

Manage Chef server

In case, if you want to upload the content, follow the steps below,

  • Create a directory ".chef" inside the project repo
  • Copy your Chef server knife/pem files into .chef
  • Run the command "berks upload" from inside the project repo. Your cookbooks will be uploaded to Chef server.
  • Run knife upload data_bags and knife upload roles, to upload your databags and roles from the repo.
Saravanan G
  • 581
  • 1
  • 9
  • 26