Chef Kitchen is a great way testing your Chef Cookbooks locally without breaking up your Production / UAT / Dev environments.
First, you have to install Vagrant and VirtualBox on your workstation (guide on how to do that easily — http://apsega.lt/getting-started-with-vagrant-and-virtualbox-on-os-x/, but you can skip adding boxes and initialising VM steps).
Then, download and install Chef Development Kit from chef.io, or use command line and install it via brew cask:
brew cask install chefdk
After Chef DK has been successfully installed, we can create our Kitchen working directory (i.e.
mkdir chef) and generate first Cookbook by running the following command:
chef generate cookbook nginx (you can specify your own cookbook name other than nginx)
Change directory to newly created cookbook:
Needed Kitchen virtual machine configuration is in
.kitchen.yml file, while
Vagrant file is in
.kitchen/kitchen-vagrant/kitchen-nginx-default-centos71/ location. Editing
.kitchen.yml is suffice for our Kitchen environment (changing box names, etc.).
After we've configured our desired VM state, we can bring it up easily:
This command is all-in-one package that actually initialises Vagrant box, installs chef-client into it and executes your recipes. To check your VM state, you can run:
To login to your guest box run:
And you can always destroy your box with the following: