SlideShare a Scribd company logo
Make your Ansible playbooks
flexible / maintainable / scalable
J E F F G E E R L I N G ( @ G E E R L I N G G U Y)
# A N S I B L E FEST
D E V E L O P E R
A U T H O R
P H O T O G R A P H E R
H O S T E D A PA C H E S O L R
D R U PA L V M &
M A C D E V P L AY B O O K
M E D I A
E C O M M E R C E P L AT F O R M
L E S S O N S L E A R N E D
1. Stay organized
2. Test early and often
3. Simplify, optimize
Make your Ansible playbooks maintainable, flexible, and scalable
S TAY O R G A N I Z E D
Make your Ansible playbooks maintainable, flexible, and scalable
• Playbooks always run from build server















– J E F F G E E R L I N G
“If it's important,
it will be forgotten.”
R E A D M E
1. Purpose
2. Links (CI, docs, issue tracking)
3. Instructions for local testing
S M A L L F I L E S
• < 100 lines per file
• Start by splitting out related tasks with
include_*
• Progress to single-responsibility roles
R O L E S
• Make roles generic
• Share roles among projects
• Contribute to / use from Galaxy?
Make your Ansible playbooks maintainable, flexible, and scalable
Make your Ansible playbooks maintainable, flexible, and scalable
T E S T E A R LY A N D O F T E N
Make your Ansible playbooks maintainable, flexible, and scalable
The Ansible CI Spectrum
• yamllint
• ansible-playbook --syntax-check
• ansible-lint
• molecule test (integration)
• ansible-playbook --check (against prod)
• Parallel infrastructure
• yamllint
• ansible-playbook --syntax-check
• ansible-lint
• molecule test (integration)
• ansible-playbook --check (against prod)
• Parallel infrastructure
increasing
complexity
Make your Ansible playbooks maintainable, flexible, and scalable
• Heed [DEPRECATION WARNING]s
• Read through porting guides
• Disable annoying WARN messages:
• Heed [DEPRECATION WARNING]s
• Read through porting guides
• Disable annoying WARN messages:
- name: Check if firewalld is installed.

command: yum list installed firewalld

args:

warn: no

register: firewalld_installed
• Target latest Ansible release
• Keep CI environment updated
S I M P L I F Y, O P T I M I Z E
S I M P L I F Y, O P T I M I Z E
– J E F F G E E R L I N G
“YAML is not a
programming language.”
Make your Ansible playbooks maintainable, flexible, and scalable
• Prefer simple, flat variables over dicts
• Prefer simple, flat variables over dicts
apache:

startservers: 2

maxclients: 2!
• Prefer simple, flat variables over dicts
apache:

startservers: 2

maxclients: 2!
apache_startservers: 2

apache_maxclients: 250
✅
• Prefer simple, flat variables over dicts
apache:

startservers: 2

maxclients: 2!
apache_startservers: 2

apache_maxclients: 250
✅
S P E E D
• CI is useless if slow
S P E E D
• CI is useless if slow
• Disable gather_facts if not needed
• forks config - fully utilize resources
S P E E D
M O D U L E S
• package - pass list to name instead of a loop
• copy - only for single files or small dirs
• lineinfile - try to switch to template
instead of looping on one file
[defaults]

callback_whitelist = profile_roles, profile_tasks, timer
Monday 10 September 22:31:08 -0500 (0:00:00.851) 0:01:08.824 ******
===============================================================================
geerlingguy.docker ------------------------------------------------------ 9.65s
geerlingguy.security ---------------------------------------------------- 9.33s
geerlingguy.nginx ------------------------------------------------------- 6.65s
geerlingguy.firewall ---------------------------------------------------- 5.39s
geerlingguy.munin-node -------------------------------------------------- 4.51s
copy -------------------------------------------------------------------- 4.34s
geerlingguy.backup ------------------------------------------------------ 4.14s
geerlingguy.htpasswd ---------------------------------------------------- 4.13s
geerlingguy.ntp --------------------------------------------------------- 3.94s
geerlingguy.swap -------------------------------------------------------- 2.71s
template ---------------------------------------------------------------- 2.64s
...
[defaults]

callback_whitelist = profile_roles, profile_tasks, timer
Try other callback plugins!
(my fave: yaml)
L E S S O N S L E A R N E D
1. Stay organized
2. Test early and often
3. Simplify, optimize
T H A N K Y O U !
# A N S I B L E FEST

More Related Content

PDF
HTTPS and Ansible
PPTX
Using ansible vault to protect your secrets
PDF
How Ansible Makes Automation Easy
PDF
Managing sensitive data with Ansible vault
PDF
Testing servers like software
PPTX
Ansible Best Practices - July 30
PDF
Compliance as Code
PDF
Ansible Case Studies
HTTPS and Ansible
Using ansible vault to protect your secrets
How Ansible Makes Automation Easy
Managing sensitive data with Ansible vault
Testing servers like software
Ansible Best Practices - July 30
Compliance as Code
Ansible Case Studies

What's hot (20)

PPTX
Introduction to Ansible - Jan 28 - Austin MeetUp
PDF
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
PDF
Ansible Crash Course
PPTX
Serverspec and Sensu - Testing and Monitoring collide
PDF
Kernelci.org needs you!
PPTX
Monitor-Driven Development Using Ansible
PPTX
OSDC2014: Testing Server Infrastructure with #serverspec
PDF
CI/CD Using Ansible and Jenkins for Infrastructure
PDF
Continuous Updating with VersionEye at code.talks 2014
PPTX
Go Faster with Ansible (PHP meetup)
PPTX
Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec
PDF
Ansible introduction - XX Betabeers Galicia
PPTX
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
PDF
Investigation of testing with ansible
PPTX
Ansible for large scale deployment
PDF
Hacking on WildFly 9
PDF
Inside the Chef Push Jobs Service - ChefConf 2015
PPTX
Monitoring Open Source Databases with Icinga
PDF
High Available Drupal
PDF
Ansible 101 - Presentation at Ansible STL Meetup
Introduction to Ansible - Jan 28 - Austin MeetUp
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
Ansible Crash Course
Serverspec and Sensu - Testing and Monitoring collide
Kernelci.org needs you!
Monitor-Driven Development Using Ansible
OSDC2014: Testing Server Infrastructure with #serverspec
CI/CD Using Ansible and Jenkins for Infrastructure
Continuous Updating with VersionEye at code.talks 2014
Go Faster with Ansible (PHP meetup)
Verifying your Ansible Roles using Docker, Test Kitchen and Serverspec
Ansible introduction - XX Betabeers Galicia
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Investigation of testing with ansible
Ansible for large scale deployment
Hacking on WildFly 9
Inside the Chef Push Jobs Service - ChefConf 2015
Monitoring Open Source Databases with Icinga
High Available Drupal
Ansible 101 - Presentation at Ansible STL Meetup
Ad

Similar to Make your Ansible playbooks maintainable, flexible, and scalable (20)

PDF
Linux Shell Scripting Craftsmanship
PPTX
InSpec For DevOpsDays Amsterdam 2017
PDF
Common Challenges in DevOps Change Management
PPTX
Adding Security to Your Workflow With InSpec - SCaLE17x
PPTX
Ansible as configuration management tool for devops
PPTX
DevSecCon London 2017: Inspec workshop by Mandi Walls
PPTX
InSpec Workshop DevSecCon 2017
PPTX
DevOpsDays InSpec Workshop
PPTX
Ingite Slides for InSpec
PPTX
DevOpsDaysRiga 2017: Mandi Walls - Building security into your workflow with ...
PDF
Ansible - A 'crowd' introduction
PDF
Prescriptive System Security with InSpec
PPTX
Prescriptive Security with InSpec - All Things Open 2019
PPTX
DevOps for database
PPTX
Ceph Deployment at Target: Customer Spotlight
PPTX
Ceph Deployment at Target: Customer Spotlight
PDF
Inspec: Turn your compliance, security, and other policy requirements into au...
PPTX
InSpec - June 2018 at Open28.be
PPTX
InSpec Workflow for DevOpsDays Riga 2017
PDF
Ansible, best practices
Linux Shell Scripting Craftsmanship
InSpec For DevOpsDays Amsterdam 2017
Common Challenges in DevOps Change Management
Adding Security to Your Workflow With InSpec - SCaLE17x
Ansible as configuration management tool for devops
DevSecCon London 2017: Inspec workshop by Mandi Walls
InSpec Workshop DevSecCon 2017
DevOpsDays InSpec Workshop
Ingite Slides for InSpec
DevOpsDaysRiga 2017: Mandi Walls - Building security into your workflow with ...
Ansible - A 'crowd' introduction
Prescriptive System Security with InSpec
Prescriptive Security with InSpec - All Things Open 2019
DevOps for database
Ceph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer Spotlight
Inspec: Turn your compliance, security, and other policy requirements into au...
InSpec - June 2018 at Open28.be
InSpec Workflow for DevOpsDays Riga 2017
Ansible, best practices
Ad

More from Jeff Geerling (20)

PDF
Continuous Testing with Molecule, Ansible, and GitHub Actions
PDF
2020 Drupal Local Development Tools Survey - CMS Philly
PDF
There's a role for that! (AnsibleFest 2019)
PDF
Everything I know about Kubernetes I learned from a Raspberry Pi cluster
PDF
Real World DevOps - Jeff Geerling's NEDCamp 2018 Keynote
PDF
Ansible and Kubernetes
PDF
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
PDF
Drupal VM for Drupal 8 Dev - MidCamp 2017
PDF
ProTips for Staying Sane while Working from Home
PDF
Highly available Drupal on a Raspberry Pi cluster
PDF
Ansible 2 and Ansible Galaxy 2
PDF
High Performance Drupal
PDF
Ansible for Drupal infrastructure and deployments
PDF
Ansible + Drupal: A Fortuitous DevOps Match
PDF
DevOps for Humans - Ansible for Drupal Deployment Victory!
PDF
Drupal 8 - A Brief Introduction
PDF
Server Check.in case study - Drupal and Node.js
PPT
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
PPT
Florissant TIF - Cross Keys Redevelopment
PDF
How to Build a Drupal Module
Continuous Testing with Molecule, Ansible, and GitHub Actions
2020 Drupal Local Development Tools Survey - CMS Philly
There's a role for that! (AnsibleFest 2019)
Everything I know about Kubernetes I learned from a Raspberry Pi cluster
Real World DevOps - Jeff Geerling's NEDCamp 2018 Keynote
Ansible and Kubernetes
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017
ProTips for Staying Sane while Working from Home
Highly available Drupal on a Raspberry Pi cluster
Ansible 2 and Ansible Galaxy 2
High Performance Drupal
Ansible for Drupal infrastructure and deployments
Ansible + Drupal: A Fortuitous DevOps Match
DevOps for Humans - Ansible for Drupal Deployment Victory!
Drupal 8 - A Brief Introduction
Server Check.in case study - Drupal and Node.js
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Florissant TIF - Cross Keys Redevelopment
How to Build a Drupal Module

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PPT
Introduction Database Management System for Course Database
PPTX
Transform Your Business with a Software ERP System
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
AI in Product Development-omnex systems
PPTX
L1 - Introduction to python Backend.pptx
PPTX
CHAPTER 2 - PM Management and IT Context
medical staffing services at VALiNTRY
Introduction Database Management System for Course Database
Transform Your Business with a Software ERP System
Introduction to Artificial Intelligence
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
ISO 45001 Occupational Health and Safety Management System
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How Creative Agencies Leverage Project Management Software.pdf
top salesforce developer skills in 2025.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Operating system designcfffgfgggggggvggggggggg
How to Migrate SBCGlobal Email to Yahoo Easily
AI in Product Development-omnex systems
L1 - Introduction to python Backend.pptx
CHAPTER 2 - PM Management and IT Context

Make your Ansible playbooks maintainable, flexible, and scalable

  • 1. Make your Ansible playbooks flexible / maintainable / scalable J E F F G E E R L I N G ( @ G E E R L I N G G U Y) # A N S I B L E FEST
  • 2. D E V E L O P E R A U T H O R P H O T O G R A P H E R
  • 3. H O S T E D A PA C H E S O L R
  • 4. D R U PA L V M & M A C D E V P L AY B O O K
  • 5. M E D I A E C O M M E R C E P L AT F O R M
  • 6. L E S S O N S L E A R N E D 1. Stay organized 2. Test early and often 3. Simplify, optimize
  • 8. S TAY O R G A N I Z E D
  • 10. • Playbooks always run from build server
 
 
 
 
 
 
 

  • 11. – J E F F G E E R L I N G “If it's important, it will be forgotten.”
  • 12. R E A D M E 1. Purpose 2. Links (CI, docs, issue tracking) 3. Instructions for local testing
  • 13. S M A L L F I L E S • < 100 lines per file • Start by splitting out related tasks with include_* • Progress to single-responsibility roles
  • 14. R O L E S • Make roles generic • Share roles among projects • Contribute to / use from Galaxy?
  • 17. T E S T E A R LY A N D O F T E N
  • 19. The Ansible CI Spectrum
  • 20. • yamllint • ansible-playbook --syntax-check • ansible-lint • molecule test (integration) • ansible-playbook --check (against prod) • Parallel infrastructure
  • 21. • yamllint • ansible-playbook --syntax-check • ansible-lint • molecule test (integration) • ansible-playbook --check (against prod) • Parallel infrastructure increasing complexity
  • 23. • Heed [DEPRECATION WARNING]s • Read through porting guides • Disable annoying WARN messages:
  • 24. • Heed [DEPRECATION WARNING]s • Read through porting guides • Disable annoying WARN messages: - name: Check if firewalld is installed.
 command: yum list installed firewalld
 args:
 warn: no
 register: firewalld_installed
  • 25. • Target latest Ansible release • Keep CI environment updated
  • 26. S I M P L I F Y, O P T I M I Z E
  • 27. S I M P L I F Y, O P T I M I Z E
  • 28. – J E F F G E E R L I N G “YAML is not a programming language.”
  • 30. • Prefer simple, flat variables over dicts
  • 31. • Prefer simple, flat variables over dicts apache:
 startservers: 2
 maxclients: 2!
  • 32. • Prefer simple, flat variables over dicts apache:
 startservers: 2
 maxclients: 2! apache_startservers: 2
 apache_maxclients: 250 ✅
  • 33. • Prefer simple, flat variables over dicts apache:
 startservers: 2
 maxclients: 2! apache_startservers: 2
 apache_maxclients: 250 ✅
  • 34. S P E E D
  • 35. • CI is useless if slow S P E E D
  • 36. • CI is useless if slow • Disable gather_facts if not needed • forks config - fully utilize resources S P E E D
  • 37. M O D U L E S • package - pass list to name instead of a loop • copy - only for single files or small dirs • lineinfile - try to switch to template instead of looping on one file
  • 39. Monday 10 September 22:31:08 -0500 (0:00:00.851) 0:01:08.824 ****** =============================================================================== geerlingguy.docker ------------------------------------------------------ 9.65s geerlingguy.security ---------------------------------------------------- 9.33s geerlingguy.nginx ------------------------------------------------------- 6.65s geerlingguy.firewall ---------------------------------------------------- 5.39s geerlingguy.munin-node -------------------------------------------------- 4.51s copy -------------------------------------------------------------------- 4.34s geerlingguy.backup ------------------------------------------------------ 4.14s geerlingguy.htpasswd ---------------------------------------------------- 4.13s geerlingguy.ntp --------------------------------------------------------- 3.94s geerlingguy.swap -------------------------------------------------------- 2.71s template ---------------------------------------------------------------- 2.64s ... [defaults]
 callback_whitelist = profile_roles, profile_tasks, timer
  • 40. Try other callback plugins! (my fave: yaml)
  • 41. L E S S O N S L E A R N E D 1. Stay organized 2. Test early and often 3. Simplify, optimize
  • 42. T H A N K Y O U ! # A N S I B L E FEST