puppet camp berlin 2014: advanced puppet design

Download Puppet Camp Berlin 2014: Advanced Puppet Design

Post on 27-Aug-2014

1.237 views

Category:

Software

2 download

Embed Size (px)

DESCRIPTION

"Advanced Puppet Design" presented at Puppet Camp Berlin 2014 by Craig Dunn

TRANSCRIPT

  • Advanced Puppet Design Craig Dunn, Puppet Camp Berlin 2014 Friday, 11 April 14
  • Hello Craig Dunn Puppet user since 2008 Previously worked for Puppet Labs Founder of Enviatics IT automation engineer and trainer Based in Spain but work anywhere Friday, 11 April 14
  • My talk Avoiding pain Writing good modules Challenges of codebase design Roles / Proles Friday, 11 April 14
  • But rst.... Everyone loves polls, right? Friday, 11 April 14
  • Thinking right Business has requirements We use technology to fulll them But its not that simple! Friday, 11 April 14
  • Business logic does not often align with technology design Friday, 11 April 14
  • Business requirement We have 3 applications we need to deploy using Puppet Friday, 11 April 14
  • Puppetize Write 3 Puppet modules for 3 applications Because that was the requirement Was it? Friday, 11 April 14
  • Its not working Friday, 11 April 14
  • Lets suppose Each application is a set of shared components implemented different ways Friday, 11 April 14
  • The business view ApplicationY Application Z Application X Friday, 11 April 14
  • The technical reality ApplicationYApplication Z Application X Friday, 11 April 14
  • Danger Signs Resources being declared in two modules You dont know where your implementation ts Lots of logic at a node level Repetition and duplication The if statement is your go-to-guy Friday, 11 April 14
  • Catastrophic Signs if ($::hostname =~ /^host[0-3].*/) { package { my-special-app: ensure => installed, } } Friday, 11 April 14
  • Catastrophic Signs if !defined(Package[httpd]) { package { httpd: ensure => installed, } } Friday, 11 April 14
  • Catastrophic Signs ensure_resource(package,httpd,{ensure => installed}) Friday, 11 April 14
  • Catastrophic Signs ensure_resource(package,httpd,{ensure => installed}) if function_defined_with_params(["#{type}[#{item}]", params]) Puppet.debug("Resource #{type}[#{item}] not created because it already exists") else Puppet::Parser::Functions.function(:create_resources) function_create_resources([type.capitalize, { item => params }]) end Friday, 11 April 14
  • World ending signs You use parser=future in production You arent regretting it yet You then implemented order=manifest Friday, 11 April 14
  • An unhappy Puppet Friday, 11 April 14
  • Stop thinking about what it looks like Break everything down into components Granularity is the key Think about what it actually is Friday, 11 April 14
  • Writing modules Granularity Portability Flexibility of implementation Friday, 11 April 14
  • A bad moduleclass web { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } package { php5: ensure => installed, require => Package[httpd], } package { mysql-server: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Friday, 11 April 14
  • A bad moduleclass web { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } package { php5: ensure => installed, require => Package[httpd], } package { mysql-server: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Granularity Friday, 11 April 14
  • A bad moduleclass web { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } package { php5: ensure => installed, require => Package[httpd], } package { mysql-server: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Portability Granularity Friday, 11 April 14
  • A bad moduleclass web { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } package { php5: ensure => installed, require => Package[httpd], } package { mysql-server: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Portability Implementation Granularity Friday, 11 April 14
  • Keep your modules granular Manage only resources in the scope of the module Small modules are ok! Friday, 11 April 14
  • A granular module class apache { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Friday, 11 April 14
  • A granular module class apache { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Granularity Friday, 11 April 14
  • A granular module class apache { $docroot=/var/www/sites $listenaddr=10.0.1.10 $servername=myweb.foo.com package { httpd: ensure => installed, } file { /etc/httpd/httpd.conf: ensure => file, content => template(web/httpd.conf.erb), } } Granularity Portability Friday, 11 April 14
  • Sharing is good Re-usable by others in your team You can publish to the forge! People will collaborate Friday, 11 April 14
  • Its all about sharing! Friday, 11 April 14
  • You are gonna share your s**t arent you? Friday, 11 April 14
  • Sharing is not just pull requests Share your ideas in blog posts What worked? What didnt? Discuss and collaborate on mailing lists IRC Friday, 11 April 14
  • Making sharing easier Data separation (Hiera) Allow the user exibility of implementation Friday, 11 April 14
  • defaults params pattern Use a parameterized class Default from an inherited class Allow the user to decide implementation Friday, 11 April 14
  • defaults pattern class apache { $packagename=httpd $docroot=/var/www $listenaddr=10.0.1.12 $servername=myweb.foo.com package { $packagename: ensure => installed, } ..... Friday, 11 April 14
  • defaults pattern class apache { $packagename=httpd $docroot=/var/www $listenaddr=10.0.1.12 $servername=myweb.foo.com package { $packagename: ensure => installed, } ..... In-module private data No way to override Friday, 11 April 14
  • defaults patternclass apache ( $packagename=httpd, $docroot=/var/www, $listenaddr, $servername, ) { package { $packagename: ensure => installed, } ..... Friday, 11 April 14
  • defaults pattern class { apache: listenaddr => 10.0.1.2, servername => foo.example.com, } Override data on implementation Friday, 11 April 14
  • defaults pattern # /etc/puppet/hieradata/dev.yaml --- apache::docroot: /var/dev/sites Overriding from Hiera Friday, 11 April 14
  • defaults pattern class apache::defaults { $packagename=$::osfamily ? { redhat => httpd, debian => apache2, default => httpd, } $docroot=/var/www $listenaddr = $::ipaddress $servername = $::fqdn } ..... Friday, 11 April 14
  • defaults pattern class apache::defaults { $packagename=$::osfamily ? { redhat => httpd, debian => apache2, default => httpd, } $docroot=/var/www $listenaddr = $::ipaddress $servername = $::fqdn } ..... Added logic to defaults Common defaults Friday, 11 April 14
  • def