SlideShare ist ein Scribd-Unternehmen logo
1 von 28
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Testing for Infrastructure as Code
A Beginner's Pattern
Presented by: Mike Caspar
Incremental Infrastructure
Coach
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
The Audience?
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Caspar Computer Services Inc.
-- Innovative Solutions since 1984 -
-
Caspar.NET
(5 cities in Canada / 10
years)
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Why am I here?
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
How do we start?
Very basic understanding of Ansible Inventory &
Groups
A sample environment
A starting pattern (The Test/Maintain Loop)
Moving machines between environments
Integrating Testing into the process (TDD for
Infrastructure)
Q & A
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Physical Servers Virtual Servers
Ansible works with both.
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Applications…
Not servers.
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Physical and Virtual Infrastructure
Production
Development
Staging (sort of)
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Inventory - Folders by Application Name
WALDO and GROVER are Application names…
Why is this important ?
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Inventory - Host Location and Types
City
Env.
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Application - Group Variables
---
# Playbook: GROVER_maintain_proxy.yml
# This playbook Maintains the GROVER Application
- name: ensure hosts are setup correctly on proxy servers in yyz
hosts: GROVER_yyz_proxy_staging, GROVER_yyz_proxy_dev, GROVER_yyz_proxy_prod
remote_user: root
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Tests can be attached and versioned along
with a specific version of Infrastructure
(think... testing & rollbacks)
Source Control….
Why ?
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Host Names not IP Addresses !
(virtual machines)
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
group_vars matching basics
Playbook hosts + Inventory + group_vars + --limit
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
group_vars matching basics
Playbook hosts + Inventory + group_vars + --limit
- name: ensure hosts are setup correctly on proxy servers in yyz
hosts: GROVER_yyz_proxy_staging, GROVER_yyz_proxy_dev, GROVER_yyz_proxy_prod
remote_user: root
Playbook
Inventory
group_vars
[GROVER_yyz_proxy_prod]
yyzproxy1.caspar.com
[GROVER_yyz_webservers_prod]
web1.caspar.com
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
The Test/Maintain Loop
_test
(govern)
_maintain
(dev)
_setup
(injected once)
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
The continual loop
( Dev/Test Continuous Loop)
APP_Maintain_serverType.yml
APP_Test_serverType.yml
APP_Maintain_serverType.yml
APP_Test_serverType.yml
The Test/Maintain Loop
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Adding a new Application (in dev/staging first)
APP_maintain_serverType.yml
APP_test_serverType.yml
APP_setup_serverType.yml (injected into loop only once).
APP_test_serverType.yml
The Test/Maintain Loop
( _setup injected only once )
_test
(govern)
_maintain
(dev)
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
---
# Playbook: GROVER_maintain_proxy.yml
# This playbook Maintains the GROVER Application
- name: ensure hosts are setup correctly on proxy servers in yyz
hosts: GROVER_yyz_proxy_staging, GROVER_yyz_proxy_dev, GROVER_yyz_proxy_prod
remote_user: root
roles:
- { role: GROVER-common }
- { role: GROVER-users }
- { role: GROBER-firewalls } tags: ['security'] }
- { role: COMMON-newrelic, state: present, tags: ['monitoring'] }
- { role: COMMON_puppet_agent, state: absent }
- name: ensure hosts are setup correctly on proxy servers in yul
hosts: GROVER_yul_proxy_staging, GROVER_yul_proxy_dev, GROVER_yul_proxy_prod
remote_user: root
roles:
- { role: GROVER-common }
- { role: GROVER-users }
- { role: GROBER-firewalls } tags: ['security'] }
- { role: COMMON-newrelic, state: present, tags: ['monitoring'] }
- { role: COMMON_puppet_agent, state: absent }
Notice the Application Name
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
We decide when a machine is in Dev/Staging/Production
(not physical location)
Production
Development
Staging (sort of)
To move a machine from Staging to Production….
Move it to another Inventory and run APP_maintain_
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
ansible-playbook -i Inventory/GROVER/yyz/dev/GROVER_test_proxy.yml
ansible-playbook -i Inventory/GROVER/yyz/staging/GROVER_test_proxy.yml
ansible-playbook -i Inventory/GROVER/yyz/prod/GROVER_test_proxy.yml
ansible-playbook -i Inventory/GROVER/yyz/dev/GROVER_test_proxy.yml --limit a.host.com
ansible-playbook -i Inventory/GROVER/yyz/staging/GROVER_test_proxy.yml --limit a.host.com
ansible-playbook -i Inventory/GROVER/yyz/prod/GROVER_test_proxy.yml --limit a.host.com
ansible-playbook -i Inventory/GROVER/yyz/dev/GROVER_maintain_proxy.yml
ansible-playbook -i Inventory/GROVER/yyz/staging/GROVER_maintain_proxy.yml
ansible-playbook -i Inventory/GROVER/yyz/prod/GROVER_maintain_proxy.yml
Example commands
White - Dev
Blue - QA/Test
Orange - Governance/Ops
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Be careful of role
defaults
Empty Strings
Length of group_vars tag
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Why test_ instead of --check?
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
TDD - Test Driven Development
(learned from the Software Community)
THINK !
Write a Failing Test
Refactor
Make it Pass
http://www.extremeprogramming.org/rules/testfirst.html
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Why is this a useful way to start?
● New apps are not re-deployed, the machines simply move inventory location
● tests have already run many times
● Testing and Governance work can be done in parallel to development tasks
● Development teams know right away if they broke something before and/or after !
● Ability to use TDD software concepts for hardware
● Infrastructure can contain a version with matching tests
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
T.D.D. concepts for Infrastructure
To truly do Incremental Infrastructure delivery, we must
have an automated way to know that we haven’t broken
something else in the system when we make changes.
The key is finding a method to allow constant evolution of
our code base (infrastructure).
We do not need to reinvent an approach. Test Driven
Development concepts have proven effective in
incremental software delivery and can be re-used
effectively for infrastructure as code..
Mike Caspar, 2016
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Git Repository for Sample Project
Sample project file(s) available here…
https://github.com/MikeCaspar/ansibleFest2016SFO
Mike Caspar, 2016
© Mike Caspar, 2016
Testing for Infrastructure as Code by Mike Caspar
is licenced under an Attribution-ShareAlike 4.0 International licence
Mike Caspar
Incremental Infrastructure Coach
Enterprise agile Coach
email: mike@caspar.com
twitter: @mikecaspar
blog: http://mike-
caspar.blogspot.com

Weitere ähnliche Inhalte

Andere mochten auch

How to increase traffic to your WordPress website.
How to increase traffic to your WordPress website. How to increase traffic to your WordPress website.
How to increase traffic to your WordPress website. Liquis Design
 
Guia De Estudio Digestivo
Guia De Estudio DigestivoGuia De Estudio Digestivo
Guia De Estudio DigestivoLuciana Yohai
 
The State of Facilities at Eastern Region Institutions JUNE16
The State of Facilities at Eastern Region Institutions JUNE16The State of Facilities at Eastern Region Institutions JUNE16
The State of Facilities at Eastern Region Institutions JUNE16Sightlines
 
Charitable Giving and Happiness
Charitable Giving and HappinessCharitable Giving and Happiness
Charitable Giving and HappinessFaircom New York
 
Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...
Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...
Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...Paul Brown
 
xoxooo tkmmm
xoxooo tkmmmxoxooo tkmmm
xoxooo tkmmmceny2
 
Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...
Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...
Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...Dave McClure
 
Practica 2 quimica organica -espol
Practica 2  quimica organica -espolPractica 2  quimica organica -espol
Practica 2 quimica organica -espolLissy Rodriguez
 
William Gross Sues Pimco for Hundreds of Millions
William Gross Sues Pimco for Hundreds of MillionsWilliam Gross Sues Pimco for Hundreds of Millions
William Gross Sues Pimco for Hundreds of MillionsTric Park
 

Andere mochten auch (14)

How to increase traffic to your WordPress website.
How to increase traffic to your WordPress website. How to increase traffic to your WordPress website.
How to increase traffic to your WordPress website.
 
Moving to the Right Side of Safety
Moving to the Right Side of SafetyMoving to the Right Side of Safety
Moving to the Right Side of Safety
 
Guia De Estudio Digestivo
Guia De Estudio DigestivoGuia De Estudio Digestivo
Guia De Estudio Digestivo
 
Latin Dansları
Latin DanslarıLatin Dansları
Latin Dansları
 
The State of Facilities at Eastern Region Institutions JUNE16
The State of Facilities at Eastern Region Institutions JUNE16The State of Facilities at Eastern Region Institutions JUNE16
The State of Facilities at Eastern Region Institutions JUNE16
 
Charitable Giving and Happiness
Charitable Giving and HappinessCharitable Giving and Happiness
Charitable Giving and Happiness
 
Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...
Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...
Challenging our Notions of Learning: Understanding How Web 2.0 Technology Wor...
 
Torque
TorqueTorque
Torque
 
Jvm mbeans jmxtran
Jvm mbeans jmxtranJvm mbeans jmxtran
Jvm mbeans jmxtran
 
xoxooo tkmmm
xoxooo tkmmmxoxooo tkmmm
xoxooo tkmmm
 
Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...
Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...
Ultimate Platform Hotness Smackdown (Twitter, Facebook, iPhone, Native Web / ...
 
God Is Forgiving
God Is ForgivingGod Is Forgiving
God Is Forgiving
 
Practica 2 quimica organica -espol
Practica 2  quimica organica -espolPractica 2  quimica organica -espol
Practica 2 quimica organica -espol
 
William Gross Sues Pimco for Hundreds of Millions
William Gross Sues Pimco for Hundreds of MillionsWilliam Gross Sues Pimco for Hundreds of Millions
William Gross Sues Pimco for Hundreds of Millions
 

Kürzlich hochgeladen

Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIINhPhngng3
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfMahamudul Hasan
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Baileyhlharris
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...amilabibi1
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lodhisaajjda
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalFabian de Rijk
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.thamaeteboho94
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar TrainingKylaCullinane
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatmentnswingard
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...David Celestin
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityHung Le
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...ZurliaSoop
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoKayode Fayemi
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfSkillCertProExams
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxlionnarsimharajumjf
 

Kürzlich hochgeladen (17)

Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptx
 

Testing for infrastructure as code for AnsibleFest 2016

  • 1. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Testing for Infrastructure as Code A Beginner's Pattern Presented by: Mike Caspar Incremental Infrastructure Coach
  • 2. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence The Audience?
  • 3. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Caspar Computer Services Inc. -- Innovative Solutions since 1984 - - Caspar.NET (5 cities in Canada / 10 years)
  • 4. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Why am I here?
  • 5. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence How do we start? Very basic understanding of Ansible Inventory & Groups A sample environment A starting pattern (The Test/Maintain Loop) Moving machines between environments Integrating Testing into the process (TDD for Infrastructure) Q & A
  • 6. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Physical Servers Virtual Servers Ansible works with both.
  • 7. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Applications… Not servers.
  • 8. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Physical and Virtual Infrastructure Production Development Staging (sort of)
  • 9. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Inventory - Folders by Application Name WALDO and GROVER are Application names… Why is this important ?
  • 10. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Inventory - Host Location and Types City Env.
  • 11. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Application - Group Variables --- # Playbook: GROVER_maintain_proxy.yml # This playbook Maintains the GROVER Application - name: ensure hosts are setup correctly on proxy servers in yyz hosts: GROVER_yyz_proxy_staging, GROVER_yyz_proxy_dev, GROVER_yyz_proxy_prod remote_user: root
  • 12. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Tests can be attached and versioned along with a specific version of Infrastructure (think... testing & rollbacks) Source Control…. Why ?
  • 13. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Host Names not IP Addresses ! (virtual machines)
  • 14. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence group_vars matching basics Playbook hosts + Inventory + group_vars + --limit
  • 15. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence group_vars matching basics Playbook hosts + Inventory + group_vars + --limit - name: ensure hosts are setup correctly on proxy servers in yyz hosts: GROVER_yyz_proxy_staging, GROVER_yyz_proxy_dev, GROVER_yyz_proxy_prod remote_user: root Playbook Inventory group_vars [GROVER_yyz_proxy_prod] yyzproxy1.caspar.com [GROVER_yyz_webservers_prod] web1.caspar.com
  • 16. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence The Test/Maintain Loop _test (govern) _maintain (dev) _setup (injected once)
  • 17. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence The continual loop ( Dev/Test Continuous Loop) APP_Maintain_serverType.yml APP_Test_serverType.yml APP_Maintain_serverType.yml APP_Test_serverType.yml The Test/Maintain Loop
  • 18. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Adding a new Application (in dev/staging first) APP_maintain_serverType.yml APP_test_serverType.yml APP_setup_serverType.yml (injected into loop only once). APP_test_serverType.yml The Test/Maintain Loop ( _setup injected only once ) _test (govern) _maintain (dev)
  • 19. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence --- # Playbook: GROVER_maintain_proxy.yml # This playbook Maintains the GROVER Application - name: ensure hosts are setup correctly on proxy servers in yyz hosts: GROVER_yyz_proxy_staging, GROVER_yyz_proxy_dev, GROVER_yyz_proxy_prod remote_user: root roles: - { role: GROVER-common } - { role: GROVER-users } - { role: GROBER-firewalls } tags: ['security'] } - { role: COMMON-newrelic, state: present, tags: ['monitoring'] } - { role: COMMON_puppet_agent, state: absent } - name: ensure hosts are setup correctly on proxy servers in yul hosts: GROVER_yul_proxy_staging, GROVER_yul_proxy_dev, GROVER_yul_proxy_prod remote_user: root roles: - { role: GROVER-common } - { role: GROVER-users } - { role: GROBER-firewalls } tags: ['security'] } - { role: COMMON-newrelic, state: present, tags: ['monitoring'] } - { role: COMMON_puppet_agent, state: absent } Notice the Application Name
  • 20. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence We decide when a machine is in Dev/Staging/Production (not physical location) Production Development Staging (sort of) To move a machine from Staging to Production…. Move it to another Inventory and run APP_maintain_
  • 21. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence ansible-playbook -i Inventory/GROVER/yyz/dev/GROVER_test_proxy.yml ansible-playbook -i Inventory/GROVER/yyz/staging/GROVER_test_proxy.yml ansible-playbook -i Inventory/GROVER/yyz/prod/GROVER_test_proxy.yml ansible-playbook -i Inventory/GROVER/yyz/dev/GROVER_test_proxy.yml --limit a.host.com ansible-playbook -i Inventory/GROVER/yyz/staging/GROVER_test_proxy.yml --limit a.host.com ansible-playbook -i Inventory/GROVER/yyz/prod/GROVER_test_proxy.yml --limit a.host.com ansible-playbook -i Inventory/GROVER/yyz/dev/GROVER_maintain_proxy.yml ansible-playbook -i Inventory/GROVER/yyz/staging/GROVER_maintain_proxy.yml ansible-playbook -i Inventory/GROVER/yyz/prod/GROVER_maintain_proxy.yml Example commands White - Dev Blue - QA/Test Orange - Governance/Ops
  • 22. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Be careful of role defaults Empty Strings Length of group_vars tag
  • 23. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Why test_ instead of --check?
  • 24. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence TDD - Test Driven Development (learned from the Software Community) THINK ! Write a Failing Test Refactor Make it Pass http://www.extremeprogramming.org/rules/testfirst.html
  • 25. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Why is this a useful way to start? ● New apps are not re-deployed, the machines simply move inventory location ● tests have already run many times ● Testing and Governance work can be done in parallel to development tasks ● Development teams know right away if they broke something before and/or after ! ● Ability to use TDD software concepts for hardware ● Infrastructure can contain a version with matching tests
  • 26. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence T.D.D. concepts for Infrastructure To truly do Incremental Infrastructure delivery, we must have an automated way to know that we haven’t broken something else in the system when we make changes. The key is finding a method to allow constant evolution of our code base (infrastructure). We do not need to reinvent an approach. Test Driven Development concepts have proven effective in incremental software delivery and can be re-used effectively for infrastructure as code.. Mike Caspar, 2016
  • 27. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Git Repository for Sample Project Sample project file(s) available here… https://github.com/MikeCaspar/ansibleFest2016SFO Mike Caspar, 2016
  • 28. © Mike Caspar, 2016 Testing for Infrastructure as Code by Mike Caspar is licenced under an Attribution-ShareAlike 4.0 International licence Mike Caspar Incremental Infrastructure Coach Enterprise agile Coach email: mike@caspar.com twitter: @mikecaspar blog: http://mike- caspar.blogspot.com