puppet @ nedap

47
Friday, February 1, 13

Upload: puppet-labs

Post on 29-Nov-2014

1.556 views

Category:

Technology


2 download

DESCRIPTION

Daniele Sluijters, from Nedap Stepping Stone, talks about "Puppet @ Nedap, and a flash-intro to rspec-puppet" at Puppet Camp Ghent 2013.

TRANSCRIPT

Page 1: Puppet @ Nedap

Friday, February 1, 13

Page 2: Puppet @ Nedap

I am:

I work for:

I help:

Daniele Sluijters (daenney)

Nedap Stepping Stone

Developers host and scale their applications

Friday, February 1, 13

Page 3: Puppet @ Nedap

Friday, February 1, 13

Page 4: Puppet @ Nedap

Friday, February 1, 13

Page 5: Puppet @ Nedap

Friday, February 1, 13

Page 6: Puppet @ Nedap

• Catering for everyone’s needs

• From a single codebase...

Departments

Friday, February 1, 13

Page 7: Puppet @ Nedap

So, Puppet...

Friday, February 1, 13

Page 8: Puppet @ Nedap

• Started to backsource our hosting.

• Need for automation to grow quickly.

• Single point of administration.

• Servers bootstrapped through FAI.

• Puppet does the rest.

Why

Friday, February 1, 13

Page 9: Puppet @ Nedap

• Puppet: 0.25 - 2.6.

• Puppet changing at a rapid pace.

• Our manifests growing exponentially.

• Manifests, modules, nodes, argh.

Early days

Friday, February 1, 13

Page 10: Puppet @ Nedap

• Limited knowledge on creating Puppet modules.

• Sparse information on how to create good modules.

• Difficult to separate logic from data.

• Lots and lots of nagios hosts, services and checks.

Growing

Friday, February 1, 13

Page 11: Puppet @ Nedap

© Jose CP, http://www.flickr.com/photos/andvaranaut/1534670848/Friday, February 1, 13

Page 12: Puppet @ Nedap

• Admit you have a problem...

• Take time to fix it!

• Introduce Hiera for data.

• Split modules in small, simple, classes.

• Tests, tests, tests!

Fixing

Friday, February 1, 13

Page 13: Puppet @ Nedap

Devil in the details...

Friday, February 1, 13

Page 14: Puppet @ Nedap

Testing

class  supervisor  {package  {  ‘supervisor’:ensure      =>  latest,

}}

Friday, February 1, 13

Page 15: Puppet @ Nedap

Testing

class  supervisor  {package  {  ‘supervisor’:ensure      =>  latest,

}}

provider  =>  ‘pip’,

Friday, February 1, 13

Page 16: Puppet @ Nedap

Update everything!

class  mysql::server  {package  {  ‘mysql-­‐server’:

ensure  =>  latest,}

}

Friday, February 1, 13

Page 17: Puppet @ Nedap

Update everything!class  puppet::agent  {

package  {  ‘puppet’:ensure  =>  latest,

}}class  puppet::master  {

package  {  ‘puppetmaster’:ensure  =>  latest,

}}

Friday, February 1, 13

Page 18: Puppet @ Nedap

© Joe Mott, http://www.flickr.com/photos/motti82/3778598336/Friday, February 1, 13

Page 19: Puppet @ Nedap

Schedule!schedule  {  'never':

period  =>  ‘never’,}

class  mysql::master  {service  {  ‘mysql’:

schedule  =>  never,}

}

Friday, February 1, 13

Page 20: Puppet @ Nedap

We’ve got issues...

Friday, February 1, 13

Page 21: Puppet @ Nedap

• Not possible to keep everything in one place

• Duplication of data within a single source

Data

Friday, February 1, 13

Page 22: Puppet @ Nedap

• Help people first...

• Then tell them they’re doing it wrong.

Community

Friday, February 1, 13

Page 23: Puppet @ Nedap

• Help people first...

• Then tell them they’re doing it wrong.

Community

• 2.7.0 is the first version of Puppet to support Ruby 1.9.

Friday, February 1, 13

Page 24: Puppet @ Nedap

Nagios

Friday, February 1, 13

Page 25: Puppet @ Nedap

Nagios• Puppet report

• config retrieval: 113.85s

• runtime: 155.21s

Friday, February 1, 13

Page 26: Puppet @ Nedap

Nagios

• time puppet agent --onetime --no-daemonize

• real: 23m 28.201s

• user: 21m 9.239s

• sys: 0m 24.026s

• Puppet report

• config retrieval: 113.85s

• runtime: 155.21s

Friday, February 1, 13

Page 27: Puppet @ Nedap

rspec-puppet

Friday, February 1, 13

Page 28: Puppet @ Nedap

Getting startedsource  :rubygemsgem  'puppet',  '~>  2.7.20'gem  'facter',  '~>  1.6.15'gem  'puppet-­‐lint',  '~>  0.3.2'gem  'rspec-­‐puppet',  '~>  0.1.5'gem  'puppetlabs_spec_helper',  '~>  0.4.0'

Friday, February 1, 13

Page 29: Puppet @ Nedap

Getting started

• Aren’t always up to date

• Not using rspec-­‐puppet-­‐init

• .fixtures.yml with puppetlabs_spec_helper

Friday, February 1, 13

Page 30: Puppet @ Nedap

Scaffolding$ cd  modules/modulename

$ mkdir  -­‐p  spec/{defines,  classes,  functions,  hosts,  fixtures}

$ echo  "require  'puppetlabs_spec_helper/module_spec_helper'"  >  "spec/spec_helper.rb"

$ echo  "require  'puppetlabs_spec_helper/rake_tasks'"  >  "Rakefile"

Friday, February 1, 13

Page 31: Puppet @ Nedap

Scaffolding$  cat  .fixtures.yml

fixtures:    symlinks:        stdlib:  "#{source_dir}/../stdlib"        webapp:  "#{source_dir}"

Friday, February 1, 13

Page 32: Puppet @ Nedap

Testing yoloclass  yolo  {    notic  {  'yolo':  }}

require  'spec_helper'describe  'yolo'  do    it  "should  build"  do        should  contain_class('yolo')    endend

Friday, February 1, 13

Page 33: Puppet @ Nedap

Testing yolorake  specFailures:    1)  yolo  should  build          Failure/Error:  should  contain_class('yolo')          Puppet::Error:              Puppet::Parser::AST::Resource  failed  with  error  ArgumentError:  Invalid  resource  type  notic  at  yolo/manifests/init.pp:40  

#  ./spec/classes/yolo_spec.rb:5Finished  in  0.0809  seconds1  example,  1  failure

Friday, February 1, 13

Page 34: Puppet @ Nedap

Fail fastclass  yolo  (  $param  =  false,  ){    validate_string($param)}

require  'spec_helper'describe  'yolo'  do    it  "should  build"  do        should  contain_class('yolo')    endend

Friday, February 1, 13

Page 35: Puppet @ Nedap

Fail fastrake  specFailures:    1)  yolo  should  build          Failure/Error:  should  contain_class('yolo')          Puppet::Error:              false  is  not  a  string.    It  looks  to  be  a  FalseClass  at  yolo/manifests/init.pp:40

#  ./spec/classes/yolo_spec.rb:5Finished  in  0.0809  seconds1  example,  1  failure

Friday, February 1, 13

Page 36: Puppet @ Nedap

Fail moreclass  yolo  (  $param=false,  ){    validate_string($param)    if  empty($param){        fail(‘Dude,  wth,  empty?!’)    }}

require  'spec_helper'describe  'yolo'  dolet  :params  do  {  :param  =>  ''  }  end    [..]end

Friday, February 1, 13

Page 37: Puppet @ Nedap

Fail morerake  specFailures:    1)  yolo  should  build          Failure/Error:  should  contain_class('yolo')          Puppet::Error:              Dude,  wth,  empty?!  at  yolo/manifests/init.pp:43

#  ./spec/classes/yolo_spec.rb:5Finished  in  0.0809  seconds1  example,  1  failure

Friday, February 1, 13

Page 38: Puppet @ Nedap

Check your validationrequire  'spec_helper'

describe  'yolo'  do    context  'with  invalid  $param  type'  do        let  :params  do  {  :param  =>  {}  }  end        it  "should  break  horribly"  do            expect  {  subject  }.to  raise_error(Puppet::Error,                          /\{\}  is  not  a  string/)        end    endend

Friday, February 1, 13

Page 39: Puppet @ Nedap

Check your validation

rake  spec.

Finished  in  0.08736  seconds1  example,  0  failures

Friday, February 1, 13

Page 40: Puppet @ Nedap

Check your facts

class  yolo(    $param  =  $yolo::params::lol)  inherits  yolo::params  {

   [do  stuff,  like  validation]

}

Friday, February 1, 13

Page 41: Puppet @ Nedap

Check your factsclass  yolo::params  {    case  $::osfamily  {        'Debian':  {            [set  some  really  fancy  variables]        }

       default:  {            fail("\$osfamily  ${::osfamily}  is  not  supported  by  the  yolo  module.")        }    }}

Friday, February 1, 13

Page 42: Puppet @ Nedap

Check your facts    describe  'on  unsupported'  do        let  :facts  do            {  :osfamily  =>  'Little  Red  Riding  Hood'  }        end

       it  'should  fail'  do            expect  {  subject  }.to  raise_error(/osfamily  Little  Red  Riding  Hood  is  not  supported/)        end    end

Friday, February 1, 13

Page 43: Puppet @ Nedap

Check your resources

class  yolo::configs  {    file  {  $f_yolo_default:        #  Template  uses  $interfaces        content  =>  template('yolo/default.erb'),    }}

Friday, February 1, 13

Page 44: Puppet @ Nedap

Check your resources

describe  'yolo::configs'  do    let  :params  do        {  :f_yolo_default  =>  '/etc/default/yolo',}    end

   it  do        should  contain_file('/etc/default  yolo').with_content(/CATS="lol"/)        endend

Friday, February 1, 13

Page 45: Puppet @ Nedap

Matchers

• For every resource: contain_resource()

• For every attribute: with_attr(‘value’)

• Or: with({:attr1  =>  ‘value1’,  :attr2  =>  ‘value2’})

• Check the content:  with_content(regex)

• include_class()

Friday, February 1, 13

Page 46: Puppet @ Nedap

Helpers

•let  :params  do  {  :param  =>  {}  }  end

•let  :facts  do  {  :osfamily  =>  ‘’  }  end

•let  :pre_condition  do  'include  class::we::need'  end

Friday, February 1, 13

Page 47: Puppet @ Nedap

© Vinoth Chandar, http://www.flickr.com/photos/vinothchandar/4278047231/Friday, February 1, 13