Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How Not to Freak Out When You Start Writing Pup...

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

Glenn

October 21, 2016
Tweet

More Decks by Glenn

Other Decks in Technology

Transcript

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

    writing Puppet modules on Windows
  2. Me • Senior Software Engineer at Puppet Specialising in Windows

    • 15 years in Desktop Engineering and IT Navy, Government, Mining, Finance, Corporate • DevOps advocate
  3. What do we need? • Setting up a development environment

    • Create a Puppet module • Debugging tools
  4. • Setup environment • Create module • Debug tools •

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

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

    editor • Puppet Agent Tools you probably need to install • Source Control • Ruby and Ruby Dev Kit
  7. 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? …
  8. 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 …
  9. Which text editor? Common - Atom, Notepad++, VS Code Some

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

    best to use LF • Text Encoding and BOM Unrecognised character at Line 1, Pos 1
  11. 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
  12. How do we install these tools? Common problems • Ruby

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

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

    Test tools • Publish module • Next steps
  15. 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
  16. Debugging tools • Modify Gemfile • Bundle install … gem

    "pry" gem "pry-byebug" gem "pry-stack_explorer"
  17. • Setup environment • Create module • Debug tools •

    Test tools • Publish module • Next steps
  18. Types of tests Where should I start? Start with unit

    and integration tests using automated tools
  19. • Setup environment • Create module • Debug tools •

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

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

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

    Add automated acceptance tests What’s next
  23. 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
  24. 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
  25. 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