SlideShare a Scribd company logo
1 of 21
Verifying your Ansible
Roles
Feat: Docker, Test Kitchen, Serverspec
About me
Edmund Dipple
edmund.dipple@gmail.com
@elmundio87
Coming up…
• Test Kitchen
• Serverspec
• Ansible
• Docker
• Demo Time!
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
Test Kitchen
• Originally designed for Chef
• Test Harness with simple
workflow
• Pluggable architecture!
Key Concepts
• Drivers <<
• Provisioners
• Platforms
Where to run your code:
Cloud infrastructure
Azure, EC2, Rackspace
Local environment
Vagrant, Docker
Key Concepts
• Drivers
• Provisioners <<
• Platforms
How to configure your environment:
Ansible, Chef, Puppet, CFEngine
Key Concepts
• Drivers
• Provisioners
• Platforms <<
Which OS to spin up:
Can be Linux or Windows if using a
VM
Test Kitchen Workflow
Create
Environments
Config
Management
Run Tests
VerifyConverge
Ansible 101
• SSH-based configuration management
• Idempotent - Test & repair to achieve desired
state
• YML files with loops, conditionals and variables
Example Ansible role
- template:
src: foo.j2
dest: /tmp/foo.sh
- user:
name: “{{item}}”
group: admin
with_items: {{new_user}}
tasks/main.yml
defaults/main.yml
templates/foo.j2
test_var: “Hello world”
new_user: [foo,bar]
#!/bin/bash
echo {{ test_var}}
Tasks
Variables
File Template
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
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
Virtual Machine Docker Container
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
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
Why test at all?
“You are already describing the
desired state of the system in
Ansible, why do it another time?”
Refactoring
Uncoupling testing
from Ansible
People get it wrong!
Installed Software
• Docker 1.8.2 (from package)
• Ansible 1.9.3 (from package)
• test-kitchen (rubygem)
• kitchen-ansible (rubygem)
• serverspec (rubygem)
Demo time!
Questions?

More Related Content

What's hot

Investigation of testing with ansible
Investigation of testing with ansibleInvestigation of testing with ansible
Investigation of testing with ansible
Dennis Rowe
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Simplilearn
 

What's hot (20)

Compliance as Code
Compliance as CodeCompliance as Code
Compliance as Code
 
Continuous infrastructure testing
Continuous infrastructure testingContinuous infrastructure testing
Continuous infrastructure testing
 
Investigation of testing with ansible
Investigation of testing with ansibleInvestigation of testing with ansible
Investigation of testing with ansible
 
Leveraging Ansible for CI/CD
Leveraging Ansible for CI/CDLeveraging Ansible for CI/CD
Leveraging Ansible for CI/CD
 
Test-Driven Infrastructure with Chef
Test-Driven Infrastructure with ChefTest-Driven Infrastructure with Chef
Test-Driven Infrastructure with Chef
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development Workflow
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
 
Automated Infrastructure Testing
Automated Infrastructure TestingAutomated Infrastructure Testing
Automated Infrastructure Testing
 
ZooKeeper - wait free protocol for coordinating processes
ZooKeeper - wait free protocol for coordinating processesZooKeeper - wait free protocol for coordinating processes
ZooKeeper - wait free protocol for coordinating processes
 
How Ansible Makes Automation Easy
How Ansible Makes Automation EasyHow Ansible Makes Automation Easy
How Ansible Makes Automation Easy
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansible
 
Testing servers like software
Testing servers like softwareTesting servers like software
Testing servers like software
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Zero Code Multi-Cloud Automation with Ansible and Terraform
Zero Code Multi-Cloud Automation with Ansible and TerraformZero Code Multi-Cloud Automation with Ansible and Terraform
Zero Code Multi-Cloud Automation with Ansible and Terraform
 
Ansible Case Studies
Ansible Case StudiesAnsible Case Studies
Ansible Case Studies
 
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
 
Ansible Devops North East - slides
Ansible Devops North East - slides Ansible Devops North East - slides
Ansible Devops North East - slides
 
Superb Supervision of Short-lived Servers with Sensu
Superb Supervision of Short-lived Servers with SensuSuperb Supervision of Short-lived Servers with Sensu
Superb Supervision of Short-lived Servers with Sensu
 
Ansible module development 101
Ansible module development 101Ansible module development 101
Ansible module development 101
 
Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch Fix
 

Viewers also liked

Viewers also liked (7)

Ansible
AnsibleAnsible
Ansible
 
Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy Mykhailiuta
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPress
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Sensu + Graphite を1年運⽤してみて #sensucasual
Sensu + Graphite を1年運⽤してみて #sensucasual Sensu + Graphite を1年運⽤してみて #sensucasual
Sensu + Graphite を1年運⽤してみて #sensucasual
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 

Similar to Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec

Fits docker into devops
Fits docker into devopsFits docker into devops
Fits docker into devops
Evans Ye
 

Similar to Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec (20)

Nordic infrastructure Conference 2017 - SQL Server in DevOps
Nordic infrastructure Conference 2017 - SQL Server in DevOpsNordic infrastructure Conference 2017 - SQL Server in DevOps
Nordic infrastructure Conference 2017 - SQL Server in DevOps
 
TurboCharge Your Continuous Delivery Pipeline with Containers - Pop-up Loft
TurboCharge Your Continuous Delivery Pipeline with Containers - Pop-up LoftTurboCharge Your Continuous Delivery Pipeline with Containers - Pop-up Loft
TurboCharge Your Continuous Delivery Pipeline with Containers - Pop-up Loft
 
Building Efficient Parallel Testing Platforms with Docker
Building Efficient Parallel Testing Platforms with DockerBuilding Efficient Parallel Testing Platforms with Docker
Building Efficient Parallel Testing Platforms with Docker
 
(DVO305) Turbocharge YContinuous Deployment Pipeline with Containers
(DVO305) Turbocharge YContinuous Deployment Pipeline with Containers(DVO305) Turbocharge YContinuous Deployment Pipeline with Containers
(DVO305) Turbocharge YContinuous Deployment Pipeline with Containers
 
AWS re:Invent 2016: Development Workflow with Docker and Amazon ECS (CON302)
AWS re:Invent 2016: Development Workflow with Docker and Amazon ECS (CON302)AWS re:Invent 2016: Development Workflow with Docker and Amazon ECS (CON302)
AWS re:Invent 2016: Development Workflow with Docker and Amazon ECS (CON302)
 
Continuous Delivery with Docker and Amazon ECS
Continuous Delivery with Docker and Amazon ECSContinuous Delivery with Docker and Amazon ECS
Continuous Delivery with Docker and Amazon ECS
 
Adf with docker
Adf with dockerAdf with docker
Adf with docker
 
Efficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankEfficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura Frank
 
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
Atmosphere 2018: Yury Tsarev - TEST DRIVEN INFRASTRUCTURE FOR HIGHLY PERFORMI...
 
Introduction to SQL Server in Containers
Introduction to SQL Server in ContainersIntroduction to SQL Server in Containers
Introduction to SQL Server in Containers
 
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container ServicePlay Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
 
Continuous Delivery to Amazon EC2 Container Service
Continuous Delivery to Amazon EC2 Container ServiceContinuous Delivery to Amazon EC2 Container Service
Continuous Delivery to Amazon EC2 Container Service
 
Automated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. AnsibleAutomated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. Ansible
 
Dockerizing OpenStack for High Availability
Dockerizing OpenStack for High AvailabilityDockerizing OpenStack for High Availability
Dockerizing OpenStack for High Availability
 
Fits docker into devops
Fits docker into devopsFits docker into devops
Fits docker into devops
 
Novices guide to docker
Novices guide to dockerNovices guide to docker
Novices guide to docker
 
Containers 101
Containers 101Containers 101
Containers 101
 
Detailed Introduction To Docker
Detailed Introduction To DockerDetailed Introduction To Docker
Detailed Introduction To Docker
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec

  • 1. Verifying your Ansible Roles Feat: Docker, Test Kitchen, Serverspec
  • 3. Coming up… • Test Kitchen • Serverspec • Ansible • Docker • Demo Time!
  • 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
  • 11. Example Ansible role - template: src: foo.j2 dest: /tmp/foo.sh - user: name: “{{item}}” group: admin with_items: {{new_user}} tasks/main.yml defaults/main.yml templates/foo.j2 test_var: “Hello world” new_user: [foo,bar] #!/bin/bash echo {{ test_var}} Tasks Variables File Template
  • 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?”
  • 19. Installed Software • Docker 1.8.2 (from package) • Ansible 1.9.3 (from package) • test-kitchen (rubygem) • kitchen-ansible (rubygem) • serverspec (rubygem)

Editor's Notes

  1. Write tests first, one at a time. Add code in small increments. Commit often while tests still work.
  2. Pluggable arch: Very active github community creating plugins for commonly used config management tools, test frameworks and platforms
  3. 2 commands in test kitchen to orchestrate creating the environment and testing it
  4. Resource: