Slide 1

Slide 1 text

Ole Michaelis & Sönke Ruempler | Jimdo Make it SOLID Software Architecture for System Administrators

Slide 2

Slide 2 text

OSDC 2014 Ole Michaelis “Open Source Rockstar” @CodeStars github.com/nesQuick codestars.eu

Slide 3

Slide 3 text

OSDC 2014 Sönke Ruempler “Chief Trolling Officer” @s0enke github.com/s0enke ruempler.eu

Slide 4

Slide 4 text

OSDC 2014 Jimdo

Slide 5

Slide 5 text

OSDC 2014 because infrastructure development is neither a Jenga game! S.O.L.I.D

Slide 6

Slide 6 text

OSDC 2014 a little poll! http://images.fineartamerica.com/images-medium-large/live-long-mr-spock-tobias-woelki.jpg

Slide 7

Slide 7 text

OSDC 2014

Slide 8

Slide 8 text

OSDC 2014 S O L I D

Slide 9

Slide 9 text

OSDC 2014 A dev/ops story Ole as Junior Admin Sönke as Dr. Software

Slide 10

Slide 10 text

OSDC 2014 the basics

Slide 11

Slide 11 text

OSDC 2014 configuration management Idempotent Declarative Convergent Abstract

Slide 12

Slide 12 text

OSDC 2014 software architecture VS. 36 years >2000 years

Slide 13

Slide 13 text

OSDC 2014

Slide 14

Slide 14 text

OSDC 2014 node web-1 { $role = 'web-app-a' $has_apache = true; include php5 } node web-2 { $role = 'web-app-b' $has_fcgi=true include php5 } # has both enabled, but needs a special config node web-3 { $role = 'web-app-c' $has_fcgi=true $has_apache=true include php5 } Web App 1 Web App 2 Web App 3

Slide 15

Slide 15 text

OSDC 2014 class php5 { if ($::has_fcgi) package { 'php5-cli' : ensure => installed } } if ($::has_apache) { package { 'php5-apache' : ensure => installed } } if ($::role == 'web-app-c') package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' } } } Global variable! Out of Context! No abstraction

Slide 16

Slide 16 text

OSDC 2014 class php5( $has_fcgi = false, $has_apache = false, $role = undef ) { if ($has_fcgi) package { 'php5-cli' : ensure => installed } } if ($has_apache) { package { 'php5-apache' : ensure => installed } } if ($role == 'web-app-c') { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' , require => Package[php-fcgi] } }

Slide 17

Slide 17 text

OSDC 2014 node 'web-1' { $role = 'web-app-a' $has_apache = true class { 'php5' : has_apache => true, role => 'web-app-a' } } node 'web-2' { $role = 'web-app-b' $has_fcgi = true class { 'php5' : has_fcgi => true, role => 'web-app-b' } } Injection! Injection!

Slide 18

Slide 18 text

OSDC 2014 Would you solder a lamp directly to the electrical wiring in a wall? Dependency Inversion

Slide 19

Slide 19 text

OSDC 2014

Slide 20

Slide 20 text

OSDC 2014 class php5( $has_fcgi = false, $has_apache = false, $role = undef ) { if ($has_fcgi) package { 'php5-cli' : ensure => installed } } if ($has_apache) { package { 'php5-apache' : ensure => installed } } if ($role == 'web-app-c') { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' require => Package[php-fcgi] } } }

Slide 21

Slide 21 text

OSDC 2014 Stuff tends to get big Beware of god classes!

Slide 22

Slide 22 text

OSDC 2014 if ($lighttpd) { package { 'php5-cgi': } configdir { '/etc/php5/cgi': require => Package['php5-cgi'] } configdir { '/etc/php5/cgi/conf.d': require => Package['php5-cgi'] } if ($testserver) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-testserver', require => Package['php5-cgi'] } } else { if ($cms ) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-cms', require => Package['php5-cgi'] } } else { if ($mgmt ) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-mgmt', require => Package['php5-cgi'] } } else { if ($lc ) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-lc. jimdo.com', require => Package['php5-cgi'] } } else { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini', require => Package['php5-cgi'] } } } } } configfile { '/etc/php5/cgi/conf.d/pdo.ini': sourcename => 'php5/cgi/conf.d/pdo.ini', require => Package['php5-cgi'] } }

Slide 23

Slide 23 text

OSDC 2014

Slide 24

Slide 24 text

OSDC 2014 ?

Slide 25

Slide 25 text

OSDC 2014

Slide 26

Slide 26 text

OSDC 2014 rspec-puppet test-kitchen

Slide 27

Slide 27 text

OSDC 2014

Slide 28

Slide 28 text

OSDC 2014 describe :node => 'web-1' do it { should contain_package ('php5-fcgi') } end describe :node => 'web-2' do it { should contain_package ('php5-apache2' ) } end describe :node => 'web-3' do it { should contain_package ('php5-fcgi') } it { should contain_package ('php5-apache2' ) } end Test php5 class: Install Package ?

Slide 29

Slide 29 text

OSDC 2014 describe :class => 'php5::fcgi' do it { should contain_package('php5-cli') } end describe :class => 'php5::apache' do it { should contain_package('php5-apache2') } end class php5::fgci { package { 'php5-cgi' : ensure => installed } } class php5::apache { package { 'php5-apache' : ensure => installed } }

Slide 30

Slide 30 text

OSDC 2014 Just because you can, doesn’t mean you should! Single Responsibility

Slide 31

Slide 31 text

OSDC 2014 describe :node => 'web-1' do it { should include_class('php5::fcgi') } it { should contain_package('php5-fcgi') } end describe :node => 'web-2' do it { should include_class('php5::apache') } it { should contain_package('php5-apache2') } end node web-1 { include php5::apache } node web-2 { include php5::fcgi } Tests Code

Slide 32

Slide 32 text

OSDC 2014

Slide 33

Slide 33 text

OSDC 2014 “programs […] are changed by adding new code, rather than by changing existing code” Open Close Principle

Slide 34

Slide 34 text

OSDC 2014

Slide 35

Slide 35 text

OSDC 2014 new requirements... now web app 1 needs a second node node web-1 { $role = 'web-app-a' include php5::apache } node web-1a { $role = 'web-app-a' include php5::apache }

Slide 36

Slide 36 text

OSDC 2014

Slide 37

Slide 37 text

OSDC 2014

Slide 38

Slide 38 text

OSDC 2014 class role::web-app-a { include php5::apache } node web-1 { include role::web-app- a } node web-1a { include role::web-app- a } Our new role! And nodes just include it!

Slide 39

Slide 39 text

OSDC 2014 >

Slide 40

Slide 40 text

OSDC 2014

Slide 41

Slide 41 text

OSDC 2014 ? class php5::fcgi($role = undef) { if ($role == 'web-app-c') { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c', require => Package[php-fcgi] } } }

Slide 42

Slide 42 text

OSDC 2014 Don’t call us, we call you! Hollywood Principle

Slide 43

Slide 43 text

OSDC 2014 class role::web-app-c::special-php-stuff { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' } } 1. Split out the special case into its own class.

Slide 44

Slide 44 text

OSDC 2014 class php5::fcgi($include_after_package_install = undef) { package { 'php5-fcgi' : ensure => installed } if ($include_after_package_install) include $include_after_package_install Package['php5-fcgi'] -> Class[$include_after_package_install] } } 2. Make the special case pluggable and reusable. 2a. And name it abstract.

Slide 45

Slide 45 text

OSDC 2014 class role::web-app-c { include php5::apache class { 'php5::fcgi' : include_after_package_install => 'profile::web-app-c::special-php-stuff' } } 3. Pass the special case as dependency in our web-app-c.

Slide 46

Slide 46 text

OSDC 2014

Slide 47

Slide 47 text

OSDC 2014 class profile::web-app-c::special-php-stuff { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' } } ?

Slide 48

Slide 48 text

OSDC 2014 define php5::specialconfig( $ensure = present, $sapi, $module, $key, $value, $section = undef, $path = '/etc/php5/%s/conf.d/%s.ini' ) { ini_setting { $title: ensure => $ensure, path => sprintf($path, $sapi, $module), section => $section, setting => $key, value => $value, require => Package["php5-${sapi}"] } }

Slide 49

Slide 49 text

OSDC 2014

Slide 50

Slide 50 text

OSDC 2014 ?

Slide 51

Slide 51 text

OSDC 2014 “puppet separate code and data” I’m feeling lucky

Slide 52

Slide 52 text

OSDC 2014 # /etc/puppet/hieradata/web1.yaml --- classes: - profile::web-app-a # /etc/puppet/hieradata/web1a.yaml --- classes: - profile::web-app-a # /etc/puppet/hieradata/web2.yaml --- classes: - profile::web-app-c # /etc/puppet/hieradata/web3.yaml --- classes: - profile::web-app-c puppet-hiera example in YAML

Slide 53

Slide 53 text

OSDC 2014 node default { hiera_include('classes') } node web-1 { include role::web-app-a } node web-1a { include role::web-app-a } node web-2 { include role::web-app-b } node web-3 { include role::web-app-c }

Slide 54

Slide 54 text

OSDC 2014 hiera AWS/Cloudformation LDAP DNS your selfwritten stuff

Slide 55

Slide 55 text

OSDC 2014

Slide 56

Slide 56 text

OSDC 2014

Slide 57

Slide 57 text

OSDC 2014

Slide 58

Slide 58 text

OSDC 2014 What about I and L in SOLID?

Slide 59

Slide 59 text

OSDC 2014 You want me to plug this in, where? Interface Segregation

Slide 60

Slide 60 text

OSDC 2014 If it looks like a duck, quacks like a duck, but need batteries - you probably have the wrong abstraction! Liskov Substitution

Slide 61

Slide 61 text

OSDC 2014 S O L I D

Slide 62

Slide 62 text

OSDC 2014

Slide 63

Slide 63 text

OSDC 2014 Structure your code! Node Profile Profiles Role Profile Modules Resources

Slide 64

Slide 64 text

OSDC 2014 Puppet forge puppet module registry

Slide 65

Slide 65 text

OSDC 2014 Librarian Puppet r10k Berkshelf (chef)

Slide 66

Slide 66 text

OSDC 2014 stdmod https://github.com/stdmod

Slide 67

Slide 67 text

OSDC 2014 sandboxed development https://github.com/mlafeldt/skeleton-cookbook https://github.com/Jimdo/puppet-skeleton

Slide 68

Slide 68 text

OSDC 2014 server spec http://serverspec.org/ beaker (puppet) https://github.com/puppetlabs/beaker

Slide 69

Slide 69 text

OSDC 2014 Thank you!

Slide 70

Slide 70 text

OSDC 2014 @CodeStars [email protected] @s0enke [email protected] Questions?

Slide 71

Slide 71 text

OSDC 2014 *I ’m just a blank slide*

Slide 72

Slide 72 text

OSDC 2014 Sources • http://www.slideshare.net/PuppetLabs/garethrushgrove-puppetconf • http://www.slideshare.net/PuppetLabs/alessandro-franceschi-new • https://github.com/jedi4ever/stop-the-fork • http://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational- pictures/ • https://speakerdeck.com/jfryman/refactoring-puppet • http://www.clker.com/cliparts/e/2/a/d/1206574733930851359Ryan_Taylor_Green_Tick.svg.med. png • http://www.craigdunn.org/2012/05/239/ • http://cdn.slashgear.com/wp-content/uploads/2012/10/google-datacenter-tech-13.jpg • http://deviq.com/Media/Default/Article/Dont-Call-Us-Well-Call-You-Jun-2013.png • http://www.timeshighereducation.co.uk/Pictures/web/g/q/g/copy_paste_keyboard_button_450.jpg • http://sanremo.com.au/wp-content/uploads/2013/05/lasagna.jpg • http://4.bp.blogspot. com/_9kQQgQD35rY/SaV5p8YBGhI/AAAAAAAAAkg/HOvlhIo7yGI/s400/06_Red_Green_Refactor. JPG • http://www.thelolshop.com/wp-content/uploads/2012/11/20121126-101937.jpg •