SlideShare a Scribd company logo
Automated Tests of Ansible code
Klaus.Franken@ing.de
with GitLab, Vagrant, VirtualBox and Ansible
OpenSourceCampAnsible, Berlin, 2019-05-16
Ansible playbooks and roles are code and as any other code it should be tested
automatically before it is applied in production environments. But unit tests are not as usefull
for Ansible code. We need integrations tests with a fresh linux system everytime. We test with
the triple-A concept:
Arrange: boot one or more fresh linux VMs (Vagrant, Virtualbox)
Act: apply Ansible code to test
Assert: test state of the VMs with another Ansible playbook
More topics:
Why testing the Ansible code too?
How to test on every git commit?
Troubles to create a testing environment
Topics from Agenda
2
• ING Germany
• aka “ING–DiBa“
• more an IT company than a bank
• Ansible is used for lot of different jobs
• Jobs in Frankfurt/Nürnberg: 

https://www.ing.jobs/Deutschland/Stellenangebote.htm?keyword=ansible
• Klaus Franken
• Deployment-Pipelines for Java-Apps (Tomcat, JBoss) with Ansible (Tower)
• Ansible since 2014
About
3
Ansible code is CODE!
Every code:
• is buggy
• must be adjusted to environment changes from time to time
We want reusable code (i.e. Ansible shared roles)
⇒ Ansible Code must be tested (automatically) just as application code.
But Ansible code cannot be tested in the same way.
Why testing?
4
because we can ...
The preferred and first step to test application code is using unit tests.
Ansible code is changing infrastructure. So we have to test changing infrastructure. Mocking
is not possible/reasonable.
We need integration tests with real (virtual) infrastructure.
Why testing different?
5
• Ansible code is developped and tried out on existing systems (i.e. VMs).
• Some tools, packages, files and directories are already there – but you don‘t no why. The
dependencies are not obviously.
• When using a role in a new/fresh system you have a lot of „surprises“ (failures).
Test always a reproducible origin
6
• Arrange
• create new VMs with Vagrant and Virtualbox
• Act
• run your Ansible code you want to test
• Assert
• check the result, i.e. with Ansible too
• Automated
• by every commit and/or scheduled
• use gitlab-ci
Idea
7
Triple-A + Automation
• create a gitlab-runner
• install a VM with needed tools for testing:
• ansible
• vagrant
• virtualbox
• install and connect gitlab-runner (see README)
• enable this runner for your project(s) (FIXME: is there a default?)
Automation 1/2
8
with gitlab-ci
https://gitlab.strukturpunkt.de/kfr/ansible_integration_test
Live Demo
9
• create a „.gitlab-ci.yml“ within you repo:
integration_test:
tags:
- vbox
script:
- cd integration_test && ./arrange.sh
Automation 2/2
10
with gitlab-ci
#!/bin/bash
# arrange
ansible-galaxy install -r ../roles/requirements.yml
vagrant up
vagrant ssh-config > ssh_config
# act
ansible-playbook act.yml
# assume
ansible-playbook assume.yml
# cleaning
vagrant destroy -f
Arrange
11
integration_test/arrange.sh
Vagrant.configure("2") do |config|
ENV['LC_ALL']="en_US.UTF-8"
config.vm.define "web" do |web|
web.vm.box = "centos/7"
web.vm.hostname = "web.example.de"
web.vm.provision "ansible" do |ansible|
ansible.playbook = "ping.yml"
ansible.host_key_checking = false
ansible.compatibility_mode = "2.0"
end
web.vm.network "forwarded_port", guest: 80, host: 8042
end
end
Vagrant
12
integration_test/Vagrantfile
• when creating the VM: start an ansible provisioner
• => vagrant create an ansible inventory with port and ssh-key
• let ansible create an ssh-config: vagrant ssh-config > ssh_config
• => regular ssh login with ssh –F ssh_config $server
I just ping the VM and use normal ansible environment for act and assum, because it‘s
easier to develop and debug.
Arrange: vagrant and ssh
13
vagrant know how to ssh into VM, we need this too
• call your ansible playbook and/or your ansible roles
- import_playbook: "../website.yml"
Act
14
integration_test/act.yml
- hosts: web
vars:
ansible_become: false
tasks:
- name: "check index.html"
delegate_to: localhost
uri:
url: http://localhost:8042/
return_content: yes
register: webcontent
failed_when: "'Hello' not in webcontent.content"
- debug:
var: webcontent
Assume
15
integration_test/assume.yml
• create .gitlab-ci.yml
• create integration-test/ from skeleton
• configure:
• Vagrantfile # ports, ressources, more than one VM
• act.yml # call your code to test
• assume.yml # things to test
Developer HowTo
16
steps to be done in git-repo
by every commit
Pros:
• you know exactly wich commit broke the code
• the causer get a note immediatly
Cons:
• commit frequence could be shorter than test duration
• queuing needed
• ressourcen needed
• don‘t find environment changes
Manually:
Cons:
• will be forgotten
Automation: by commit or scheduled or manually?
17
• Vagrantfile can do this
Test a environment with more VMs
18
we need a loop in arrange.sh: arrange, act & assume
Test a role more than one with different parameters
19
Alternatives
20
Assume
• https://serverspec.org/
• https://www.inspec.io/
• InfraSpec
Ansible Testing
• Molecule
• iX 4.2019
• the act-playbooks are a good documentation how to use a role
• the assert-playbooks are a promise, good documentation what you can rely on as a
consumer of a role
performance description for free.
more benefits when testing
21
• integration testing is possible
• integration testing isn‘t too hard
• testing against a reproducible origin
Questions ?
Repo&Slides: https://gitlab.strukturpunkt.de/kfr/ansible_integration_test
klaus.Franken@ing.de
Conclusion
22

More Related Content

What's hot

DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony AlvarezDevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
Anthony Alvarez
 
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
Frank van der Linden
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Codemotion
 
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Michael Lihs
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Michael Lihs
 
Intro to Netflix's Chaos Monkey
Intro to Netflix's Chaos MonkeyIntro to Netflix's Chaos Monkey
Intro to Netflix's Chaos Monkey
Michael Whitehead
 
Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014
Claus Ibsen
 
My Top 5 Favorite Gems
My Top 5 Favorite GemsMy Top 5 Favorite Gems
My Top 5 Favorite Gems
Jimmy Ngu
 
Automate your Development Environment with Vagrant & Chef
Automate your Development Environment with Vagrant & ChefAutomate your Development Environment with Vagrant & Chef
Automate your Development Environment with Vagrant & Chef
Michael Lihs
 
Slim PHP when you don't need the kitchen sink
Slim PHP   when you don't need the kitchen sinkSlim PHP   when you don't need the kitchen sink
Slim PHP when you don't need the kitchen sink
Joe Ferguson
 
Game of Codes: the Battle for CI
Game of Codes: the Battle for CIGame of Codes: the Battle for CI
Game of Codes: the Battle for CI
Atlassian
 
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Codemotion
 
Powering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with VagrantPowering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with Vagrant
Coen Jacobs
 
Codecoon - A technical Case Study
Codecoon - A technical Case StudyCodecoon - A technical Case Study
Codecoon - A technical Case Study
Michael Lihs
 
Microservices with apache_camel_barcelona
Microservices with apache_camel_barcelonaMicroservices with apache_camel_barcelona
Microservices with apache_camel_barcelona
Claus Ibsen
 
Immutable infrastructure:觀念與實作 (建議)
Immutable infrastructure:觀念與實作 (建議)Immutable infrastructure:觀念與實作 (建議)
Immutable infrastructure:觀念與實作 (建議)
William Yeh
 
"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada
Fwdays
 
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ BrnoJenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Vaclav Tunka
 
OpenWhisk
OpenWhiskOpenWhisk
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in Elixir
Pete Gamache
 

What's hot (20)

DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony AlvarezDevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
 
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
 
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
 
Intro to Netflix's Chaos Monkey
Intro to Netflix's Chaos MonkeyIntro to Netflix's Chaos Monkey
Intro to Netflix's Chaos Monkey
 
Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014Apache Camel workshop at BarcelonaJUG in January 2014
Apache Camel workshop at BarcelonaJUG in January 2014
 
My Top 5 Favorite Gems
My Top 5 Favorite GemsMy Top 5 Favorite Gems
My Top 5 Favorite Gems
 
Automate your Development Environment with Vagrant & Chef
Automate your Development Environment with Vagrant & ChefAutomate your Development Environment with Vagrant & Chef
Automate your Development Environment with Vagrant & Chef
 
Slim PHP when you don't need the kitchen sink
Slim PHP   when you don't need the kitchen sinkSlim PHP   when you don't need the kitchen sink
Slim PHP when you don't need the kitchen sink
 
Game of Codes: the Battle for CI
Game of Codes: the Battle for CIGame of Codes: the Battle for CI
Game of Codes: the Battle for CI
 
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
 
Powering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with VagrantPowering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with Vagrant
 
Codecoon - A technical Case Study
Codecoon - A technical Case StudyCodecoon - A technical Case Study
Codecoon - A technical Case Study
 
Microservices with apache_camel_barcelona
Microservices with apache_camel_barcelonaMicroservices with apache_camel_barcelona
Microservices with apache_camel_barcelona
 
Immutable infrastructure:觀念與實作 (建議)
Immutable infrastructure:觀念與實作 (建議)Immutable infrastructure:觀念與實作 (建議)
Immutable infrastructure:觀念與實作 (建議)
 
"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada
 
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ BrnoJenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
 
OpenWhisk
OpenWhiskOpenWhisk
OpenWhisk
 
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in Elixir
 

Similar to OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagrant, VirtualBox and Ansible by Klaus Franken

High Productivity Web Development Workflow
High Productivity Web Development WorkflowHigh Productivity Web Development Workflow
High Productivity Web Development Workflow
Vũ Nguyễn
 
High productivity web development workflow - JavaScript Meetup Saigon 2014
High productivity web development workflow - JavaScript Meetup Saigon 2014High productivity web development workflow - JavaScript Meetup Saigon 2014
High productivity web development workflow - JavaScript Meetup Saigon 2014
Oliver N
 
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Paul Durivage
 
Ansible at work
Ansible at workAnsible at work
Ansible at work
Bas Meijer
 
Jenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipelineJenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipeline
Steffen Gebert
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Amazon Web Services
 
Open source and cross platform .net
Open source and cross platform .netOpen source and cross platform .net
Open source and cross platform .net
Ibon Landa
 
Ansible top 10 - 2018
Ansible top 10 -  2018Ansible top 10 -  2018
Ansible top 10 - 2018
Viresh Doshi
 
ConcourseCi overview
ConcourseCi  overviewConcourseCi  overview
ConcourseCi overview
Gwenn Etourneau
 
Vagrant to-aws-flow
Vagrant to-aws-flowVagrant to-aws-flow
Vagrant to-aws-flow
Kimberly Macias
 
Fake IT, until you make IT
Fake IT, until you make ITFake IT, until you make IT
Fake IT, until you make IT
Bas Meijer
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
Mario-Leander Reimer
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
QAware GmbH
 
CI
CICI
AWS Code Services
AWS Code ServicesAWS Code Services
AWS Code Services
Amazon Web Services
 
Automated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. AnsibleAutomated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. Ansible
Alberto Molina Coballes
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
Dan Vaida
 
CIbox - OpenSource solution for making your #devops better
CIbox - OpenSource solution for making your #devops betterCIbox - OpenSource solution for making your #devops better
CIbox - OpenSource solution for making your #devops better
Andrii Podanenko
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Steffen Gebert
 
Infrastructure testing with Molecule and TestInfra
Infrastructure testing with Molecule and TestInfraInfrastructure testing with Molecule and TestInfra
Infrastructure testing with Molecule and TestInfra
Tomislav Plavcic
 

Similar to OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagrant, VirtualBox and Ansible by Klaus Franken (20)

High Productivity Web Development Workflow
High Productivity Web Development WorkflowHigh Productivity Web Development Workflow
High Productivity Web Development Workflow
 
High productivity web development workflow - JavaScript Meetup Saigon 2014
High productivity web development workflow - JavaScript Meetup Saigon 2014High productivity web development workflow - JavaScript Meetup Saigon 2014
High productivity web development workflow - JavaScript Meetup Saigon 2014
 
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
 
Ansible at work
Ansible at workAnsible at work
Ansible at work
 
Jenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipelineJenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipeline
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
 
Open source and cross platform .net
Open source and cross platform .netOpen source and cross platform .net
Open source and cross platform .net
 
Ansible top 10 - 2018
Ansible top 10 -  2018Ansible top 10 -  2018
Ansible top 10 - 2018
 
ConcourseCi overview
ConcourseCi  overviewConcourseCi  overview
ConcourseCi overview
 
Vagrant to-aws-flow
Vagrant to-aws-flowVagrant to-aws-flow
Vagrant to-aws-flow
 
Fake IT, until you make IT
Fake IT, until you make ITFake IT, until you make IT
Fake IT, until you make IT
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
CI
CICI
CI
 
AWS Code Services
AWS Code ServicesAWS Code Services
AWS Code Services
 
Automated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. AnsibleAutomated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. Ansible
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
CIbox - OpenSource solution for making your #devops better
CIbox - OpenSource solution for making your #devops betterCIbox - OpenSource solution for making your #devops better
CIbox - OpenSource solution for making your #devops better
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
 
Infrastructure testing with Molecule and TestInfra
Infrastructure testing with Molecule and TestInfraInfrastructure testing with Molecule and TestInfra
Infrastructure testing with Molecule and TestInfra
 

Recently uploaded

Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 

Recently uploaded (20)

Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 

OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagrant, VirtualBox and Ansible by Klaus Franken

  • 1. Automated Tests of Ansible code Klaus.Franken@ing.de with GitLab, Vagrant, VirtualBox and Ansible OpenSourceCampAnsible, Berlin, 2019-05-16
  • 2. Ansible playbooks and roles are code and as any other code it should be tested automatically before it is applied in production environments. But unit tests are not as usefull for Ansible code. We need integrations tests with a fresh linux system everytime. We test with the triple-A concept: Arrange: boot one or more fresh linux VMs (Vagrant, Virtualbox) Act: apply Ansible code to test Assert: test state of the VMs with another Ansible playbook More topics: Why testing the Ansible code too? How to test on every git commit? Troubles to create a testing environment Topics from Agenda 2
  • 3. • ING Germany • aka “ING–DiBa“ • more an IT company than a bank • Ansible is used for lot of different jobs • Jobs in Frankfurt/Nürnberg: 
 https://www.ing.jobs/Deutschland/Stellenangebote.htm?keyword=ansible • Klaus Franken • Deployment-Pipelines for Java-Apps (Tomcat, JBoss) with Ansible (Tower) • Ansible since 2014 About 3
  • 4. Ansible code is CODE! Every code: • is buggy • must be adjusted to environment changes from time to time We want reusable code (i.e. Ansible shared roles) ⇒ Ansible Code must be tested (automatically) just as application code. But Ansible code cannot be tested in the same way. Why testing? 4 because we can ...
  • 5. The preferred and first step to test application code is using unit tests. Ansible code is changing infrastructure. So we have to test changing infrastructure. Mocking is not possible/reasonable. We need integration tests with real (virtual) infrastructure. Why testing different? 5
  • 6. • Ansible code is developped and tried out on existing systems (i.e. VMs). • Some tools, packages, files and directories are already there – but you don‘t no why. The dependencies are not obviously. • When using a role in a new/fresh system you have a lot of „surprises“ (failures). Test always a reproducible origin 6
  • 7. • Arrange • create new VMs with Vagrant and Virtualbox • Act • run your Ansible code you want to test • Assert • check the result, i.e. with Ansible too • Automated • by every commit and/or scheduled • use gitlab-ci Idea 7 Triple-A + Automation
  • 8. • create a gitlab-runner • install a VM with needed tools for testing: • ansible • vagrant • virtualbox • install and connect gitlab-runner (see README) • enable this runner for your project(s) (FIXME: is there a default?) Automation 1/2 8 with gitlab-ci
  • 10. • create a „.gitlab-ci.yml“ within you repo: integration_test: tags: - vbox script: - cd integration_test && ./arrange.sh Automation 2/2 10 with gitlab-ci
  • 11. #!/bin/bash # arrange ansible-galaxy install -r ../roles/requirements.yml vagrant up vagrant ssh-config > ssh_config # act ansible-playbook act.yml # assume ansible-playbook assume.yml # cleaning vagrant destroy -f Arrange 11 integration_test/arrange.sh
  • 12. Vagrant.configure("2") do |config| ENV['LC_ALL']="en_US.UTF-8" config.vm.define "web" do |web| web.vm.box = "centos/7" web.vm.hostname = "web.example.de" web.vm.provision "ansible" do |ansible| ansible.playbook = "ping.yml" ansible.host_key_checking = false ansible.compatibility_mode = "2.0" end web.vm.network "forwarded_port", guest: 80, host: 8042 end end Vagrant 12 integration_test/Vagrantfile
  • 13. • when creating the VM: start an ansible provisioner • => vagrant create an ansible inventory with port and ssh-key • let ansible create an ssh-config: vagrant ssh-config > ssh_config • => regular ssh login with ssh –F ssh_config $server I just ping the VM and use normal ansible environment for act and assum, because it‘s easier to develop and debug. Arrange: vagrant and ssh 13 vagrant know how to ssh into VM, we need this too
  • 14. • call your ansible playbook and/or your ansible roles - import_playbook: "../website.yml" Act 14 integration_test/act.yml
  • 15. - hosts: web vars: ansible_become: false tasks: - name: "check index.html" delegate_to: localhost uri: url: http://localhost:8042/ return_content: yes register: webcontent failed_when: "'Hello' not in webcontent.content" - debug: var: webcontent Assume 15 integration_test/assume.yml
  • 16. • create .gitlab-ci.yml • create integration-test/ from skeleton • configure: • Vagrantfile # ports, ressources, more than one VM • act.yml # call your code to test • assume.yml # things to test Developer HowTo 16 steps to be done in git-repo
  • 17. by every commit Pros: • you know exactly wich commit broke the code • the causer get a note immediatly Cons: • commit frequence could be shorter than test duration • queuing needed • ressourcen needed • don‘t find environment changes Manually: Cons: • will be forgotten Automation: by commit or scheduled or manually? 17
  • 18. • Vagrantfile can do this Test a environment with more VMs 18
  • 19. we need a loop in arrange.sh: arrange, act & assume Test a role more than one with different parameters 19
  • 20. Alternatives 20 Assume • https://serverspec.org/ • https://www.inspec.io/ • InfraSpec Ansible Testing • Molecule • iX 4.2019
  • 21. • the act-playbooks are a good documentation how to use a role • the assert-playbooks are a promise, good documentation what you can rely on as a consumer of a role performance description for free. more benefits when testing 21
  • 22. • integration testing is possible • integration testing isn‘t too hard • testing against a reproducible origin Questions ? Repo&Slides: https://gitlab.strukturpunkt.de/kfr/ansible_integration_test klaus.Franken@ing.de Conclusion 22