Pro Yearly is on sale from $80 to $50! »

How Not to Freak Out When You Start Writing Puppet Modules for Windows

Aac3dafaab7a7c2063d2526ba5936305?s=47 Glenn
October 21, 2016

How Not to Freak Out When You Start Writing Puppet Modules for Windows

Writing your first Puppet module is pretty daunting. There are so many things to set up: tools, repositories, tests! In this presentation we’ll walk through setting up a local Windows development environment, and then write a Puppet module. We’ll also look at debugging, testing and publishing the module to the Puppet Forge.

http://sched.co/6fjw

Recording - https://www.youtube.com/watch?v=9A2-_nPrqfs

Aac3dafaab7a7c2063d2526ba5936305?s=128

Glenn

October 21, 2016
Tweet

Transcript

  1. How not to freak out … … when you start

    writing Puppet modules on Windows
  2. before we start ...

  3. Me • Senior Software Engineer at Puppet Specialising in Windows

    • 15 years in Desktop Engineering and IT Navy, Government, Mining, Finance, Corporate • DevOps advocate
  4. The setup …

  5. None
  6. None
  7. None
  8. None
  9. What do we need? • Setting up a development environment

    • Create a Puppet module • Debugging tools
  10. What do we need? • Testing tools • Publish the

    module • Next steps
  11. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  12. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  13. Tools you probably already have • Windows computer • Text

    editor • Puppet Agent Tools you probably need to install • Source Control • Ruby and Ruby Dev Kit
  14. Why Source Control? • Made a change and realised it

    was a mistake and wanted to revert back? • Lost a modules or had a backup that was too old? • Wanted to see the difference between two (or more) versions of your modules? • Wanted to prove that a change broke or fixed a piece of modules? • Wanted to review the history of a modules? • Wanted to submit a change to someone else's modules? • Wanted to share your modules, or let other people work on your modules? • Wanted to see how much work is being done, and where, when and by whom? • Wanted to quickly experiment something new without breaking anything? …
  15. Why Source Control? • Undo mistakes • Be kind to

    you future self
  16. Why Source Control? Prefer git for Puppet Module work •

    Lightweight • Doesn’t require a central server • Very common But, choose something that’s appropriate for you …
  17. Why Ruby? Q: Why use ruby? A: Because, Puppet.

  18. Why Ruby? Q: Doesn’t that already come with Puppet Agent?

    A: Yes, but…
  19. Which text editor? Common - Atom, Notepad++, VS Code Some

    have ruby and puppet plugins to help with development Lots of other options though….
  20. Which text editor? Common problems • CRLF vs LF Probably

    best to use LF • Text Encoding and BOM Unrecognised character at Line 1, Pos 1
  21. How do we install these tools? • Manual installation •

    Chocolatey https://chocolatey.org
  22. How do we install these tools? PS> choco install git

    PS> choco install puppet-agent PS> choco install visualstudiocode PS> choco install ruby ruby2.devkit
  23. How do we install these tools? Common problems • Ruby

    Devkit can be tricky to install Manually install the devkit into your ruby installation
  24. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  25. Create a Module – Where to start? • Beginner’s Guide

    to Modules • Module fundamentals
  26. Creating a Module - Tools Puppet Module Tool bundler rake

  27. None
  28. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  29. Debugging tools • pry Console driven debugger for ruby •

    pry-byebug Pry plugin to add step-by-step and stack debugging • pry-stack_explorer Pry plugin to navigate the call stack in ruby
  30. Debugging tools • Modify Gemfile • Bundle install … gem

    "pry" gem "pry-byebug" gem "pry-stack_explorer"
  31. Debugging tools require "pry"; binding.pry

  32. None
  33. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  34. Why should I test?

  35. • The “un-happy” path • Document the intent • Avoid

    regression Why should I test?
  36. • Acceptance • Integration • Unit Types of tests

  37. Types of tests Where should I start? Start with unit

    and integration tests using automated tools
  38. Unit and Integration tests • rspec • rspec-mocks or mocha

    • rspec-puppet Testing tools
  39. Acceptance tests • beaker • beaker-rspec Testing tools

  40. None
  41. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  42. Puppet Module Tool puppet-blacksmith Publishing tools

  43. None
  44. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  45. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  46. • Read up on testing • Learn more ruby •

    Add automated acceptance tests What’s next
  47. • Custom types and providers • Test your Windows modules

    on Linux nodes What’s next
  48. glenn.sarti glenn.sarti@puppet.com @glennsarti Go write some modules!

  49. Links Source Control • The Release Pipeline Module http://aka.ms/thereleasepipelinemodelpdf •

    Ruby Installation http://rubyinstaller.org/downloads/ • Ruby DevKit https://github.com/oneclick/rubyinstaller/wiki/Development-Kit • What is the BOM https://en.wikipedia.org/wiki/Byte_order_mark • Chocolatey https://chocolatey.org/ • Puppet Extension for Visual Studio Code https://marketplace.visualstudio.com/items?itemName=Borke.Puppet Modules • Puppet Enterprise quick start guide for Windows users https://docs.puppet.com/pe/latest/quick_start_windows_intro.html • Beginner’s Guide to Modules https://docs.puppet.com/guides/module_guides/bgtm.html • Module fundamentals https://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html • Ruby Bundler http://bundler.io/ • puppet module generate https://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html#writing-modules
  50. Links Debugging • Pry http://pryrepl.org/ https://www.sitepoint.com/rubyists-time-pry-irb/ • pry-byebug https://github.com/deivid-rodriguez/pry-byebug •

    pry-stack_explorer https://github.com/pry/pry-stack_explorer Testing • Rspec http://rspec.info/ • rspec-puppet http://rspec-puppet.com/ • rspec-mocks https://github.com/rspec/rspec-mocks • mocha http://gofreerange.com/mocha/docs/ • beaker https://github.com/puppetlabs/beaker/blob/master/docs/README.md • beaker-rspec https://github.com/puppetlabs/beaker-rspec
  51. Links Publishing • puppet-blacksmith https://github.com/voxpupuli/puppet-blacksmith • Publishing modules on the

    forge https://docs.puppet.com/puppet/4.7/reference/modules_publishing.html • The metadata.json file https://docs.puppet.com/puppet/4.7/reference/modules_metadata.html Other • Puppet REPL A REPL for the puppet language https://github.com/nwops/puppet-repl • Puppet Skeleton Module Generator https://github.com/garethr/puppet-module-skeleton • Puppet Strings The next generation Puppet documentation extraction and presentation tool https://github.com/puppetlabs/puppet-strings
  52. None