SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Thinking through code layout
- Tomas Doran

@bobtfish
tdoran@yelp.com
28/11/2013
Lots of great material
• Still takes effort to understand
• More than one right way to do it
• KISS
• Get data out of manifests
• Follow conventions

http://www.slideshare.net/PuppetLabs/modern-module-development-ken-barber-2012-edinburgh-puppet-camp
http://www.slideshare.net/slideshow/embed_code/25536833
https://speakerdeck.com/player/889a6450ee6b0130026036a0670cc949
Modules only!
• No manifests except site.pp
• autoload structure
• Modules work with environments
• Well known higher level reuse patterns! (Later)

All code should be in modules, always - with no exceptions except a site.pp
Be flexible!
• Most important for forge modules!
• For your own modules, KISS
• Allow package install to be overridden!
• Allow service to be not managed!
• Don’t manage users!
Version compatibility
• Puppet 0.x
• … upgrade?
• Puppet 2.7
• Parameterized classes
• Dynamic scope
• Puppet 3.0
• NO dynamic scope
• Data bindings (automatic hiera)
• Puppet 3.3
• Hiera in modules

http://docs.puppetlabs.com/guides/parameterized_classes.html
Dynamic scope
Dynamic scope
NO Dynamic scope
Data binding
Puppet 2.7
Data binding
Puppet 2.7

Puppet 3.x
ARM9
ARM9

?????

Eh? Is that a processor type?
ARM9

Or one of these?
ARM9 - hiera in modules
• In puppet 3.3:
modules/foo/data
modules/foo/data/common.yaml
modules/foo/data/os/Linux.yaml
modules/foo/hiera.yaml

• Doesn’t really affect design if you did it right!

https://github.com/puppetlabs/armatures/blob/master/arm-9.data_in_modules/index.md
Package / File / Service

Starting at the basics….
Package / File / Service

Most modules do something like this. Note the ${module_name} variable for DRY
http://docs.puppetlabs.com/puppet/3/reference/lang_variables.html#parser-set-variables
http://docs.puppetlabs.com/learning/ordering.html#packagefileservice
Metaparameters

http://docs.puppetlabs.com/learning/ordering.html#packagefileservice
Package/Config/Service classes

Putting each component in it’s own class makes dependencies simpler / more declarative
http://www.devco.net/archives/2009/09/28/simple_puppet_module_structure.php
One entry point
• Entry point should always be init.pp:



include foo

!
http://www.devco.net/archives/2009/09/28/simple_puppet_module_structure.php
Externalize dependencies
• Put inter-class dependencies in init.pp

Some people don’t like this (I do), as it makes the dependencies obvious from the entry point you include.
http://www.devco.net/archives/2012/12/13/simple-puppet-module-structure-redux.php
Separate parameters

This is the traditional method, having a ::params class. This is good when you have conditional logic around parameters.
http://docs.puppetlabs.com/puppet/3/reference/lang_classes.html#inheritance
http://docs.puppetlabs.com/guides/parameterized_classes.html#appendix-smart-parameter-defaults
Hiera parameters (2.7)

For simple (non conditional) values, you can just use a hiera lookup.
If you’re shipping to the forge you still need params class, if you’re not you can just use hiera.
Hiera parameters (3.x)

http://docs.puppetlabs.com/puppet/3/reference/lang_classes.html#inheritance
http://docs.puppetlabs.com/guides/parameterized_classes.html#appendix-smart-parameter-defaults
Hiera parameter variance

Data in params.pp is kinda gross. Move it out to common.yaml?
Logic for which key to look in can be embedded in the hiera call (instead of params.pp).
Hiera parameter variance
If your hierarchy includes:
os/%{::operatingsystem}
common
!
You can just use:
foo::package_name
!

If you have ${::operating_system} in your hierarchy, you can do this simpler thing.
Possible to argue this both ways round, but I’d recommend this as it’s more forward compatible (ARM9)
Hiera parameter variance
If your hierarchy includes:
os/%{::operatingsystem}
common
!
You can just use:
foo::package_name
!
Unless it’s a forge module :(

If you’re shipping to the forge, you can’t (sanely) rely on puppet 3.3, and you don’t want to force people to add to
their hieradata - fallback to params.pp
Puppet 3.3
Per module hierarchy:
foo/data/os/%{::operatingsystem}.yaml
foo/data/common.yaml
Use stdlib
• str2bool
• any2array
• ensure_packages
• ensure_resource
• get_module_path
• getparam
• facts.d
• many many more!

https://github.com/puppetlabs/puppetlabs-stdlib
str2bool

• ‘true’ vs true
• All class parameters
• All hiera data
• Other backends may not have
booleans!

https://github.com/puppetlabs/puppetlabs-stdlib
any2array
• Any time you take an array parameter!

https://github.com/puppetlabs/puppetlabs-stdlib
ensure_packages / ensure_resource

!

• Avoids duplicate resources
!
!
!

• Same for generic resources

https://github.com/puppetlabs/puppetlabs-stdlib
Toolkits
• nginx::vhost {}
• docker::run {}
Toolkits
• nginx::vhost {}
• docker::run {}
• create_resources helper
Multiple instances
• May have more than one nginx running!
• This is where it gets complex :)
• Class or define params override hiera
• Default params in foo::bar
• Instance params:

foo::instance::${instance_name}::bar
Toolkits + Multiple instances
getparam (stdlib)

https://github.com/puppetlabs/puppetlabs-stdlib
Toolkits + Multiple instances
Roles and profiles
• Role = node classifier (contains >= 1 profile)
• role::webserver
• Profile = use multiple modules + hiera data
• profile::apache
• profile::tomcat
• Module = Single concern
• apache
• tomcat

http://www.craigdunn.org/2012/05/239/
http://blog.keepingyouhonest.net/?p=443
https://puppetlabs.com/learn/roles-profiles-introduction
tags for overriding

http://docs.puppetlabs.com/puppet/3/reference/lang_resources.html#amending-attributes-with-a-collector
Thanks!
http://www.yelp.com/careers?jvi=ogVTXfwL
Slides will be up shortly at:
http://slideshare.net/bobtfish/

Questions?
$864
Mail: tdoran@yelp.com
Twitter: @bobtfish

Mais conteúdo relacionado

Semelhante a Thinking through code layout - Tomas Doran

Broward drupal d7-omega
Broward drupal d7-omegaBroward drupal d7-omega
Broward drupal d7-omegaJay Epstein
 
Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...
Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...
Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...Anne Nicolas
 
Presentation distro recipes-2013
Presentation distro recipes-2013Presentation distro recipes-2013
Presentation distro recipes-2013olberger
 
Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Anand Sampat
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...Yury Bushmelev
 
CfgMgmtCamp 2023 - Puppet is YAML.pdf
CfgMgmtCamp 2023 - Puppet is YAML.pdfCfgMgmtCamp 2023 - Puppet is YAML.pdf
CfgMgmtCamp 2023 - Puppet is YAML.pdfMartin Alfke
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Emma Jane Hogbin Westby
 
Pure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkPure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkBryan Ollendyke
 
Writing and Sharing Great Modules with the Puppet Forge
Writing and Sharing Great Modules with the Puppet ForgeWriting and Sharing Great Modules with the Puppet Forge
Writing and Sharing Great Modules with the Puppet ForgePuppet
 
SFDX – Myth Buster, Svatopluk Sejkora
SFDX – Myth Buster, Svatopluk SejkoraSFDX – Myth Buster, Svatopluk Sejkora
SFDX – Myth Buster, Svatopluk SejkoraCzechDreamin
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
 
[Nvidia] Extracting Depot Paths Into New Instances of Their Own
[Nvidia] Extracting Depot Paths Into New Instances of Their Own[Nvidia] Extracting Depot Paths Into New Instances of Their Own
[Nvidia] Extracting Depot Paths Into New Instances of Their OwnPerforce
 
Top 5 Hadoop Admin Tasks
Top 5 Hadoop Admin TasksTop 5 Hadoop Admin Tasks
Top 5 Hadoop Admin TasksEdureka!
 
Webinar: Top 5 Hadoop Admin Tasks
Webinar: Top 5 Hadoop Admin TasksWebinar: Top 5 Hadoop Admin Tasks
Webinar: Top 5 Hadoop Admin TasksEdureka!
 

Semelhante a Thinking through code layout - Tomas Doran (20)

Broward drupal d7-omega
Broward drupal d7-omegaBroward drupal d7-omega
Broward drupal d7-omega
 
Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...
Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...
Distro Recipes 2013 : Contribution of RDF metadata for traceability among pro...
 
Presentation distro recipes-2013
Presentation distro recipes-2013Presentation distro recipes-2013
Presentation distro recipes-2013
 
Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...
 
CfgMgmtCamp 2023 - Puppet is YAML.pdf
CfgMgmtCamp 2023 - Puppet is YAML.pdfCfgMgmtCamp 2023 - Puppet is YAML.pdf
CfgMgmtCamp 2023 - Puppet is YAML.pdf
 
Drupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating ModulesDrupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating Modules
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
Drupal Front End PHP
Drupal Front End PHPDrupal Front End PHP
Drupal Front End PHP
 
Demo Sass
Demo SassDemo Sass
Demo Sass
 
Pure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talkPure Speed Drupal 4 Gov talk
Pure Speed Drupal 4 Gov talk
 
Open Platform for AI & ML modeling
Open Platform for AI & ML modelingOpen Platform for AI & ML modeling
Open Platform for AI & ML modeling
 
Writing and Sharing Great Modules with the Puppet Forge
Writing and Sharing Great Modules with the Puppet ForgeWriting and Sharing Great Modules with the Puppet Forge
Writing and Sharing Great Modules with the Puppet Forge
 
SFDX – Myth Buster, Svatopluk Sejkora
SFDX – Myth Buster, Svatopluk SejkoraSFDX – Myth Buster, Svatopluk Sejkora
SFDX – Myth Buster, Svatopluk Sejkora
 
Scalable Automatic Machine Learning with H2O” by Erin LeDell, Chief Machine L...
Scalable Automatic Machine Learning with H2O” by Erin LeDell, Chief Machine L...Scalable Automatic Machine Learning with H2O” by Erin LeDell, Chief Machine L...
Scalable Automatic Machine Learning with H2O” by Erin LeDell, Chief Machine L...
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
[Nvidia] Extracting Depot Paths Into New Instances of Their Own
[Nvidia] Extracting Depot Paths Into New Instances of Their Own[Nvidia] Extracting Depot Paths Into New Instances of Their Own
[Nvidia] Extracting Depot Paths Into New Instances of Their Own
 
Top 5 Hadoop Admin Tasks
Top 5 Hadoop Admin TasksTop 5 Hadoop Admin Tasks
Top 5 Hadoop Admin Tasks
 
Webinar: Top 5 Hadoop Admin Tasks
Webinar: Top 5 Hadoop Admin TasksWebinar: Top 5 Hadoop Admin Tasks
Webinar: Top 5 Hadoop Admin Tasks
 
Inside DocBlox
Inside DocBloxInside DocBlox
Inside DocBlox
 

Último

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Thinking through code layout - Tomas Doran