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 vcs and configure ci like TravisCI to run your tests for every PR once you bring new changes in your repository.
You can even follow tdd 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!