4

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?

5
  • This sounds too broad, I suppose you can always create an ansible playbook to automate running tests.
    – Wtower
    May 3, 2016 at 7:44
  • @Wtower But how do you test the playbook itself?
    – satoru
    May 3, 2016 at 7:46
  • I see what is your issue here, I would recommend you to edit in the details.
    – Wtower
    May 3, 2016 at 11:20
  • If you are using exclusively idempotent Ansible modules, every task is testing itself. Most tests that you could write on top of this would be redundant. You should write tests that evaluate things not managed directly by Ansible, like running unit or integration tests against an application you are deploying, and looking at failures to see if they are application or infrastructure issues.
    – MillerGeek
    May 3, 2016 at 18:24
  • Also, you can test whether your playbooks are idempotent by running them again on top of the same stack. if anything is listed as changed, you have an idempotency issue.
    – MillerGeek
    May 3, 2016 at 18:25

2 Answers 2

5

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!

0

If you can let us know, what you want to test. We can help better.

But, Did you check the dry-run mode? I think, Puppet and Ansible supports it, you can have a cron or some automated script which runs all the puppet/ansible modules against a single(test) node.

More info:
1. http://docs.ansible.com/ansible/playbooks_checkmode.html
2. Check the noop mode in https://docs.puppet.com/puppet/latest/reference/man/agent.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.