SlideShare uma empresa Scribd logo
1 de 23
Ansible Best PracticesTyler Turk – DevOps Engineer at WP Engine
Who am I?
DevOps Engineer at WP Engine
Enjoys Operations, Development,
and long walks on the beach
General Overview
Content Organization
• Follow hierarchy best practices
• Use roles for content
• Simplify your roles
Make it readable; keep it simple
• Always provide a task name
• Always define state
• Over-use comments and white-space
Tag all the things
• Tags help organization
• --skip-tags=tags,to,skip
• --tags=only,run,these,tags
Don’t Repeat Yourself!
• Re-use code when possible
• Leverage jinja2 templating
• Avoid duplication unless
absolutely necessary
Idempotency
What is idempotence?
Idempotence is the property of certain
operations in mathematics and computer
science, that can be applied multiple times
without changing the result beyond the
initial application
Why is idempotency important?
Config Management that lacks idempotency introduces doubt!
• Ensure no changes unless things actually change
• Some idempotency issues can be big issues (> versus >>)
• Hides the real changes in a cloud of doubt
• Reduction in speed if changes are consistently made
• Testing becomes increasingly difficult
Shooting Yourself in the Foot
• Conflicting tasks for differing roles
• Remember: Don’t Repeat Yourself!
• Double check your work
How do we get there?
• Fully understand requirements
• Document required processes and
procedures
• Requirement verification with invested
parties
• Review module docs to ensure it is
idempotent
Some Modules Lacking Idempotency
• Shell module
• Command module
• File module with touch argument
What are changed_when and failed_when?
Templating
Jinja2 – An Introduction
• Python templating language
• Many filters available
(to_nice_json, to_nice_yaml, sort)
• Conditional evaluation on task result
(success, changed, failed, skipped)
Additional Information:
http://docs.ansible.com/playbooks_variables.html#using-variables-about-jinja2
http://jinja.pocoo.org/docs/templates/#builtin-filters
Variables with Jinja2
• Avoid dictionaries if values will change
• Accessible with double curly braces
{{ i_am_a_variable }}
{{ cluster.datacenter }}
• Verify variable definition
{% if cluster.lbmaster is not defined %}
# Potential Error: No lbmaster
{% endif %}
More with Jinja2
• Simple file templating with loops
• Simple file templating with if/else
• Even use variables for file names!
• Iterate through items, globs, and
hashes
Lessons Learned
Lessons Learned
• Long running tasks should run in
screen!
• Leverage the community on IRC
• Validate proper order of operations
• Overly document playbooks and
procedures
More Lessons Learned
• Burn and churn on virtual
instances for additional testing
• Consistency in playbook
development
• Implement actual testing with
ansible-lint and other CI utilities
• Do not merge non-idempotent pull
requests
Questions?
What about testing? That’s next!
References
Ansible Playbook Best Practices
http://docs.ansible.com/playbooks_best_practices.html
Ansible (Real Life) Good Practices
http://www.reinteractive.net/posts/167-ansible-real-life-good-practices
Jinja2 Documentation
http://jinja.pocoo.org/docs/

Mais conteúdo relacionado

Mais procurados

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
 
Investigation of testing with ansible
Investigation of testing with ansibleInvestigation of testing with ansible
Investigation of testing with ansible
Dennis Rowe
 

Mais procurados (20)

Monitor-Driven Development Using Ansible
Monitor-Driven Development Using AnsibleMonitor-Driven Development Using Ansible
Monitor-Driven Development Using Ansible
 
Docker Birtday #5
Docker Birtday #5Docker Birtday #5
Docker Birtday #5
 
DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & Ansible
 
Continuous Testing with Molecule, Ansible, and GitHub Actions
Continuous Testing with Molecule, Ansible, and GitHub ActionsContinuous Testing with Molecule, Ansible, and GitHub Actions
Continuous Testing with Molecule, Ansible, and GitHub Actions
 
Ansible
AnsibleAnsible
Ansible
 
Introduction to ansible galaxy
Introduction to ansible galaxyIntroduction to ansible galaxy
Introduction to ansible galaxy
 
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'
 
Extending ansible
Extending ansibleExtending ansible
Extending ansible
 
Ansible
AnsibleAnsible
Ansible
 
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...
 
Testing Ansible with Jenkins and Docker
Testing Ansible with Jenkins and DockerTesting Ansible with Jenkins and Docker
Testing Ansible with Jenkins and Docker
 
Ansible Case Studies
Ansible Case StudiesAnsible Case Studies
Ansible Case Studies
 
Scaling and Managing Selenium Grid
Scaling and Managing Selenium GridScaling and Managing Selenium Grid
Scaling and Managing Selenium Grid
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL Meetup
 
OSDC2014: Testing Server Infrastructure with #serverspec
OSDC2014: Testing Server Infrastructure with #serverspecOSDC2014: Testing Server Infrastructure with #serverspec
OSDC2014: Testing Server Infrastructure with #serverspec
 
Investigation of testing with ansible
Investigation of testing with ansibleInvestigation of testing with ansible
Investigation of testing with ansible
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Deploying PHP Applications with Ansible
Deploying PHP Applications with AnsibleDeploying PHP Applications with Ansible
Deploying PHP Applications with Ansible
 
Hands on ansible
Hands on ansibleHands on ansible
Hands on ansible
 

Semelhante a Ansible Best Practices - July 30

Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
Einar Ingebrigtsen
 

Semelhante a Ansible Best Practices - July 30 (20)

TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
Clean code
Clean codeClean code
Clean code
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
 
What is this agile thing anyway
What is this agile thing anywayWhat is this agile thing anyway
What is this agile thing anyway
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
Software Engineering in Startups
Software Engineering in StartupsSoftware Engineering in Startups
Software Engineering in Startups
 
Kku2011
Kku2011Kku2011
Kku2011
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
[TDC 2018 - Trilha XP] Feature flags e releases controlados
[TDC 2018 - Trilha XP] Feature flags e releases controlados[TDC 2018 - Trilha XP] Feature flags e releases controlados
[TDC 2018 - Trilha XP] Feature flags e releases controlados
 
TDC2018SP | Trilha UX - Feature flags e Releases controlados
TDC2018SP | Trilha UX - Feature flags e Releases controladosTDC2018SP | Trilha UX - Feature flags e Releases controlados
TDC2018SP | Trilha UX - Feature flags e Releases controlados
 
presentation
presentationpresentation
presentation
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Ansible Best Practices - July 30

  • 1. Ansible Best PracticesTyler Turk – DevOps Engineer at WP Engine
  • 2. Who am I? DevOps Engineer at WP Engine Enjoys Operations, Development, and long walks on the beach
  • 4. Content Organization • Follow hierarchy best practices • Use roles for content • Simplify your roles
  • 5. Make it readable; keep it simple • Always provide a task name • Always define state • Over-use comments and white-space
  • 6. Tag all the things • Tags help organization • --skip-tags=tags,to,skip • --tags=only,run,these,tags
  • 7. Don’t Repeat Yourself! • Re-use code when possible • Leverage jinja2 templating • Avoid duplication unless absolutely necessary
  • 9. What is idempotence? Idempotence is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result beyond the initial application
  • 10. Why is idempotency important? Config Management that lacks idempotency introduces doubt! • Ensure no changes unless things actually change • Some idempotency issues can be big issues (> versus >>) • Hides the real changes in a cloud of doubt • Reduction in speed if changes are consistently made • Testing becomes increasingly difficult
  • 11. Shooting Yourself in the Foot • Conflicting tasks for differing roles • Remember: Don’t Repeat Yourself! • Double check your work
  • 12. How do we get there? • Fully understand requirements • Document required processes and procedures • Requirement verification with invested parties • Review module docs to ensure it is idempotent
  • 13. Some Modules Lacking Idempotency • Shell module • Command module • File module with touch argument
  • 14. What are changed_when and failed_when?
  • 16. Jinja2 – An Introduction • Python templating language • Many filters available (to_nice_json, to_nice_yaml, sort) • Conditional evaluation on task result (success, changed, failed, skipped) Additional Information: http://docs.ansible.com/playbooks_variables.html#using-variables-about-jinja2 http://jinja.pocoo.org/docs/templates/#builtin-filters
  • 17. Variables with Jinja2 • Avoid dictionaries if values will change • Accessible with double curly braces {{ i_am_a_variable }} {{ cluster.datacenter }} • Verify variable definition {% if cluster.lbmaster is not defined %} # Potential Error: No lbmaster {% endif %}
  • 18. More with Jinja2 • Simple file templating with loops • Simple file templating with if/else • Even use variables for file names! • Iterate through items, globs, and hashes
  • 20. Lessons Learned • Long running tasks should run in screen! • Leverage the community on IRC • Validate proper order of operations • Overly document playbooks and procedures
  • 21. More Lessons Learned • Burn and churn on virtual instances for additional testing • Consistency in playbook development • Implement actual testing with ansible-lint and other CI utilities • Do not merge non-idempotent pull requests
  • 23. References Ansible Playbook Best Practices http://docs.ansible.com/playbooks_best_practices.html Ansible (Real Life) Good Practices http://www.reinteractive.net/posts/167-ansible-real-life-good-practices Jinja2 Documentation http://jinja.pocoo.org/docs/