Testing Chef Recipes

Hey everyone;

I was wondering if there is a best practice for testing your chef cookbooks/recipes before pushing them to production. I can always have a test server that I would run the recipes on first, but after working with chef for a little bit now, I can't help but think there is something more efficient to use that I just don't know about.

P.S. I did try to install test-kitchen, but it gives me an error with the gem installer:

ERROR:  Error installing test-kitchen:
ERROR: Failed to build gem native extension.

Thanks

Hi @alexpatt!

The most simple way to get all the tools you need, is to use Chef Workstation (https://downloads.chef.io/chef-workstation/0.7.4) . That will include all the chef components (including test-kitchen) on most modern operating systems.

In order to install test-kitchen from a gem, you need C compilers enabled, as the gems use native extensions. There is a "build_essentials" resource in the Chef Infra Client that you can use to install those, though I would recommend going with the Workstation approach.

You are absolutely correct that the best way to test your Chef Infra code is to use a combination of test-kitchen and Chef Inspec.

Hope that helps!

Nathan

Hi @ncerny, thanks for the reply!

I've managed to get test-kitchen installed successfully, but when i run the command kitchen create the output is

-----> Starting Kitchen (v2.2.5)
-----> Creating <default-ubuntu-1804>...
       Bringing machine 'default' up with 'virtualbox' provider...
       ==> default: Checking if box 'bento/ubuntu-18.04' is up to date...
       ==> default: Machine not provisioned because `--no-provision` is specified.
       Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
       Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
       Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
       Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds
       Waiting for SSH service on 127.0.0.1:2222, retrying in 3 seconds

and it just keeps hanging on this until I force stop it. My .kitchen.yml file looks like this

---
driver:
  name: vagrant
  transport:
    ssh_key: /root/.ssh/id_rsa
    username: ubuntu

provisioner:
  name: chef_zero
  log_level: info

platforms:
  - name: ubuntu-18.04

suites:
  - name: default
    run_list:
      - recipe[standard-server::default]
    attributes:

Do you happen to have any ideas as to what could be causing this issue? Thanks again.

Can you open Virtualbox and see if the VM is created? If it's created but appears to be hanging, then you may not have virtualization enabled on your host/desktop/laptop.