All Route 1337 LLC Ansible roles are tested via Test Kitchen.
Yes. Normally Test Kitchen is a Chef thing, but we found it to be very useful for testing Ansible roles as well.
We're using Inspec with Test Kitchen to achieve a test environment that we can use not only during role development, but also
during CI/CD pipelines involving Ansible, and directly against live servers if needed.
In order to configure the test environment you will need a few prerequisites. We are assuming you are on a Mac but these instructions are largely the same for Linux.
- Install the Ruby virtual environment tools via
brew install rbenv ruby-build
- Install the Ansible linting tool via
brew install ansible-lint
- Configure a Ruby 3.1.2 virtual environment via
rbenv install 3.1.2
- Set it to be the default via
rbenv global 3.1.2
- Add the following to your
~/.profile
rubydev() { if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi }
- Enter the Ruby virtual environment via
rubyenv
(Re-source your .profile first) - Then just
gem install bundler && bundle install
while in the repo root. - Make sure you have AWS credentials for the default profile with active API access
- For Ubuntu 22.04+ you will need a custom AMI that has RSA enabled for sshd until Vagrant is updated
- Now try
kitchen list
to see the roles available for testing.
You can test against any server (production or not) that you can SSH to using the inspec
command directly via inspec exec test/smoke/<ROLE>/default --sudo -t ssh://<YOUR USERNAME>@172.16.2.143
All roles tested this way must follow these testing rules:
- All roles must have accompanying Inspec tests that fully test their actions.
- Sample data should be used to verify that templates fill properly.
- All supported operating systems should be tested against.
- Code should pass
ansible-lint /path/to/role
Return to README