SlideShare a Scribd company logo
Puppet Camp Sydney
The (im)perfect Puppet module
2AGENDA
Who we are
The common pattern
Pitfalls
Module standards
Module walk-through‘
WHO IS ODECEE?
Innovation for the Enterprise
A digital world where technology is simple
and business gets what it wants
170+ staff
Banking/financial
services
Communications Logistics Insurance Government
Offices in
Melbourne &
Sydney
Digital
DevOps
Sprout is designed to collaborate on new ideas and develop
innovative ‘real world’ solutions.
4WHO WE ARE
PHILIP JAYPETER HALL
•  Ten years industry experience
•  Odecee Lead Engineer
•  Swinburne University Centre for
Astrophysics & Supercomputing
•  realestate.com.au
•  catchoftheday.com.au
@peterkh
•  Eight years industry experience
•  Odecee Senior Engineer
•  Ericsson Mobile Packet Core
•  Softel Systems
•  Puppet certified professional #454
@ps_jay
5
Data
SCOPE
Business logic
goes here
(not sharable)
Node
Role
Profile
No business logic
Sharable on the
Puppet Forge
Class
Module
Hiera
Explicit
Hiera lookups
Automatic
lookups only
Scope of our talk
6
Style guide:
•  v1.1.2: Existed 2011 – 2015
•  v2.0.1: Current 2015 onwards
Guiding principles:
•  Readability matters
•  Scoping and simplicity are key
•  Your module is a piece of
software
Covers writing code but not how to
structure modules
CODE STANDARDS
docs.puppetlabs.com/guides/style_guide.html
7MODULE STANDARDS
Two documents
•  Module fundamentals: covers file-system layout
docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html
•  Beginners guide to modules: step-by-step guide
docs.puppetlabs.com/guides/module_guides/bgtm.html
8
>	
  puppet	
  module	
  generate	
  pcsyd15-­‐foo	
  
	
  
pcsyd15-­‐foo/Gemfile	
  
pcsyd15-­‐foo/metadata.json	
  
pcsyd15-­‐foo/Rakefile	
  
pcsyd15-­‐foo/README.md	
  
pcsyd15-­‐foo/manifests/init.pp	
  
pcsyd15-­‐foo/spec/spec_helper.rb	
  
pcsyd15-­‐foo/spec/classes/init_spec.rb	
  
pcsyd15-­‐foo/tests/init.pp	
  
MODULE SKELETON
9AUTOMATIC PARAMETER LOOKUP
Puppet 3 – automatic lookup
class	
  foo	
  (	
  
	
  	
  param_1,	
  	
  #	
  no	
  default	
  
	
  	
  param_2	
  =	
  “a	
  default”,	
  
)	
  
Since puppet 3, parameters get their value automatically
Explicitly set in a resource-like declaration
Hiera lookup (automatic)
Default provided by class
If no default, catalog compile fails
Equivalent Puppet 2 code
class	
  foo	
  (	
  
	
  	
  param_1	
  =	
  hiera(“foo::param_1”),	
  
	
  	
  param_2	
  =	
  hiera(“foo::param_2”,	
  “a	
  default”)	
  
)	
  
10THE COMMON MODULE PATTERN
params.pp
•  Defaults
•  Handle operating system
differences
init.pp
•  Inherit from params.pp
•  Contain (or anchor) other
subclasses (install,
config, …)
Hiera
config.pp, install.pp, etc.
•  Inherit from init.pp
•  Contained by init.pp
init.pp variables
referenced by all other
classes/defines
puppet-stdlib used for
param validation
Well known Puppet Forge
contributors following this
pattern:
•  puppetlabs
•  example42
•  garethr
11PITFALL #1: Looking up Hiera directly
•  Module less sharable: not all installations use Hiera
•  Harder to debug: more areas of code to identify Hiera
lookups
•  Non-obvious: Module user needs to know all “magic”
Hiera values to set for desired outcome
•  Complex unit testing: Need to feed Hiera values as well
as parameters
12PITFALL #1: Hunting for Hiera lookups
class	
  nginx::params	
  {	
  
	
  	
  $worker_processes	
  =	
  $::processorcount	
  
	
  	
  $worker_connections	
  =	
  ‘1024’	
  
	
  	
  $conf_template	
  =	
  ‘nginx/nginx.conf.erb’	
  
	
  	
  $error_pages_default	
  =	
  false	
  
	
  	
  $set_real_ip	
  =	
  hiera(“nginx::real_ip_range”)	
  
	
  	
  $real_ip_header	
  =	
  ‘X-­‐Forwarded-­‐For’	
  
	
  	
  $blocked_ips	
  =	
  []	
  
	
  	
  $certs	
  =	
  {}	
  
	
  	
  $server_template	
  =	
  'nginx/server-­‐template.conf.erb’	
  
...	
  
13PITFALL #2: Module Scope
•  A module should only have one area of responsibility
•  That module should be the only module with that area of
responsibility
•  Anti-pattern:
•  Apache module for installing httpd
•  MyPHPApp module installs a vhost config in:
/etc/httpd/conf.d/
14PITFALL #3: Dependencies
•  Don’t have “too many” dependencies
•  puppet-stdlib is okay & expected
•  Aim for zero dependencies
•  Testing is more complex: need to include the dependency
•  Module less sharable: now dependent on additional classes
that others may not have
•  From Module Fundamentals:
“Be wary of having classes declare classes from other modules”
15
Example of a class including a class:
#	
  Class	
  for	
  creating	
  the	
  PuppetDB	
  postgresql	
  database	
  
class	
  puppetdb::database::postgresql(	
  
	
  	
  …	
  
)	
  inherits	
  puppetdb::params	
  {	
  
	
  	
  …	
  
	
  	
  #	
  create	
  the	
  puppetdb	
  database	
  
	
  	
  postgresql::server::db	
  {	
  $database_name:	
  
	
  	
  	
  	
  …	
  
	
  	
  }	
  
}	
  
Must also have
puppetlabs-postgresql
module
Alternatively:
•  Document in the README
and then link in a
“profile” class
•  Create module parameter
for inclusion of the
external class
PITFALL #3: puppetlabs-puppetdb
Module Walk-through
puppetlabs-ntp
github.com/puppetlabs/puppetlabs-ntp
CONSIDERATIONS
Anchor pattern or
contain function
needed for classes
inside classes
Hiera needed to
keep profiles and
roles sensible
Puppet version
> 2.6.2 needed for
param inherits
18
Separation between
modules keeps
testing simple
Common patterns
reduces staff
ramp up time
Mix puppet forge
and local modules
with ease
IN SUMMARY
Questions?
@odecee www.facebook.com/odeceesocialwww.odecee.com.au www.linkedin.com/company/odecee
Philip JayPeter Hall
Lead DevOps engineer
@peterkh @ps_jay
Senior DevOps Engineer

More Related Content

PDF
Puppet Camp Melbourne 2014: Puppet and a DevOps Journey (Beginner)
PDF
Puppet camp2021 testing modules and controlrepo
PDF
Puppet for Sys Admins
PDF
Apache Lucene for Java EE Developers
PPTX
Puppetizing Your Organization
PPTX
Creating Developer-Friendly Docker Containers with Chaperone
PDF
2021 04-15 operational verification (with notes)
PDF
Our Puppet Story (GUUG FFG 2015)
Puppet Camp Melbourne 2014: Puppet and a DevOps Journey (Beginner)
Puppet camp2021 testing modules and controlrepo
Puppet for Sys Admins
Apache Lucene for Java EE Developers
Puppetizing Your Organization
Creating Developer-Friendly Docker Containers with Chaperone
2021 04-15 operational verification (with notes)
Our Puppet Story (GUUG FFG 2015)

What's hot (10)

PDF
Implementing your own Google App Engine
PDF
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
PDF
Unbreaking Your Django Application
PDF
Stackato v6
PPTX
Managed Beans: When, Why and How
PDF
How to analyze your codebase with Exakat using Docker - Longhorn PHP
PPTX
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
PPTX
Managing modular software for your nu get, c++ and java development
PPTX
Maven
PDF
Note - Apache Maven Intro
Implementing your own Google App Engine
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
Unbreaking Your Django Application
Stackato v6
Managed Beans: When, Why and How
How to analyze your codebase with Exakat using Docker - Longhorn PHP
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Managing modular software for your nu get, c++ and java development
Maven
Note - Apache Maven Intro
Ad

Viewers also liked (20)

PDF
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
PDF
Using Vagrant, Puppet, Testing & Hadoop
PDF
Puppet Development Workflow
PDF
Devops, Dungeons & Dragons
PDF
Puppet - Configuration Management Made Eas(ier)
PDF
Writing and Publishing Puppet Modules - PuppetConf 2014
PDF
PDF
A Introduction of Packer
PDF
Docker internals
PDF
EC2 AMI Factory with Chef, Berkshelf, and Packer
PPTX
Packer, where DevOps begins
PDF
Docker and Puppet for Continuous Integration
PPTX
C#: Globalization and localization
PDF
Usecase examples of Packer
ODP
Connascence
PDF
Superb Supervision of Short-lived Servers with Sensu
PDF
Puppet Conf 2012 - Managing Network Devices with Puppet
PPT
Deploying puppet code at light speed
KEY
Dates aghhhh!!?!?!?!
PDF
Docker Architecture (v1.3)
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Using Vagrant, Puppet, Testing & Hadoop
Puppet Development Workflow
Devops, Dungeons & Dragons
Puppet - Configuration Management Made Eas(ier)
Writing and Publishing Puppet Modules - PuppetConf 2014
A Introduction of Packer
Docker internals
EC2 AMI Factory with Chef, Berkshelf, and Packer
Packer, where DevOps begins
Docker and Puppet for Continuous Integration
C#: Globalization and localization
Usecase examples of Packer
Connascence
Superb Supervision of Short-lived Servers with Sensu
Puppet Conf 2012 - Managing Network Devices with Puppet
Deploying puppet code at light speed
Dates aghhhh!!?!?!?!
Docker Architecture (v1.3)
Ad

Similar to Puppet Camp Sydney 2015: The (Im)perfect Puppet Module (20)

PDF
From SaltStack to Puppet and beyond...
PDF
Strategies for Puppet code upgrade and refactoring
PDF
Packaging perl (LPW2010)
PPT
Introduction to the intermediate Python - v1.1
PPTX
DrupalCon LA 2015 Review
PDF
Drupal 8 - Core and API Changes
PDF
Reproducibility and automation of machine learning process
PDF
Ottawa Puppet User Group - Publishing a Module on the Puppet Forge
PDF
Puppet: From 0 to 100 in 30 minutes
PDF
Open erp technical_memento_v0.6.3_a4
PDF
Puppet modules: An Holistic Approach
PDF
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
PPTX
Php extensions
PDF
OpenERP Technical Memento
PPTX
Automation using Puppet 3
PDF
Your first d8 module
PDF
Python Tricks That You Can't Live Without
PDF
The State of Puppet - Dan Bode
PDF
Organizing Your PHP Projects (2010 ConFoo)
PDF
Organinzing Your PHP Projects (2010 Memphis PHP)
From SaltStack to Puppet and beyond...
Strategies for Puppet code upgrade and refactoring
Packaging perl (LPW2010)
Introduction to the intermediate Python - v1.1
DrupalCon LA 2015 Review
Drupal 8 - Core and API Changes
Reproducibility and automation of machine learning process
Ottawa Puppet User Group - Publishing a Module on the Puppet Forge
Puppet: From 0 to 100 in 30 minutes
Open erp technical_memento_v0.6.3_a4
Puppet modules: An Holistic Approach
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Php extensions
OpenERP Technical Memento
Automation using Puppet 3
Your first d8 module
Python Tricks That You Can't Live Without
The State of Puppet - Dan Bode
Organizing Your PHP Projects (2010 ConFoo)
Organinzing Your PHP Projects (2010 Memphis PHP)

More from Puppet (20)

PPTX
Puppet Community Day: Planning the Future Together
PPTX
The Evolution of Puppet: Key Changes and Modernization Tips
PPTX
Can You Help Me Upgrade to Puppet 8? Tips, Tools & Best Practices for Your Up...
PPTX
Bolt Dynamic Inventory: Making Puppet Easier
PPTX
Customizing Reporting with the Puppet Report Processor
PPTX
Puppet at ConfigMgmtCamp 2025 Sponsor Deck
PPTX
The State of Puppet in 2025: A Presentation from Developer Relations Lead Dav...
PPTX
Let Red be Red and Green be Green: The Automated Workflow Restarter in GitHub...
PPTX
Puppetcamp r10kyaml
PPTX
Puppet camp vscode
PDF
Modules of the twenties
PDF
Applying Roles and Profiles method to compliance code
PPTX
KGI compliance as-code approach
PDF
Enforce compliance policy with model-driven automation
PDF
Keynote: Puppet camp compliance
PPTX
Automating it management with Puppet + ServiceNow
PPTX
Puppet: The best way to harden Windows
PPTX
Simplified Patch Management with Puppet - Oct. 2020
PPTX
Accelerating azure adoption with puppet
PDF
Puppet catalog Diff; Raphael Pinson
Puppet Community Day: Planning the Future Together
The Evolution of Puppet: Key Changes and Modernization Tips
Can You Help Me Upgrade to Puppet 8? Tips, Tools & Best Practices for Your Up...
Bolt Dynamic Inventory: Making Puppet Easier
Customizing Reporting with the Puppet Report Processor
Puppet at ConfigMgmtCamp 2025 Sponsor Deck
The State of Puppet in 2025: A Presentation from Developer Relations Lead Dav...
Let Red be Red and Green be Green: The Automated Workflow Restarter in GitHub...
Puppetcamp r10kyaml
Puppet camp vscode
Modules of the twenties
Applying Roles and Profiles method to compliance code
KGI compliance as-code approach
Enforce compliance policy with model-driven automation
Keynote: Puppet camp compliance
Automating it management with Puppet + ServiceNow
Puppet: The best way to harden Windows
Simplified Patch Management with Puppet - Oct. 2020
Accelerating azure adoption with puppet
Puppet catalog Diff; Raphael Pinson

Puppet Camp Sydney 2015: The (Im)perfect Puppet Module

  • 1. Puppet Camp Sydney The (im)perfect Puppet module
  • 2. 2AGENDA Who we are The common pattern Pitfalls Module standards Module walk-through‘
  • 3. WHO IS ODECEE? Innovation for the Enterprise A digital world where technology is simple and business gets what it wants 170+ staff Banking/financial services Communications Logistics Insurance Government Offices in Melbourne & Sydney Digital DevOps Sprout is designed to collaborate on new ideas and develop innovative ‘real world’ solutions.
  • 4. 4WHO WE ARE PHILIP JAYPETER HALL •  Ten years industry experience •  Odecee Lead Engineer •  Swinburne University Centre for Astrophysics & Supercomputing •  realestate.com.au •  catchoftheday.com.au @peterkh •  Eight years industry experience •  Odecee Senior Engineer •  Ericsson Mobile Packet Core •  Softel Systems •  Puppet certified professional #454 @ps_jay
  • 5. 5 Data SCOPE Business logic goes here (not sharable) Node Role Profile No business logic Sharable on the Puppet Forge Class Module Hiera Explicit Hiera lookups Automatic lookups only Scope of our talk
  • 6. 6 Style guide: •  v1.1.2: Existed 2011 – 2015 •  v2.0.1: Current 2015 onwards Guiding principles: •  Readability matters •  Scoping and simplicity are key •  Your module is a piece of software Covers writing code but not how to structure modules CODE STANDARDS docs.puppetlabs.com/guides/style_guide.html
  • 7. 7MODULE STANDARDS Two documents •  Module fundamentals: covers file-system layout docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html •  Beginners guide to modules: step-by-step guide docs.puppetlabs.com/guides/module_guides/bgtm.html
  • 8. 8 >  puppet  module  generate  pcsyd15-­‐foo     pcsyd15-­‐foo/Gemfile   pcsyd15-­‐foo/metadata.json   pcsyd15-­‐foo/Rakefile   pcsyd15-­‐foo/README.md   pcsyd15-­‐foo/manifests/init.pp   pcsyd15-­‐foo/spec/spec_helper.rb   pcsyd15-­‐foo/spec/classes/init_spec.rb   pcsyd15-­‐foo/tests/init.pp   MODULE SKELETON
  • 9. 9AUTOMATIC PARAMETER LOOKUP Puppet 3 – automatic lookup class  foo  (      param_1,    #  no  default      param_2  =  “a  default”,   )   Since puppet 3, parameters get their value automatically Explicitly set in a resource-like declaration Hiera lookup (automatic) Default provided by class If no default, catalog compile fails Equivalent Puppet 2 code class  foo  (      param_1  =  hiera(“foo::param_1”),      param_2  =  hiera(“foo::param_2”,  “a  default”)   )  
  • 10. 10THE COMMON MODULE PATTERN params.pp •  Defaults •  Handle operating system differences init.pp •  Inherit from params.pp •  Contain (or anchor) other subclasses (install, config, …) Hiera config.pp, install.pp, etc. •  Inherit from init.pp •  Contained by init.pp init.pp variables referenced by all other classes/defines puppet-stdlib used for param validation Well known Puppet Forge contributors following this pattern: •  puppetlabs •  example42 •  garethr
  • 11. 11PITFALL #1: Looking up Hiera directly •  Module less sharable: not all installations use Hiera •  Harder to debug: more areas of code to identify Hiera lookups •  Non-obvious: Module user needs to know all “magic” Hiera values to set for desired outcome •  Complex unit testing: Need to feed Hiera values as well as parameters
  • 12. 12PITFALL #1: Hunting for Hiera lookups class  nginx::params  {      $worker_processes  =  $::processorcount      $worker_connections  =  ‘1024’      $conf_template  =  ‘nginx/nginx.conf.erb’      $error_pages_default  =  false      $set_real_ip  =  hiera(“nginx::real_ip_range”)      $real_ip_header  =  ‘X-­‐Forwarded-­‐For’      $blocked_ips  =  []      $certs  =  {}      $server_template  =  'nginx/server-­‐template.conf.erb’   ...  
  • 13. 13PITFALL #2: Module Scope •  A module should only have one area of responsibility •  That module should be the only module with that area of responsibility •  Anti-pattern: •  Apache module for installing httpd •  MyPHPApp module installs a vhost config in: /etc/httpd/conf.d/
  • 14. 14PITFALL #3: Dependencies •  Don’t have “too many” dependencies •  puppet-stdlib is okay & expected •  Aim for zero dependencies •  Testing is more complex: need to include the dependency •  Module less sharable: now dependent on additional classes that others may not have •  From Module Fundamentals: “Be wary of having classes declare classes from other modules”
  • 15. 15 Example of a class including a class: #  Class  for  creating  the  PuppetDB  postgresql  database   class  puppetdb::database::postgresql(      …   )  inherits  puppetdb::params  {      …      #  create  the  puppetdb  database      postgresql::server::db  {  $database_name:          …      }   }   Must also have puppetlabs-postgresql module Alternatively: •  Document in the README and then link in a “profile” class •  Create module parameter for inclusion of the external class PITFALL #3: puppetlabs-puppetdb
  • 17. CONSIDERATIONS Anchor pattern or contain function needed for classes inside classes Hiera needed to keep profiles and roles sensible Puppet version > 2.6.2 needed for param inherits
  • 18. 18 Separation between modules keeps testing simple Common patterns reduces staff ramp up time Mix puppet forge and local modules with ease IN SUMMARY
  • 19. Questions? @odecee www.facebook.com/odeceesocialwww.odecee.com.au www.linkedin.com/company/odecee Philip JayPeter Hall Lead DevOps engineer @peterkh @ps_jay Senior DevOps Engineer