SlideShare a Scribd company logo
1 of 50
Download to read offline
Modules 201
                       Writing Flexible and Scalable
                                  Puppet


                        Eric Shamow | PuppetCamp NYC

Friday, April 27, 12
Who Am I?
                       • Senior Professional Services Engineer for
                         Puppet Labs
                       • Former Operations Manager
                       • Recovering Sysadmin
                       • Travel around helping people make Puppet
                         even more awesome
                       • Not Shamwow. If you came to the wrong
                         talk you can leave now
Friday, April 27, 12
How Did We Get
                            Here?
                       The module seemed just fine when I wrote
                                        it...




Friday, April 27, 12
How Did We Get
                            Here?
                       The module seemed just fine when I wrote
                                        it...
                         (I never thought RHEL 6 would come out)




Friday, April 27, 12
I never thought...




Friday, April 27, 12
I never thought...
                       • RHEL 6 would come out




Friday, April 27, 12
I never thought...
                       • RHEL 6 would come out
                       • My company would switch to Debian




Friday, April 27, 12
I never thought...
                       • RHEL 6 would come out
                       • My company would switch to Debian
                       • Other people would want to reuse the
                         module




Friday, April 27, 12
I never thought...
                       • RHEL 6 would come out
                       • My company would switch to Debian
                       • Other people would want to reuse the
                         module
                       • I’d want to use only a part of the module


Friday, April 27, 12
I never thought...
                       • RHEL 6 would come out
                       • My company would switch to Debian
                       • Other people would want to reuse the
                         module
                       • I’d want to use only a part of the module
                        • ...maybe as a part of something else

Friday, April 27, 12
Ur Doin It Wrong




Friday, April 27, 12
Puppet is Declarative
                          Shoehorning conditional logic into
                               declarative language?




Friday, April 27, 12
Puppet is Declarative
                          Shoehorning conditional logic into
                               declarative language?
                                Please do not do this:




Friday, April 27, 12
Puppet is Declarative
                           Shoehorning conditional logic into
                                declarative language?
                                 Please do not do this:
                       case $::operatingsystem {
                         ‘redhat’: {
                           if $::fqdn == “bobmarley” {
                              file { ‘foo’:
                                ...
                           } else {
                           ...
                          ...
                       }
Friday, April 27, 12
When Logic Fails




Friday, April 27, 12
Organizing Your Data




Friday, April 27, 12
Organizing Your Data

                       • Hiera




Friday, April 27, 12
Organizing Your Data

                       • Hiera
                       • External Node Classifiers




Friday, April 27, 12
Organizing Your Data

                       • Hiera
                       • External Node Classifiers
                       • Custom Functions




Friday, April 27, 12
Code Models Reality




Friday, April 27, 12
Code Models Reality

                       • Move complexity closer to where it is in
                         real life




Friday, April 27, 12
Code Models Reality

                       • Move complexity closer to where it is in
                         real life
                       • If your CMDB contains lots of
                         exceptions, that’s where you should read
                         from




Friday, April 27, 12
Code Models Reality

                       • Move complexity closer to where it is in
                         real life
                       • If your CMDB contains lots of
                         exceptions, that’s where you should read
                         from
                       • If there is contorted logic, keep it away
                         from nuts and bolts module mechanics



Friday, April 27, 12
Please Don’t Make Me Edit
                   Your Module




Friday, April 27, 12
Parameterized Classes

                         class motd (
                           $pci_enabled = true,
                           $owner       = ‘bob’,
                         ) {
                           ...
                         }




Friday, April 27, 12
params.pp Pattern

                       class motd::params {
                         $owner = ‘Bob’
                       }

                       class motd (
                         $owner = $motd::params::owner
                       ) {



Friday, April 27, 12
params.pp Pattern +
                                hiera

                       class motd::params {
                         $owner = hiera(‘owner’,‘Bob’)
                       }

                       class motd (
                         $owner = $motd::params::owner
                       ) {



Friday, April 27, 12
Outsource Logic to
                          Submodules
    class mysql::params {
      $server_package = $::operatingsystem ? {
        ‘redhat’ => ‘mysql-server’,
        ...
      }
    }

    class mysql::server {
      package { ‘mysql-server’:
        name => $mysql::params::server_package,
        ...
      }
    }
Friday, April 27, 12
Be as Modular as
                           Possible
    class mysql::server {
      package { ‘mysql-server’:
        name => $mysql::params::server_package,
        ...
      }
    }
    class mysql::client {
      ...
    }
    class mysql {
      include mysql::client
      include mysql::server
    }
Friday, April 27, 12
Limit Inheritance




Friday, April 27, 12
Limit Inheritance




Friday, April 27, 12
Limit Inheritance

                       • Favor composition over inheritance




Friday, April 27, 12
Limit Inheritance

                       • Favor composition over inheritance
                       • Inheritance + dynamic variable scoping =
                         PAIN




Friday, April 27, 12
Limit Inheritance

                       • Favor composition over inheritance
                       • Inheritance + dynamic variable scoping =
                         PAIN
                       • Useful at the edges



Friday, April 27, 12
Limit Inheritance

                       • Favor composition over inheritance
                       • Inheritance + dynamic variable scoping =
                         PAIN
                       • Useful at the edges
                       • Useful for overriding/extending in limited
                         circumstances



Friday, April 27, 12
Stop Being Surprised by Change




Friday, April 27, 12
Stop Being Surprised by Change




Friday, April 27, 12
Stop Being Surprised by Change

                       • You don’t have to define every Operating
                         System or version




Friday, April 27, 12
Stop Being Surprised by Change

                       • You don’t have to define every Operating
                         System or version
                       • Assume cutovers won’t be clean - you
                         will be 50% RHEL 5 and 50% RHEL 6 for
                         a while




Friday, April 27, 12
Stop Being Surprised by Change

                       • You don’t have to define every Operating
                         System or version
                       • Assume cutovers won’t be clean - you
                         will be 50% RHEL 5 and 50% RHEL 6 for
                         a while
                       • And even when you aren’t, you’ll be 98%
                         RHEL 6 and 2% RHEL 5 until the end of
                         time.


Friday, April 27, 12
Protect Yourself Against
                        Unintentional Defaults




Friday, April 27, 12
Protect Yourself Against
                        Unintentional Defaults

                       • Always provide a default case




Friday, April 27, 12
Protect Yourself Against
                        Unintentional Defaults

                       • Always provide a default case
                       • In most cases that default case should be
                         failure




Friday, April 27, 12
Protect Yourself Against
                        Unintentional Defaults

                       • Always provide a default case
                       • In most cases that default case should be
                         failure

                       • Use the stdlib :fail method to fail
                         gracefully.




Friday, April 27, 12
Protect Yourself Against
                        Unintentional Defaults


    class mysql::params {
      case $::operatingsystem {
        ‘redhat’: { $serverpkg = ‘mysql-server’ }
        default: {
          fail(‘MySQL Server package undefined.’)
        }
      }
    }



Friday, April 27, 12
Remember
                       You Don’t Have To Think of
                              Everything




Friday, April 27, 12
Remember
                          You Don’t Have To Think of
                                 Everything

                       Leave room for others to improve your modules
                                 without refactoring them...




Friday, April 27, 12
Remember
                          You Don’t Have To Think of
                                 Everything

                       Leave room for others to improve your modules
                                 without refactoring them...

                       ...and then you get to benefit and re-merge their
                                     changes when they do.




Friday, April 27, 12
And then we haz a community!




Friday, April 27, 12
Thank You

                           Eric Shamow
                       eric@puppetlabs.com
                        http://opsrealist.info
                            @eshamow




Friday, April 27, 12

More Related Content

More from Puppet

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyamlPuppet
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)Puppet
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscodePuppet
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twentiesPuppet
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codePuppet
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approachPuppet
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationPuppet
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliancePuppet
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowPuppet
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Puppet
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppetPuppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkPuppet
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping groundPuppet
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy SoftwarePuppet
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User GroupPuppet
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsPuppet
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyPuppet
 

More from Puppet (20)

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyaml
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscode
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approach
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliance
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNow
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden Windows
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael Pinson
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping ground
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User Group
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOps
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 

Writing Flexible and Scalable Puppet Modules

  • 1. Modules 201 Writing Flexible and Scalable Puppet Eric Shamow | PuppetCamp NYC Friday, April 27, 12
  • 2. Who Am I? • Senior Professional Services Engineer for Puppet Labs • Former Operations Manager • Recovering Sysadmin • Travel around helping people make Puppet even more awesome • Not Shamwow. If you came to the wrong talk you can leave now Friday, April 27, 12
  • 3. How Did We Get Here? The module seemed just fine when I wrote it... Friday, April 27, 12
  • 4. How Did We Get Here? The module seemed just fine when I wrote it... (I never thought RHEL 6 would come out) Friday, April 27, 12
  • 6. I never thought... • RHEL 6 would come out Friday, April 27, 12
  • 7. I never thought... • RHEL 6 would come out • My company would switch to Debian Friday, April 27, 12
  • 8. I never thought... • RHEL 6 would come out • My company would switch to Debian • Other people would want to reuse the module Friday, April 27, 12
  • 9. I never thought... • RHEL 6 would come out • My company would switch to Debian • Other people would want to reuse the module • I’d want to use only a part of the module Friday, April 27, 12
  • 10. I never thought... • RHEL 6 would come out • My company would switch to Debian • Other people would want to reuse the module • I’d want to use only a part of the module • ...maybe as a part of something else Friday, April 27, 12
  • 11. Ur Doin It Wrong Friday, April 27, 12
  • 12. Puppet is Declarative Shoehorning conditional logic into declarative language? Friday, April 27, 12
  • 13. Puppet is Declarative Shoehorning conditional logic into declarative language? Please do not do this: Friday, April 27, 12
  • 14. Puppet is Declarative Shoehorning conditional logic into declarative language? Please do not do this: case $::operatingsystem { ‘redhat’: { if $::fqdn == “bobmarley” { file { ‘foo’: ... } else { ... ... } Friday, April 27, 12
  • 15. When Logic Fails Friday, April 27, 12
  • 17. Organizing Your Data • Hiera Friday, April 27, 12
  • 18. Organizing Your Data • Hiera • External Node Classifiers Friday, April 27, 12
  • 19. Organizing Your Data • Hiera • External Node Classifiers • Custom Functions Friday, April 27, 12
  • 21. Code Models Reality • Move complexity closer to where it is in real life Friday, April 27, 12
  • 22. Code Models Reality • Move complexity closer to where it is in real life • If your CMDB contains lots of exceptions, that’s where you should read from Friday, April 27, 12
  • 23. Code Models Reality • Move complexity closer to where it is in real life • If your CMDB contains lots of exceptions, that’s where you should read from • If there is contorted logic, keep it away from nuts and bolts module mechanics Friday, April 27, 12
  • 24. Please Don’t Make Me Edit Your Module Friday, April 27, 12
  • 25. Parameterized Classes class motd ( $pci_enabled = true, $owner = ‘bob’, ) { ... } Friday, April 27, 12
  • 26. params.pp Pattern class motd::params { $owner = ‘Bob’ } class motd ( $owner = $motd::params::owner ) { Friday, April 27, 12
  • 27. params.pp Pattern + hiera class motd::params { $owner = hiera(‘owner’,‘Bob’) } class motd ( $owner = $motd::params::owner ) { Friday, April 27, 12
  • 28. Outsource Logic to Submodules class mysql::params { $server_package = $::operatingsystem ? { ‘redhat’ => ‘mysql-server’, ... } } class mysql::server { package { ‘mysql-server’: name => $mysql::params::server_package, ... } } Friday, April 27, 12
  • 29. Be as Modular as Possible class mysql::server { package { ‘mysql-server’: name => $mysql::params::server_package, ... } } class mysql::client { ... } class mysql { include mysql::client include mysql::server } Friday, April 27, 12
  • 32. Limit Inheritance • Favor composition over inheritance Friday, April 27, 12
  • 33. Limit Inheritance • Favor composition over inheritance • Inheritance + dynamic variable scoping = PAIN Friday, April 27, 12
  • 34. Limit Inheritance • Favor composition over inheritance • Inheritance + dynamic variable scoping = PAIN • Useful at the edges Friday, April 27, 12
  • 35. Limit Inheritance • Favor composition over inheritance • Inheritance + dynamic variable scoping = PAIN • Useful at the edges • Useful for overriding/extending in limited circumstances Friday, April 27, 12
  • 36. Stop Being Surprised by Change Friday, April 27, 12
  • 37. Stop Being Surprised by Change Friday, April 27, 12
  • 38. Stop Being Surprised by Change • You don’t have to define every Operating System or version Friday, April 27, 12
  • 39. Stop Being Surprised by Change • You don’t have to define every Operating System or version • Assume cutovers won’t be clean - you will be 50% RHEL 5 and 50% RHEL 6 for a while Friday, April 27, 12
  • 40. Stop Being Surprised by Change • You don’t have to define every Operating System or version • Assume cutovers won’t be clean - you will be 50% RHEL 5 and 50% RHEL 6 for a while • And even when you aren’t, you’ll be 98% RHEL 6 and 2% RHEL 5 until the end of time. Friday, April 27, 12
  • 41. Protect Yourself Against Unintentional Defaults Friday, April 27, 12
  • 42. Protect Yourself Against Unintentional Defaults • Always provide a default case Friday, April 27, 12
  • 43. Protect Yourself Against Unintentional Defaults • Always provide a default case • In most cases that default case should be failure Friday, April 27, 12
  • 44. Protect Yourself Against Unintentional Defaults • Always provide a default case • In most cases that default case should be failure • Use the stdlib :fail method to fail gracefully. Friday, April 27, 12
  • 45. Protect Yourself Against Unintentional Defaults class mysql::params { case $::operatingsystem { ‘redhat’: { $serverpkg = ‘mysql-server’ } default: { fail(‘MySQL Server package undefined.’) } } } Friday, April 27, 12
  • 46. Remember You Don’t Have To Think of Everything Friday, April 27, 12
  • 47. Remember You Don’t Have To Think of Everything Leave room for others to improve your modules without refactoring them... Friday, April 27, 12
  • 48. Remember You Don’t Have To Think of Everything Leave room for others to improve your modules without refactoring them... ...and then you get to benefit and re-merge their changes when they do. Friday, April 27, 12
  • 49. And then we haz a community! Friday, April 27, 12
  • 50. Thank You Eric Shamow eric@puppetlabs.com http://opsrealist.info @eshamow Friday, April 27, 12