I did a day’s training at the FLOSS UK conference in Manchester on Chef. Anthony Hodson came from Chef (a company with over 200 employees) to provide this intermediate training which covered writing receipes using test driven development. Thanks to Chef and Anthony and FLOSS UK for providing it cheap. Here’s some notes for my own interest and anyone else who cares.
Using chef generate we started a new cookbook called http.
This cookbook contains a .kitchen.yml file. Test Kitchen is a chef tool to run tests on chef recipes. ‘kitchen list’ will show the machines it’s configured to run. Default uses Virtualbox and centos/ubuntu. Can be changed to Docker or whatever. ‘kitchen create’ will make them. ‘kitchen converge to deploy. ‘kitchen login’ to log into v-machine. ‘kitchen verify’ run tests. ‘kitchen test’ will destroy then setup and verify, takes a bit longer.
Write the test first. If you’re not sure what the test should be write stub/placeholder statements for what you do know then work out the code.
ChefSpec (an RSpec language) is the in memory unit tests for receipes, it’s quicker and does finer grained tests than the Kitchen tests (which use InSpec and do black box tests on the final result). Run with chef exec rspec ../default-spec.rb rspec shows a * for a stub.
Beware if a test passes first time, it might be a false positive.
ohai is a standalone or chef client tool which detects the node attributes and passes to the chef client. We didn’t get onto this as it was for a follow on day.
Pry is a Ruby debugger. It’s a Gem and part of chefdk.
To debug recipes use pry in the receipe, drops you into a debug prompt for checking the values are what you think they are.
I still find deploying chef a nightmare, it won’t install in the normal way on my preferred Scaleway server because they’re ARM, by default it needs a Chef server but you can just use chef-client with –local-mode and then there’s chef solo, chef zero and knife solo which all do things that I haven’t quite got my head round. All interesting to learn anyway.by