Test-Kitchen Workflow With Docker For OSX

docker containers

Test-Kitchen Workflow With Docker For OSX

Everyone knows that automation is key to being successful in getting your job done and done correctly. One thing that people complain about over and over is the time it takes to set up a fast feedback loop to properly validate your configuration management code be it Puppet, Ansible, Chef, or SaltStack. Our Managed Services team exclusively uses Test-Kitchen to streamline this workflow for the shortest possible feedback loop for this work.   So let’s dive into a few of these points and get your baseline setup working with Docker and OSX!

What Gains You’ll Make From This Article:

  • Full local development setup for configuration management
  • A repeatable process to scale out to your DevOps team.
  • A look into immutable infrastructure
  • Lighter weight base test infrastructure
  • Very short feedback loop

Getting The Pre-Reqs Installed For OSX:

Here is the list of software that you will need installed prior to getting going with this:

  • Homebrew
  • Terminal Software (we suggest iTerm2 + zsh)
  • ruby 2.x
  • bundler (gem install bundler)
  • Coffee / Beer (depending on the time of the day you’re cranking through this)

Installing Docker Edge

We’re going to use Docker as the main provider we work with in this tutorial. Also we want all of the features available to us as we’re going to be working with them over the course of the week.


  • Grab the Edge dmg file and get it installed by following the documentation
  • Make sure that docker service is running by opening your terminal and run the following commands:
    • docker ps

Installing Chef Development Kit (ChefDK)

Regardless of what configuration management solution you are using you will want to install the full chef development kit to ensure that you have properly installed test-kitchen.


  • Grab the latest dmg and install it

Now we’re ready to rock and get to the interesting stuff!!!

Bootstrapping Your Project

We’re going to do a fairly simple project and just get your project bootstrapped. We will pull down an Ubuntu 16.04 docker image and prep it for installing Apache with Ansible, which is RLT’s preferred configuration management solution.

In your terminal run these commands:

mkdir rlt-kitchen
cd rlt-kitchen
git init && kitchen init

➜ rlt-kitchen git:(master) ✗ ls -lah
total 24
drwxr-xr-x 7 efouarge staff 224B Jan 8 13:13 .
drwxr-xr-x 9 efouarge staff 288B Jan 8 13:12 ..
drwxr-xr-x 9 efouarge staff 288B Jan 8 13:13 .git
-rw-r--r-- 1 efouarge staff 29B Jan 8 13:13 .gitignore
-rw-r--r-- 1 efouarge staff 173B Jan 8 13:13 .kitchen.yml
-rw-r--r-- 1 efouarge staff 9B Jan 8 13:13 chefignore
drwxr-xr-x 3 efouarge staff 96B Jan 8 13:13 test

mkdir -p roles/apache/tasks
mkdir -p roles/apache/handlers
mkdir -p roles/core/tasks
mkdir inventories
mkdir group_vars

Your project is now bootstrapped and you should be ready to start.

Setting Up Test-Kitchen With Docker Support

Now to get Docker rolling with test-kitchen we’re going to need to make a few quick edits and couple new files.

Edit the .kitchen.yml

 name: docker
 privileged: true
 use_sudo: true

 name: ansible_playbook
 roles_path: roles
 require_ansible_repo: true
 ansible_verbose: true
 ansible_version: latest
 hosts: webservers
 playbook: site.yml
 ansible_inventory: inventories/development

 - name: ubuntu-16.04

 - name: default

Create file Gemfile with this content:

# RLT test-kitchen sample Gemfile
source "https://rubygems.org"

gem "test-kitchen"
gem "kitchen-docker"
gem "kitchen-ansible"
gem "net-ssh"
gem "serverspec"
gem "kitchen-verifier-serverspec"

Install the new ruby gems with bundler:

bundle install
kitchen list
## Expected output
Instance Driver Provisioner Verifier Transport Last Action Last Error
default-ubuntu-1604 Docker AnsiblePlaybook Busser Ssh <Not Created> <None>

Great work!! Now we’re ready to push on to getting the Ansible code in place

Integrating Ansible Into The Workflow

We’ve already created the base directory structure. Now we just need to get the base Ansible code in to get our Apache server up and going. Create the following files:


- name: Setup webserver
 hosts: webservers
 - core
 - apache


# uncomment this to disable SSH key host checking
host_key_checking = False




serverMode: DEV


- name: Debug {{ serverMode }}
 msg="Server Environment - {{ serverMode }}"

- name: Update cache
 update_cache=yes cache_valid_time=3600


- name: Install Apache2
 name=apache2 state=installed
 - apache2

- name: Disable OS default site config
 a2dissite 000-default
 "'already disabled' not in result.stdout"
 - restart-apache2
 - apache2


- name: restart-apache2
 name=apache2 state=restarted
 - apache2

Now the ansible code is completed!  Let’s validate it is working!!

Validating Ansible Code With Test-Kitchen

This is the core of the workflow and the meat that you are looking for as a DevOps Engineer.

Create your instances

kitchen create

Apply the Ansible code

kitchen converge
kitchen login default-ubuntu-1604

Tear down process

kitchen destroy

What’s Next?

This is just a part of larger series of posts that we will be publishing around streamlining your DevOps workflow. Reach out to us here if you need a larger project delivered or an assessment done on your current workflow!

Coming down the pipeline here are the upcoming articles!! Don’t see something you’d want us to cover? Let us know in the comments.

  • Serverspec integration
  • bats integration
  • Inspec integration
  • Dealing with Windows config management testing
  • Puppet
  • Jenkins Integration
  • Complex application config management testing
Do you require assistance on your network or want to deploy your very own?
Then click the button below to get started!