Search code examples
berkshelf

Does berkshelf support multiple cookbooks? How?


I have two cooksbooks that I created in my Chef repo that I want to try to manage using Berkshelf.

One cookbook is dependent on the other. Both are not in Chef Supermarket. I don't want to add them there just for dependency resolving.

On on berks install this things complains about the other cookbook is missing.

This cookbook only exist as upload to my Chef server. It is not in Chef supermarket and also not in ~/.berkshelf/cookbooks/

Is this possible? Or does Berkshelf require all recipes in one cookbook? It is not possible to have dependencies between two cookbooks that are not in Chef supermarket?

The Berkshelf does not seem to deal with this use case of multiple interdependent cookbooks. There are also no commands to get cookbooks in ~/.berkshelf/cookbooks.


Solution

  • Berkshelf do support multiple cookbooks. I've experience in managing more than 30 cookbooks in same berkshelf. Berks can refer cookbooks from local path, git path, github sources and community cookbooks from Chef super market.

    Update

    Lets take the example of the scenario mentioned in the query. Please carry out the below steps,

    • You need to create a project repository with your cookbooks and other stuff.
    • Project repo is nothing but a directory containing other directories for Roles, Databags, Cookbooks and Environments.
    • Place your cookbooks inside cookbooks directory.
    • Create a Berksfile in the root of the repo.
    • Berksfile uses berkshelf. Install latest berkshelf version using gem install berkshelf (I would prefer using bundle install)

    Example content of Berksfile

    source "https://supermarket.chef.io"
    
    # Mention community cookbooks used, if any
    cookbook 'community_cookbook_name'
    
    # Mention cookbook names from your repo
    %w(my_cookbook_name_1 my_cookbook_name_2).each do | cookbook_name |
      cookbook cookbook_name, path: 'cookbooks/' + cookbook_name
    end
    
    • Community cookbook dependencies will get resolved using the source url in 1st line.
    • Now the basic project repo setup has been done. You're ready to run berks install

    • List items berks list

    Please try the above steps and let me know if it's solved your purpose.

    • In case, if you want to upload the content, follow the steps below,
    • Create a directory ".chef" inside the project repository
    • Copy your Chef server knife/pem files into .chef
    • Run the command mentioned below from inside the project repo.

      berks upload

      Your cookbooks will be uploaded to Chef server using the command.

    • You can use knife upload data_bags and knife upload roles, to upload your databags and roles from the repo.