windowsgitberksfile

Chef-Repo Berkshelf Confusion Setup


I am soooo confused when it comes to Chef / Berkshelf and need help and advice.

What I've found / read there's an underlining assumption with some things with Berkshelf and for the newbie there is a bit of a grey area that needs filling

Let me try to explain:

I followed the typical Chef path

Create Chef-repo in user directory

C:\Users\itsmeofcourse\chef-repo

then hooked that into an internal git-repo and happily writing basic cookbooks for Windows and uploading everything into that git-repo

as it stands every cookbook exists under the "cookbook" folder in my chef-repo.

C:\Users\itsmeofcourse\chef-repo
                            /cookbook

I've then followed the path of writing wrapper cookbooks around community cookbooks, so it would look like

client_iis - depends upon department_iis - depends upon global_iis - depends upon iis - community cookbook

this allows us make IIS changes at certain different levels within our infrastructure.

Now where documentation I feel falls down, is everyone is saying move your cookbooks out of the "cookbook" folder

so what I understand, "your" chef-repo will exist in a git-repo but just for changes to sub-folders like environments / data bags / roles / certificates etc ? and the cookbook are then separate projects is that correct or not ?

Where do you move your cookbooks to ? anywhere on you machine / within your user %home%? How does Chef know where these are stored or do you have to amend your "knife.rb" and point to a certain directory ?

so it would look like

knife.rb cookbook_path ["c:/cookbooks"]

C:\Users\itsmeofcourse\chef-repo :github => repo_1

c:/cooksbooks
   /base  :github => repo_2
   /iis   :github => repo_3
   /sql   :github => repo_4
   /client_iis   :github => repo_
   /department_iis   :github => repo_3

Can I ask what am I missing

or do you place a berksfile in the root of my chef-repo and then do what ? to manage everything in my cookbook folder ?

I have read through https://github.com/berkshelf/berkshelf/issues/535

please can someone help


Solution

  • Yes, it's correct and you would usually move your cookbooks to a separate repository.

    One gotcha I had, was while reading this article: http://www.prashantrajan.com/posts/2013/06/leveling-up-chef-best-practices/ and the "Single Repo Per Cookbook" part. Read the whole thing, it's good!

    It seems like you are not missing anything. Moving your cookbooks out of cookbooks directory, means creating separate repos per cookbook and depending on them using top level Berksfile (in the root of your chef-repo).

    For a typical vagrant+chef repo for a web app (called coolwebapp), I would usually have:

    .
    +-- cmp-cookbooks
    |   +-- cmp-coolwebapp (this is only cookbook stored in this repo, and this repo exists because of this cookbook)
    +-- data_bags
    |   +-- users
    |   |   +-- mysql.json
    |   |   +-- os.json
    |   |   +-- admins.json
    |   +-- private_keys
    |       +-- deployment.json
    +-- environments
    |   +-- production.rb
    |   +-- staging.rb
    |   +-- qa.rb
    |   +-- integration.rb
    |   +-- local.rb
    +-- nodes (but this should not be stored in your repo I guess)
    |   +-- ip_here.json
    |   +-- other_ip_here.json
    +-- Berksfile
    +-- Vagrantfile
    

    Berksfile would contain:

    cookbook "cmp-coolwebapp",   "~>0.3.0",  path: "./cmp-cookbooks/cmp-coolwebapp"
    cookbook "cmp-provisioning", "~>0.7.0",  git: _priv_provisioning_cookbook_repo_
    cookbook "cmp-role-db",      "~>0.7.0",  git: _priv_role1_cookbook_repo_
    cookbook "cmp-role-www",     "~>0.8.0",  git: _priv_role2_cookbook_repo_
    cookbook "cmp-role-devops",  "~>0.7.0",  git: _priv_role3_cookbook_repo_
    

    "cmp" stands for our company name. Our cookbooks are stored in private repos, and are being maintained individually.

    Cookbook cmp-role-www for example, would have mostly community cookbooks as dependencies in Berksfile, and our own cmp-apache2, cmp-nginx, cmp-varnish wrapper cookbooks stored in its repo.

    Answering your last question" "How does Chef know where these are stored or do you have to amend your "knife.rb" and point to a certain directory ?"

    If you manage your cookbook dependencies with Berkshelf, you can include cookbook from any location you prefer:

    cookbook "artifact",   path: "/Users/reset/code/artifact-cookbook"
    cookbook "mysql",      git: "https://github.com/opscode-cookbooks/mysql.git", branch: "foodcritic"
    cookbook "rightscale", git: "https://github.com/rightscale/rightscale_cookbooks.git", rel: "cookbooks/rightscale"
    

    The last one is useful when you store several company cookbook in one repository. http://berkshelf.com/ "Source options" section.