2

I'm new to chef and berkshelf, and very confused I have tried seeking help in open board questions but no luck please help me..

  1. Does berkshelf install my recipes along resolving the dependencies? Meaning the recipes has MySQL so after vagrant up will MySQL be installed?
  2. Should I use vagrantfile in vagrant root or the one with berkshelf?
  3. Why does vagrantfile in berkshelf (even without recipes) always have the entries for MySQL: server_root/Debian/repl passwords!!!!)

Thank you

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
SJamro
  • 21
  • 1

1 Answers1

4

Berkshelf is a cookbook dependency manager.

Assuming you have already installed the chef development kit, first generate a cookbook:

$ chef generate cookbook demo
$ tree
.
└── demo
    ├── Berksfile
    ├── chefignore
    ├── metadata.rb
    ├── README.md
    ├── recipes
    │   └── default.rb
    ├── spec
    │   ├── spec_helper.rb
    │   └── unit
    │       └── recipes
    │           └── default_spec.rb
    └── test
        └── integration
            ├── default
            │   └── serverspec
            │       └── default_spec.rb
            └── helpers
                └── serverspec
                    └── spec_helper.rb

The Berksfile holds the configuration and its format is documented on the website. The cookbook generator creates a default setting that tells berkshelf to download dependencies from the Chef supermarket and to use the metadata file to list those dependencies:

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

metadata

So let's edit the metadata.rb file adding mysql as a dependency

name 'demo'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'all_rights'
description 'Installs/Configures demo'
long_description 'Installs/Configures demo'
version '0.1.0'

depends "mysql"

So now if you decide to run berkshelf, it will resolve your cookbook's dependencies for you automatically.

$ berks vendor cookbooks
Resolving cookbook dependencies...
Fetching 'demo' from source at .
Using demo (0.1.0) from source at .
Using mysql (8.1.1)
Vendoring demo (0.1.0) to cookbooks/demo
Vendoring mysql (8.1.1) to cookbooks/mysql

Hopefully this answers some of your questions, but to conclude could I recommend that you look at test kitchen? The cookbook generator also configures this to use Vagrant to both run chef and test your cookbook at the same time:

$ kitchen test default-ubuntu-1404

Be a happy Chef!

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185