Ansible strategy for including smoke tests

So, as per previous post, we want a way to be able to test the infrastructure and do so, in a way that we can run it independently of the actual creation of the infrastructure and also, fine-grained enough that you should be able to run the smoke tests for only a single piece of the infrastructure (or skip all of the smoke tests) if so required.

To get this working, we’ll be making use of Ansible roles and tags. The strategy, is to equate application with role and then, within the role tasks, have a separate task file, tagged with “tests”.

By default, when Ansible runs, it runs all tags (i.e. it’ll run the main playbook tasks as well as the tests), which is what we want. If we specify a particular tag associated with a role, that role will be run, with it’s tests. If we only specify the global “tests” tag, the tests for all roles will be run. If we want to target one or more roles’ tests, we currently need to do that by specifying the “tests” tag and then passing all of the roles/tags whose tests we don’t want to run to the “–skip-tags” argument.

This last case is not ideal, as we need to know all of the roles/tags in the playbook to skip. A workaround is to add a role-specific testing tag to the list of tags e.g. “role_a_smoketests” and then we can leave out the full list in the “–skip-tags” definition.

The code can be seen at: https://github.com/srkiNZ84/ansible_testing

Next, we’ll need to look at how to integrate one of the testing frameworks or indeed how to use Ansible itself for actually writing the smoke tests.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.