/ chef

(re) Starting with Chef

Quite a while ago, I posted about using Logstash as a Chef handler. That was about the last time that I used Chef. I changed jobs and managing servers wasnʼt part of my duties anymore. Well, Iʼve changed jobs again and, now, Iʼm back to managing servers. I initially started using Ansible but, I donʼt like the way it works. So, Iʼm back to using chef.

So when I got started this time around, I got started once again with Chefʼs documentation. If you are at all familiar with the recent developments (well not so recent really) then, you already know what the problem. It seems obvious in retrospect (or, for that matter, while youʼre doing it) but, dumping all of your custom cookbooks, as well as a ll of your dependencies, in a single repository is a bad idea.

Then, there is cookbook uploading. Once you have all of cookbooks setup in your repository, you need to upload them to the chef server. The first time is relatively easy, just knife cookbook upload -A to upload all of them at once. Then when you modify a cookbook and include a new dependency you go to upload it, knife cookbook upload <cookbook-name>. Which, of course, gives you an error that not all of the dependencies are available on the server. Annoying but, easily solved, just run knife cookbook upload --include-dependencies <cookbook-name>.

There has to be a better way and there is, The Berkshelf Way. Also, donʼt follow the directions on installing Chef Workstation. Youʼll need the part about setting up the keys and ~/.chef but, save yourself some trouble and just install chefdk. Then use Berkshelf to setup an application cookbook. To upload the cookbook and its dependencies to the Chef Server, all you need to do is run berks upload. In addition to the much better workflow, you get a bunch of awesome extras. It includes a Vagrant environment, for manual testing; Test-Kitchen, for automated integration testing; and Chefspec for unit testing. Berkshelf is an awesome addition to Chef and it should be the default workflow.