Testing Ansible roles with test-kitchen and Docker using the Ansible Role Tester

‹ Structured log files in Python using python-json-logger | Understanding protocol buffer version compatibility issues in Python ›

Preparing an Ansible role to be distributed can be time consuming and error prone. Ideally, you should test it against many versions of Ansible and many operating system versions. However, doing this is time consuming.

Enter the Ansible Role Tester.

In its simplest form, you simply add this to your CI script after making sure that docker and bundler are available:

wget -O- bit.ly/ansibletest | sh

The role tester will clone its source from github, and using test-kitchen, execute your role against various permutations of Ansible versions and operating system versions. I have started using this script to ansible roles for setting up new personal hardware.

You can configure behavior like the ansible versions and host operating systems that are tested using environment variables:

wget -O- bit.ly/ansibletest | env ANSIBLE_VERSIONS="system 1.4.4 2.1.0.0" DOCKER_IMAGES="ubuntu:16.04 centos:5" sh

The source code is freely available under GPL license on github. There are certainly many more features that could be added, and pull requests are welcome.

Subscribe to All Posts - Wesley Tanaka