Kitchen CI – using the Vagrant driver

I’d previously been using the Docker driver with Kitchen CI and kitchen-ansible to test my Ansible playbooks. I really like using Kitchen CI. Test-driven infrastructure development! Regression testing! It’s great.

There were several reasons I decided to switch from the Docker driver to Vagrant. My target hosts are all either VMs or bare metal servers, so Vagrant VMs more closely resemble that environment. In particular, there are a couple areas where Docker containers don’t perform well for this purpose:

  • Configuring and testing SELinux settings
  • Configuring and testing systemd services

Using Vagrant instead is easy enough, just change the driver name in the .kitchen.yml file from:

name: docker


name: vagrant

I also updated the platforms section from:

- name: centos-7
    image: centos7-ansible


- name: centos-7

Then I ran kitchen test all:

-----> Starting Kitchen (v1.20.0)
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ClientError
>>>>>> Message: Could not load the 'vagrant' driver from the load path. Please ensure that your driver is installed as a gem or included in your Gemfile if using Bundler.
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

Sanity check, do I have Vagrant installed?

$ vagrant --version
Vagrant 2.0.3

I should note that I spent a while trying to test this on a CentOS VM running in VirtualBox. Installing VirtualBox and Vagrant on CentOS can be a bit of a pain. VirtualBox networking within a VirtualBox VM doesn’t work very well, if at all. I ended up running this on my Mac laptop.

Install the kitchen-vagrant gem:

$ gem install kitchen-vagrant
Fetching: kitchen-vagrant-1.3.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

Oh, right. User privileges:

$ sudo gem install kitchen-vagrant
Fetching: kitchen-vagrant-1.3.2.gem (100%)
Successfully installed kitchen-vagrant-1.3.2
Parsing documentation for kitchen-vagrant-1.3.2
Installing ri documentation for kitchen-vagrant-1.3.2
Done installing documentation for kitchen-vagrant after 0 seconds
1 gem installed
$ kitchen test all

Since this is the first time I ran it (successfully) with Vagrant, it had to download OS images for CentOS 7. It took a little while, but now it’s done and subsequent tests run a bit faster.

Leave a Reply

Your email address will not be published.