puppetcamp nyc - building scalable modules
DESCRIPTION
Building Puppet modules for scalability, Eric Shamow, PuppetCamp NYC 4/2012TRANSCRIPT
![Page 1: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/1.jpg)
Modules 201
Eric Shamow | PuppetCamp NYC
Writing Flexible and Scalable Puppet
Friday, April 27, 12
![Page 2: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/2.jpg)
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
![Page 3: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/3.jpg)
How Did We Get Here?
The module seemed just fine when I wrote it...
Friday, April 27, 12
![Page 4: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/4.jpg)
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
![Page 5: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/5.jpg)
I never thought...
Friday, April 27, 12
![Page 6: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/6.jpg)
I never thought...
• RHEL 6 would come out
Friday, April 27, 12
![Page 7: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/7.jpg)
I never thought...
• RHEL 6 would come out
• My company would switch to Debian
Friday, April 27, 12
![Page 8: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/8.jpg)
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
![Page 9: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/9.jpg)
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
![Page 10: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/10.jpg)
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
![Page 11: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/11.jpg)
Ur Doin It Wrong
Friday, April 27, 12
![Page 12: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/12.jpg)
Puppet is DeclarativeShoehorning conditional logic into
declarative language?
Friday, April 27, 12
![Page 13: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/13.jpg)
Puppet is DeclarativeShoehorning conditional logic into
declarative language?
Please do not do this:
Friday, April 27, 12
![Page 14: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/14.jpg)
Puppet is DeclarativeShoehorning conditional logic into
declarative language?
Please do not do this:case $::operatingsystem { ‘redhat’: { if $::fqdn == “bobmarley” { file { ‘foo’: ... } else { ... ...}
Friday, April 27, 12
![Page 15: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/15.jpg)
When Logic Fails
Friday, April 27, 12
![Page 16: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/16.jpg)
Organizing Your Data
Friday, April 27, 12
![Page 17: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/17.jpg)
Organizing Your Data
• Hiera
Friday, April 27, 12
![Page 18: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/18.jpg)
Organizing Your Data
• Hiera
• External Node Classifiers
Friday, April 27, 12
![Page 19: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/19.jpg)
Organizing Your Data
• Hiera
• External Node Classifiers
• Custom Functions
Friday, April 27, 12
![Page 20: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/20.jpg)
Code Models Reality
Friday, April 27, 12
![Page 21: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/21.jpg)
Code Models Reality
• Move complexity closer to where it is in real life
Friday, April 27, 12
![Page 22: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/22.jpg)
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
![Page 23: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/23.jpg)
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
![Page 24: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/24.jpg)
Please Don’t Make Me Edit Your Module
Friday, April 27, 12
![Page 25: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/25.jpg)
Parameterized Classes
class motd ( $pci_enabled = true, $owner = ‘bob’,) { ...}
Friday, April 27, 12
![Page 26: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/26.jpg)
params.pp Pattern
class motd::params { $owner = ‘Bob’}
class motd ( $owner = $motd::params::owner) {
Friday, April 27, 12
![Page 27: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/27.jpg)
params.pp Pattern + hiera
class motd::params { $owner = hiera(‘owner’,‘Bob’)}
class motd ( $owner = $motd::params::owner) {
Friday, April 27, 12
![Page 28: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/28.jpg)
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
![Page 29: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/29.jpg)
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
![Page 30: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/30.jpg)
Limit Inheritance
Friday, April 27, 12
![Page 31: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/31.jpg)
Limit Inheritance
Friday, April 27, 12
![Page 32: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/32.jpg)
Limit Inheritance
• Favor composition over inheritance
Friday, April 27, 12
![Page 33: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/33.jpg)
Limit Inheritance
• Favor composition over inheritance
• Inheritance + dynamic variable scoping = PAIN
Friday, April 27, 12
![Page 34: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/34.jpg)
Limit Inheritance
• Favor composition over inheritance
• Inheritance + dynamic variable scoping = PAIN
• Useful at the edges
Friday, April 27, 12
![Page 35: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/35.jpg)
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
![Page 36: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/36.jpg)
Stop Being Surprised by Change
Friday, April 27, 12
![Page 37: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/37.jpg)
Stop Being Surprised by Change
Friday, April 27, 12
![Page 38: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/38.jpg)
• You don’t have to define every Operating System or version
Stop Being Surprised by Change
Friday, April 27, 12
![Page 39: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/39.jpg)
• 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
Stop Being Surprised by Change
Friday, April 27, 12
![Page 40: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/40.jpg)
• 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.
Stop Being Surprised by Change
Friday, April 27, 12
![Page 41: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/41.jpg)
Protect Yourself Against Unintentional Defaults
Friday, April 27, 12
![Page 42: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/42.jpg)
• Always provide a default case
Protect Yourself Against Unintentional Defaults
Friday, April 27, 12
![Page 43: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/43.jpg)
• Always provide a default case
• In most cases that default case should be failure
Protect Yourself Against Unintentional Defaults
Friday, April 27, 12
![Page 44: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/44.jpg)
• Always provide a default case
• In most cases that default case should be failure
• Use the stdlib :fail method to fail gracefully.
Protect Yourself Against Unintentional Defaults
Friday, April 27, 12
![Page 45: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/45.jpg)
Protect Yourself Against Unintentional Defaults
class mysql::params { case $::operatingsystem { ‘redhat’: { $serverpkg = ‘mysql-server’ } default: { fail(‘MySQL Server package undefined.’) } }}
Friday, April 27, 12
![Page 46: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/46.jpg)
RememberYou Don’t Have To Think of
Everything
Friday, April 27, 12
![Page 47: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/47.jpg)
RememberYou Don’t Have To Think of
Everything
Leave room for others to improve your modules without refactoring them...
Friday, April 27, 12
![Page 48: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/48.jpg)
RememberYou 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
![Page 49: PuppetCamp NYC - Building Scalable Modules](https://reader035.vdocument.in/reader035/viewer/2022081403/554f5b3ab4c905c8088b4648/html5/thumbnails/49.jpg)
And then we haz a community!
Friday, April 27, 12