Home

Mike Caspar edited this page Sep 11, 2016 · 19 revisions

Welcome to the playbook_test_framework wiki!

Details on design and usage coming soon!

These DOCS are a Work in progress.

The role on galaxy... https://galaxy.ansible.com/MikeCaspar/playbook_test_framework/

The original slides for the test/maintain loop can be read about here.

Tests during this part of the loop are created via a _test.yml file that can be separately executed from _maintain playbooks.

This allows a test first/test parallel type approach with the ability to also use _test.yml as a form of governance check.

To provide samples to those that wish to use this approach, I decided it was a good idea to share pre-defined exmaple roles for those that wish to take this approach and do not want to start from scratch.

The intent is to allow teams working on infrastructure to use existing ansible yaml syntax without having to learn python development.

quick notes if you are into trying things out already.

  • You may use this as an auto-loader for all sub-roles for testing or you can load each role as needed individually.
  • This galaxy test role auto-loader will be controlled as to which versions of sub-modules get loaded. Do what works best for you.

  • if you want to add a role, feel free to reach out to me for help until I work out some documentation for how to do this effectively.

  • Please list mandatory fields for each role.

Design guidelines

  • test roles are intended to be part of the _test cycle.
  • roles should make no changes to system settings and should be read-only
  • each role will have default parameter of

    debug: false

if it is not provided. Setting to true will enable debug.

  • A fail-fast approach was initially used. This did not work well for parallel creation of tests (or creation of tests in advance.
  • To simulate other testing frameworks, all failed tests will appear via messages as "TEST_FAILED:" or "TEST_PASSED:" followed by some text.
  • A common use pattern is to execute the playbook and echo output to log.txt. Then grep that log.txt for TEST_FAILED or TEST_PASSED as needed

A sample _test playbook

`

  • hosts: servers

    roles:

    • { role: MikeCaspar.testForTimezone, timezoneCity:"America/Toronto" }
    • { role: MikeCaspar.testForFolder, path:"/etc" , expected: present}
    • { role: MikeCaspar.testForPackage, name: "ufw" , expected: present}

Governance and/or acceptance

Alternate files names could be used for the _test cycle including _accept or _govern. For an explanation read the page Alternate_Test_File_Names]https://github.com/MikeCaspar/playbook_test_framework/wiki/Alternate_Test_File_Names)

The test/maintain loop

https://raw.githubusercontent.com/wiki/MikeCaspar/playbook_test_framework/images/TestMaintainLoop.png