52
How not to freak out … … when you start writing Puppet modules on Windows

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

  • Upload
    puppet

  • View
    238

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

How not to freak out …

… when you start writing Puppet

modules on Windows

Page 2: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

before we start ...

Page 3: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Me

• Senior Software Engineer at PuppetSpecialising in Windows

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

• DevOps advocate

Page 4: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

The setup …

Page 5: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 6: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 7: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 8: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 9: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

What do we need?

• Setting up a development environment

• Create a Puppet module

• Debugging tools

Page 10: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

What do we need?

• Testing tools

• Publish the module

• Next steps

Page 11: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 12: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 13: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Tools you probably already have

• Windows computer

• Text editor

• Puppet Agent

Tools you probably need to install

• Source Control

• Ruby and Ruby Dev Kit

Page 14: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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?

Page 15: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Why Source Control?

•Undo mistakes

•Be kind to you future self

Page 16: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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 …

Page 17: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Why Ruby?

Q: Why use ruby?

A: Because, Puppet.

Page 18: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Why Ruby?

Q: Doesn’t that already come with

Puppet Agent?

A: Yes, but…

Page 19: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Which text editor?

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

Lots of other options though….

Page 20: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Which text editor?

Common problems

• CRLF vs LF

Probably best to use LF

• Text Encoding and BOM

Unrecognised character at Line 1, Pos 1

Page 21: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

How do we install these tools?

• Manual installation

• Chocolateyhttps://chocolatey.org

Page 22: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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

Page 23: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

How do we install these tools?

Common problems

• Ruby Devkit can be tricky to install

Manually install the devkit into your ruby installation

Page 24: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 25: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Create a Module – Where to start?

• Beginner’s Guide to Modules

• Module fundamentals

Page 26: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Creating a Module - Tools

Puppet Module Tool

bundler

rake

Page 27: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 28: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 29: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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

Page 30: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Debugging tools

• Modify Gemfile

• Bundle install

gem "pry"

gem "pry-byebug"

gem "pry-stack_explorer"

Page 31: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Debugging tools

require "pry"; binding.pry

Page 32: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 33: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 34: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Why should I test?

Page 35: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• The “un-happy” path

• Document the intent

• Avoid regression

Why should I test?

Page 36: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Acceptance

• Integration

• Unit

Types of tests

Page 37: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Types of tests

Where should I start?

Start with unit and integration tests using

automated tools

Page 38: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Unit and Integration tests

• rspec

• rspec-mocks or mocha

• rspec-puppet

Testing tools

Page 39: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Acceptance tests

• beaker

• beaker-rspec

Testing tools

Page 40: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 41: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 42: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

Puppet Module Tool

puppet-blacksmith

Publishing tools

Page 43: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet
Page 44: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 45: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Setup environment

• Create module

• Debug tools

• Test tools

• Publish module

• Next steps

Page 46: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Read up on testing

• Learn more ruby

• Add automated acceptance tests

What’s next

Page 47: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

• Custom types and providers

• Test your Windows modules on

Linux nodes

What’s next

Page 48: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

glenn.sarti

[email protected]

@glennsarti

Go write some modules!

Page 49: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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

Page 50: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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

Page 51: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet

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

Page 52: PuppetConf 2016: How Not to Freak Out When You Start Writing Puppet Modules for Windows – Glenn Sarti, Puppet