Stanford Hackathon (D|N)an - Business Development(d|n)an@puppetlabs.com | #puppet       PuppetLabs - 2012
Overview
Overview
Puppet vs. Scripts• Abstraction• Idempotent• Declarative
Abstraction• Puppet packages:  package { ‘sshd’:    ensure => ‘present’,  }• Packages commands:  yum/rpm  apt/deb  pkgadd/...
Idempotent• Script:  service sshd stop  Stopping sshd:       [ OK ]  service sshd stop  Stopping sshd:       [FAILED]• Pup...
Declarative    Puppet internal                 Puppet user    System state (is):           Desire state (should):service s...
Puppet Resource• Puppet   manifest building block • file • user • package • service • ...
Puppet Resource• puppet   resource <type> [title]
Puppet Manifests•   package { ‘ssh’:      ensure => ‘present’,    }    file { ‘/etc/sshd/sshd_config’:      owner => ‘root’,...
Puppet              Organization                       manifests                       package { sshd:node lisa {         ...
Module          Directories• manifests:    puppet manifests (*.pp)• files:   configuration file• templates:    ERB template (...
Organization
Module    Development• Syntax   Check• Unit   Test• Acceptance    Test• Environment    -> Deploy
Puppet Syntax• puppet   parser validate • git   commit hook • vim   syntastic • geppetto   (eclipse IDE)• puppet   best pr...
Unit Test• puppet   cucumber• rspec-puppet   (Tim Sharpe)
rspec-puppet• verify   resources in catalog• validate   different facts• validate   different parameters
rspec-puppet• rspec-puppet   directory structure:• <module_name>/spec   /classes   /defines   /fixtures      /manifests/site...
rspec-puppet•   #rspec_test/manifests/init.pp    class rspec_test($message = ‘default’) {       notify { $message: }    }•...
Travis CI• Github   integration• Invoke   test on git push• Simple   test matrix
.travis.yml•   language: ruby    before_script:      - git clone git://github.com/puppetlabs/puppetlabs-    stdlib.git spe...
Gemfile•   source :rubygems    puppetversion = ENV.key?(PUPPET_VERSION) ?    "= #{ENV[PUPPET_VERSION]}" : [>= 2.7]    gem p...
Travis CI
Acceptance       Testing• vagrant   box • veewee    (basebox) • http://vagrantbox.es• vagrant   init• vagrant   up• vagran...
Vagrant•   config.vm.provision :puppet do |puppet|     puppet.manifests_path = "manifests"     puppet.manifest_file = "oneir...
Puppet Modules• forge.puppetlabs.com• www.github.com/puppetlabs• Bring   your own module!
Module Projects?• Module    cleanup • puppet-lint     (best practice)• Module    test • rspec    puppet • travis   ci• Mod...
Puppet Projects?• Puppet issues: projects.puppetlabs.com• Puppettools: geppeto puppet-lint rspec-puppet
We are hiring!
We are hiring!
Upcoming SlideShare
Loading in...5
×

Stanford Hackathon - Puppet Modules

2,153

Published on

A quick intro to hacking on Puppet modules from Nan Liu and Dan Bode.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,153
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
81
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Stanford Hackathon - Puppet Modules

    1. 1. Stanford Hackathon (D|N)an - Business Development(d|n)an@puppetlabs.com | #puppet PuppetLabs - 2012
    2. 2. Overview
    3. 3. Overview
    4. 4. Puppet vs. Scripts• Abstraction• Idempotent• Declarative
    5. 5. Abstraction• Puppet packages: package { ‘sshd’: ensure => ‘present’, }• Packages commands: yum/rpm apt/deb pkgadd/pkgutil gem ...
    6. 6. Idempotent• Script: service sshd stop Stopping sshd: [ OK ] service sshd stop Stopping sshd: [FAILED]• Puppet: puppet resource service sshd ensure=stopped ... notice: /Service[sshd]/ensure: ensure changed running to stopped puppet resource service sshd ensure=stopped ...
    7. 7. Declarative Puppet internal Puppet user System state (is): Desire state (should):service sshd status service { sshd: ensure => running, } system == desire No noop? No Remedy (sync): Reportservice sshd start
    8. 8. Puppet Resource• Puppet manifest building block • file • user • package • service • ...
    9. 9. Puppet Resource• puppet resource <type> [title]
    10. 10. Puppet Manifests• package { ‘ssh’: ensure => ‘present’, } file { ‘/etc/sshd/sshd_config’: owner => ‘root’, group => ‘root’, mode => ‘0600’, source => ‘puppet:///modules/sshd/sshd_config’, require => Package[‘ssh’], } service { ‘sshd’: ensure => ‘running’, subscribe => File[‘/etc/sshd/ssd_config’], }
    11. 11. Puppet Organization manifests package { sshd:node lisa { ensure => latest, class {lisa { { } node "ssh": class ssh { }} class {lisa node "ssh": } class ssh { … } class { "ssh": } } … } } file { sshd_config: source => "puppet:///..." site.pp } files native resource (ruby) # sshd_config,v 1.81 # # sshd_config,v 1.81 This is the sshd server # This is the sshd server system-wide configuration system-wide configuration ssh::root_key { … key => "AAAA…" … } ssh module define resource (puppet)
    12. 12. Module Directories• manifests: puppet manifests (*.pp)• files: configuration file• templates: ERB template (*.erb)• lib: ruby (*.rb)• tests: puppet unit testing (*.pp)
    13. 13. Organization
    14. 14. Module Development• Syntax Check• Unit Test• Acceptance Test• Environment -> Deploy
    15. 15. Puppet Syntax• puppet parser validate • git commit hook • vim syntastic • geppetto (eclipse IDE)• puppet best practice • puppet-lint
    16. 16. Unit Test• puppet cucumber• rspec-puppet (Tim Sharpe)
    17. 17. rspec-puppet• verify resources in catalog• validate different facts• validate different parameters
    18. 18. rspec-puppet• rspec-puppet directory structure:• <module_name>/spec /classes /defines /fixtures /manifests/site.pp
    19. 19. rspec-puppet• #rspec_test/manifests/init.pp class rspec_test($message = ‘default’) { notify { $message: } }• #rspec_test/spec/rspec_test_spec.rb describe rspec_test do describe with default parameters do it { should contain_notify(default) } end describe when overriding message do let :params do {:message => override} end it { should contain_notify(override) } end end
    20. 20. Travis CI• Github integration• Invoke test on git push• Simple test matrix
    21. 21. .travis.yml• language: ruby before_script: - git clone git://github.com/puppetlabs/puppetlabs- stdlib.git spec/fixtures/modules/stdlib rvm: - 1.8.7 - 1.9.2 script: "rake spec" env: - PUPPET_VERSION=2.6.12 - PUPPET_VERSION=2.7.12 matrix: exclude: - rvm: 1.9.2 env: PUPPET_VERSION=2.6.12
    22. 22. Gemfile• source :rubygems puppetversion = ENV.key?(PUPPET_VERSION) ? "= #{ENV[PUPPET_VERSION]}" : [>= 2.7] gem puppet, puppetversion  group :test do gem rake, >= 0.9.0 gem rspec, >= 2.8.0 gem rspec-puppet, >= 0.1.1 end
    23. 23. Travis CI
    24. 24. Acceptance Testing• vagrant box • veewee (basebox) • http://vagrantbox.es• vagrant init• vagrant up• vagrant provision
    25. 25. Vagrant• config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.manifest_file = "oneiric.pp" end• config.vm.network :hostonly, "10.0.2.15"• config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
    26. 26. Puppet Modules• forge.puppetlabs.com• www.github.com/puppetlabs• Bring your own module!
    27. 27. Module Projects?• Module cleanup • puppet-lint (best practice)• Module test • rspec puppet • travis ci• Module development
    28. 28. Puppet Projects?• Puppet issues: projects.puppetlabs.com• Puppettools: geppeto puppet-lint rspec-puppet
    29. 29. We are hiring!
    30. 30. We are hiring!
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×