Testing Ansible with Kitchen


All code must be tested. An Ansible playbook is code even though it is about infrastructure. Testing infrastructure is important in order to save time on debugging different OS servers and once you have it, CI is possible which is awesome. Using kitchen we can automate the testing of our configuration management code across a variety of platforms using Docker as a driver to setup the environment and serverspec in order to perform the tests.


Install Requirments

Kitchen Configuration

  • Create a .kitchen.yml file and populate it with these lines:

Role creation

  • Create a roles folder and copy the role under test to it, in our case it is the sample-role (will be replaced with a script to make it more practical).

  • Create a test.yml and populate it with these lines: (or any name that you want - but then change it also in the .kitchen.yml)

Test Creation

  • Create default_spec.rb test file under test/integration/default/serverspec and populate it with these lines: (you can change the name ‘default’ and then in all paths update to the correct name)


  • Now go to the root folder, where .kitchen.yml is located and run sudo kitchen test
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com