PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn...

Post on 22-Jan-2018

240 views 0 download

Transcript of PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn...

How not to freak out …

… when you start writing Puppet

modules on Windows

before we start ...

Me

• Senior Software Engineer at PuppetSpecialising in Windows

• 15 years in Desktop Engineering and ITNavy, Government, Mining, Finance, Corporate

• DevOps advocate

The setup …

What do we need?

• Setting up a development environment

• Create a Puppet module

• Debugging tools

What do we need?

• Testing tools

• Publish the module

• Next steps

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Tools you probably already have

• Windows computer

• Text editor

• Puppet Agent

Tools you probably need to install

• Source Control

• Ruby and Ruby Dev Kit

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?

Why Source Control?

•Undo mistakes

•Be kind to you future self

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 …

Why Ruby?

Q: Why use ruby?

A: Because, Puppet.

Why Ruby?

Q: Doesn’t that already come with

Puppet Agent?

A: Yes, but…

Which text editor?

Common - Atom, Notepad++, VS CodeSome have ruby and puppet plugins to help with development

Lots of other options though….

Which text editor?

Common problems

• CRLF vs LF

Probably best to use LF

• Text Encoding and BOM

Unrecognised character at Line 1, Pos 1

How do we install these tools?

• Manual installation

• Chocolateyhttps://chocolatey.org

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

How do we install these tools?

Common problems

• Ruby Devkit can be tricky to install

Manually install the devkit into your ruby installation

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Create a Module – Where to start?

• Beginner’s Guide to Modules

• Module fundamentals

Creating a Module - Tools

Puppet Module Tool

bundler

rake

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Debugging tools

• pryConsole driven debugger for ruby

• pry-byebugPry plugin to add step-by-step and stack

debugging

• pry-stack_explorerPry plugin to navigate the call stack in ruby

Debugging tools

• Modify Gemfile

• Bundle install

gem "pry"

gem "pry-byebug"

gem "pry-stack_explorer"

Debugging tools

require "pry"; binding.pry

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Why should I test?

• The “un-happy” path

• Document the intent

• Avoid regression

Why should I test?

• Acceptance

• Integration

• Unit

Types of tests

Types of tests

Where should I start?

Start with unit and integration tests using

automated tools

Unit and Integration tests

• rspec

• rspec-mocks or mocha

• rspec-puppet

Testing tools

Acceptance tests

• beaker

• beaker-rspec

Testing tools

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Puppet Module Tool

puppet-blacksmith

Publishing tools

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

• Read up on testing

• Learn more ruby

• Add automated acceptance tests

What’s next

• Custom types and providers

• Test your Windows modules on

Linux nodes

What’s next

glenn.sarti

glenn.sarti@puppet.com

@glennsarti

Go write some modules!

LinksSource Control

• The Release Pipeline Modulehttp://aka.ms/thereleasepipelinemodelpdf

• Ruby Installationhttp://rubyinstaller.org/downloads/

• Ruby DevKithttps://github.com/oneclick/rubyinstaller/wiki/Development-Kit

• What is the BOMhttps://en.wikipedia.org/wiki/Byte_order_mark

• Chocolateyhttps://chocolatey.org/

• Puppet Extension for Visual Studio Codehttps://marketplace.visualstudio.com/items?itemName=Borke.Puppet

Modules

• Puppet Enterprise quick start guide for Windows

usershttps://docs.puppet.com/pe/latest/quick_start_windows_intro.html

• Beginner’s Guide to Moduleshttps://docs.puppet.com/guides/module_guides/bgtm.html

• Module fundamentalshttps://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html

• Ruby Bundlerhttp://bundler.io/

• puppet module generatehttps://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html#writing-modules

LinksDebugging

• Pryhttp://pryrepl.org/

https://www.sitepoint.com/rubyists-time-pry-irb/

• pry-byebughttps://github.com/deivid-rodriguez/pry-byebug

• pry-stack_explorerhttps://github.com/pry/pry-stack_explorer

Testing

• Rspechttp://rspec.info/

• rspec-puppethttp://rspec-puppet.com/

• rspec-mockshttps://github.com/rspec/rspec-mocks

• mochahttp://gofreerange.com/mocha/docs/

• beakerhttps://github.com/puppetlabs/beaker/blob/master/docs/README.md

• beaker-rspechttps://github.com/puppetlabs/beaker-rspec

LinksPublishing

• puppet-blacksmithhttps://github.com/voxpupuli/puppet-blacksmith

• Publishing modules on the forgehttps://docs.puppet.com/puppet/4.7/reference/modules_publishing.html

• The metadata.json filehttps://docs.puppet.com/puppet/4.7/reference/modules_metadata.html

Other

• Puppet REPL

A REPL for the puppet languagehttps://github.com/nwops/puppet-repl

• Puppet Skeleton Module Generatorhttps://github.com/garethr/puppet-module-skeleton

• Puppet Strings

The next generation Puppet documentation

extraction and presentation toolhttps://github.com/puppetlabs/puppet-strings