using ruby & thor for easier puppet module development

11

Click here to load reader

Upload: tehmasp-chaudhri

Post on 28-Nov-2014

642 views

Category:

Technology


0 download

DESCRIPTION

Using Ruby & Thor For Easier Puppet Module Development Magnum site: https://github.com/tehmaspc/magnum Original slides: http://goo.gl/syiOUW

TRANSCRIPT

Page 1: Using Ruby & Thor For Easier Puppet Module Development

USING RUBY & THOR FOR EASIER PUPPETMODULE DEVELOPMENT

/ (We're Hiring!)

Tehmasp Chaudhri @tehmaspc

Pearson North America

Page 2: Using Ruby & Thor For Easier Puppet Module Development

WHAT IS THOR?Thor is a Ruby toolkit for building powerful command-lineinterfaces.The developer can easily integrate Thor into their Ruby code.Classes such as Groups, Actions, and Shell are provided whichmake tasks such as file system interaction and command lineuser dialogue easier.Thor can be leveraged to make custom project generators (e.g.'bundle gem -b mygem')

Page 3: Using Ruby & Thor For Easier Puppet Module Development

POPULAR PROJECTS USING THOR:

...

berkshelfbundlerrailsvagrant

Page 4: Using Ruby & Thor For Easier Puppet Module Development

MORE INFO:Thor (main)Thor (GitHub wiki)

Page 5: Using Ruby & Thor For Easier Puppet Module Development

WHY DID WE USE THOR?Technical Reasons:

Thor is written in Ruby, our Puppet code is in a Ruby DSL.Thor's custom project generator use case was appealing andworks well. It's easy to add and update template files.We wanted to create a framework for Puppet moduledevelopment which provided the Puppet tools we like, so thatwe could create standalone & well tested Puppet modules.Thor let us glue all this together.

Business Reasons:

We allow (many) dev teams to contribute to our Puppetmodule development; thus we needed a way to make creatingPuppet modules quick & easy, consistent, manageable, andwith 'best practices' baked in.

Page 6: Using Ruby & Thor For Easier Puppet Module Development

TOOLS WE LIKE TO USE WITH PUPPET MODULEDEVELOPMENT:puppet-lintpuppet-git-hookspuppetlabs_spec_helperrspec-puppetserverspecvagrantbundlerrakejenkins

Shoutout to Phil Zimmerman's Puppet Testing For The Win

Page 7: Using Ruby & Thor For Easier Puppet Module Development

THOR CUSTOM GENERATOR EXAMPLE:...

def write_emptydirs empty_directory target.join('files') empty_directory target.join('manifests') empty_directory target.join('templates') empty_directory target.join('spec') empty_directory target.join('serverspec/spec') empty_directory target.join('.vagrant_puppet') end

def write_readme template 'README.md.erb', target.join('README.md') end

def write_modulefile template 'puppet/ModuleFile.erb', target.join('ModuleFile') end

...

Page 8: Using Ruby & Thor For Easier Puppet Module Development

MODULEFILE.ERB EXAMPLE:name '<%= module_name %>' version '0.1.0' source 'UNKNOWN' author '<%= maintainer_email %>' license '<%= license_name %>' summary 'UNKNOWN' description 'UNKNOWN' project_page 'UNKNOWN'

## Add dependencies, if any: # dependency 'username/name', '>= 1.2.0'

Page 9: Using Ruby & Thor For Easier Puppet Module Development

CURRENT LIST OF TEMPLATE FILES:./git/gitignore.erb ./git/puppet-git-hooks-pre-commit.erb ./licenses/apachev2.erb ./licenses/mit.erb ./licenses/reserved.erb ./puppet/init.pp.erb ./puppet/ModuleFile.erb ./README.md.erb ./spec/fixtures.yml.erb ./spec/rspec/init_spec.rb.erb ./spec/rspec/spec_helper.rb.erb ./spec/serverspec/init_spec.rb.erb ./spec/serverspec/spec_helper.rb.erb ./util/Gemfile.erb ./util/Rakefile.erb ./vagrant/init.pp.erb ./vagrant/Vagrantfile.erb

Page 10: Using Ruby & Thor For Easier Puppet Module Development

DEMOMagnum (our custom Thor based tool)

Page 11: Using Ruby & Thor For Easier Puppet Module Development

QUESTIONS?