using ruby & thor for easier puppet module development

Post on 28-Nov-2014

642 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

USING RUBY & THOR FOR EASIER PUPPETMODULE DEVELOPMENT

/ (We're Hiring!)

Tehmasp Chaudhri @tehmaspc

Pearson North America

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')

POPULAR PROJECTS USING THOR:

...

berkshelfbundlerrailsvagrant

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

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.

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

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

...

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'

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

DEMOMagnum (our custom Thor based tool)

QUESTIONS?

top related