Search code examples
ansiblepuppetdevopsconfiguration-management

How to automatically test configuration managing scripts?


I am using tools like Puppet/Chef/Ansible to set up and config development environments and production servers.

Whenever I update the configuration, I run the tool against my development environment and log in to check manually if things works as expected.

But this is tedious to do, and I can't test everything every time, so is there any way I can automate the testing?


Solution

  • There are Infrastructure Testing Frameworks for this:

    • ServerSpec / InSpec - ruby-based. Famous, big community, nice looking and best in his class.
    • BATS - Bash Automated Testing System, which is a bit easier.
    • TestInfra - Python-based infra testing framework. Still pretty young, very small community. Intro.
    • Goss - Fast (written in Go), small tool for validating server/infra configuration. Test scenarios are written in yaml.

    Automation:

    • There is interesting Molecule project - some automation for testing Ansible roles, designed by Cisco. Never tried it yet.
    • Step further would be using TestKitchen which handles automation to spin up Vagrant or Docker or even AWS instance and test Puppet/Chef/Ansible with Rspec/BATS against just spinned up machines.

    So what you need - pick up framework, write tests and run your playbooks/recipes & tests against mock VMs.

    Ideally is to keep your "infra as code" in and configure like TravisCI to run your tests for every PR once you bring new changes in your repository. You can even follow here: write tests first, make them fail, then write actual implementation in your favorite configuration management tool and see if that change makes tests green/passed.


    MOAR Infrastructure Testing & Automation!