Most people are probably already aware of this fact, but you can test your Ansible-roles on multiple Ansible versions (e.g. 1.9 and 2.0) with the help of Travis.

This is done using environment variables. When multiple environment variables are specified, a build will be run for every variable!

You can take advantage of this if you specify each version of Ansible you want to test as a variable:

env:
  - ANSIBLE_VERSION=latest
  - ANSIBLE_VERSION=1.9.4

Then you just have to modify the install-part of the travis.yml-file to pip-install Ansible with the environment variable set as the version variable:

install:
  - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi

Then (hopefully) your Travis CI tests will look like this:

ansible_travis

You can get a full example on the travis-file in my ansible-test-framework!



Related posts: