Using kitchen-salt for testing salt-formulas

I have put off learning how test-kitchen works with salt formulas for awhile. Mainly due to the multi-step setup process that can be slightly confusing if you are not accustomed to working with developer tools day to day. It became clear though that learning this workflow would be really beneficial for developing salt-formulas and other projects because of the increased testing speed and the ability to quickly iterate changes without building bulky VM infrastructure.

While the above approach is great, I have found some oddities when using docker for testing salt-formulas. As an example, something that works without issue in a VM, doesn’t always work the same way when using containers. The complex relationships between the build OS and the container OS can add the need for interesting workarounds. Nevertheless, if this sounds interesting, then use this quick setup guide for getting started.

There are several technologies used to create the underlying build system so we can take advantage of the benefits of the proposed solution such as; Ruby, Docker, KitchenSalt, InSpec, and a CI tool like Travis. Below are steps to install each major sub-component.

Install docker

Install docker by following the steps located here

Once completed, make sure your user is setup to use docker.

sudo usermod -aG docker <username>

You may have to reload your profile.

source /etc/profile

Check if you can run docker ps from the cli as your user.

Install rbenv, ruby, and bundler

Install the dependencies for building ruby on CentOS:

sudo yum install -y git openssl-devel readline-devel zlib-devel bzip2 make gcc gcc-c++

Clone the rbenv repos and setup your path:

sudo git clone git:// /usr/local/rbenv
sudo mkdir /usr/local/rbenv/plugins
sudo git clone git:// /usr/local/rbenv/plugins/ruby-build
sudo tee /etc/profile.d/ <<< 'export PATH="/usr/local/rbenv/plugins/ruby-build/bin:/usr/local/rbenv/bin:$PATH"'
sudo tee -a /etc/profile.d/ <<< 'source <(rbenv init -)'

Install ruby with rbenv and set the version to use by default:

Versions of ruby to install

rbenv install 2.6.3
rbenv global 2.6.3

Install bundler, as it provides a consistent deployment by installing the defined ruby gems within individual project environments.

gem install bundler

Install KitchenSalt

Create a Gemfile in your working directory and add; kitchen-salt, kitchen-docker, and kitchen-sync entries.

vi Gemfile

insert the below contents:

# frozen_string_literal: true
source ''

gem 'kitchen-docker'
gem 'kitchen-salt'
gem 'kitchen-sync'

Now run bundle install

Validate everything works

A quick test is to clone the salt-formulas template-formula to make sure everything works.

git clone

cd into the repo and configure things

cd template-formula
bundle install

Run your test

bin/kitchen test centos-7-2019-2-py3

You can look in the .travis.yml file for additional platforms to test if you are curious.



You must be logged in to post a comment.

Proudly powered by WordPress   Premium Style Theme by