In this presentation I demonstrated how simple it is to develop Ansible roles in a test driven way, using the faster feedback that docker enables and the easily readable Serverspec test framework, with Test Kitchen helping to bring all the tools together.
4. Test Driven Development
Write Failing Test
Write CodeMake Test Pass
Write tests
one at a time
Add code in small
increments
Commit often No refactoring until tests pass
5. Test Kitchen
• Originally designed for Chef
• Test Harness with simple
workflow
• Pluggable architecture!
6. Key Concepts
• Drivers <<
• Provisioners
• Platforms
Where to run your code:
Cloud infrastructure
Azure, EC2, Rackspace
Local environment
Vagrant, Docker
7. Key Concepts
• Drivers
• Provisioners <<
• Platforms
How to configure your environment:
Ansible, Chef, Puppet, CFEngine
8. Key Concepts
• Drivers
• Provisioners
• Platforms <<
Which OS to spin up:
Can be Linux or Windows if using a
VM
10. Ansible 101
• SSH-based configuration management
• Idempotent - Test & repair to achieve desired
state
• YML files with loops, conditionals and variables
12. Serverspec
RSpec for your infrastructure
describe file('/etc/passwd') do
it { should be_file }
it { should exist }
end
describe package('httpd') do
it { should be_installed }
end
describe user('foo') do
it { should exist }
it { should belong_to_group ‘bar’ }
end
Resource
Matcher
13. Docker 101
• Image = Readonly template of a filesystem
• Container = Isolated filesystem and processes
based on an image
• Image filesystem is made up of 1 or more cached
layers
• A container is not a VM!
• Host kernel is shared with containers
15. Why does this matter?
• Spinning up a new container takes very little time
• Faster feedback when testing
• Containers can run inside VMs on hardware that
doesn’t support virtualisation inside VMs
• Images take seconds to update due to caching
'In our world, fast feedback is essential' - @martinfowler
16. Creating a new docker image
Example Dockerfile
FROM ubuntu:15.04
RUN apt-get update
RUN apt-get install sudo openssh-server curl lsb-release -y
From Docker registry
17. Why test at all?
“You are already describing the
desired state of the system in
Ansible, why do it another time?”