DevOps Zone is brought to you in partnership with:

Patrick Debois has been working on closing the gap between development and operations for many years. In 2009 he organized the first devopsdays.org conference and since then the world is stuck with the term 'devops'. Always seeking for opportunities to optimize the global IT instead of local optimizations. Patrick is a DZone MVB and is not an employee of DZone and has posted 39 posts at DZone. You can read more from them at their website. View Full User Profile

Puppet editing like a pro

12.05.2011
| 10227 views |
  • submit to reddit

I've spent some time recently on setting up my environment to work more productively on writing puppet manifests. This blogpost highlights some of the findings to get me more productive on editing puppet files and modules. Some older information can be found at Editor Tips on the puppetlabs website.

Tip 1: Syntax highlighting,snippet completion

Puppet syntax is very specific, it's important to get clues about missing curly braces, semi-colums, etc .. as fast as possible. There is support for this in the most common editors:

Using Textmate:

@Masterzen has created a textmate bundle for use with puppet. You can find it at https://github.com/masterzen/puppet-textmate-bundle.

Michael Halligan describes how to install it from the commandline

mkdir -p /Library/Application\ Support/TextMate/Bundles
cd /Library/Application\ Support/TextMate/Bundles
git clone git://gitorious.org/git-tmbundle/mainline.git Git.tmbundle
git clone http://git.gitorious.org/git-tmbundle/mainline.git Git.tmbundle
git clone https://github.com/masterzen/puppet-textmate-bundle.git Puppet.tmbundle
git clone https://github.com/drnic/Chef.tmbundle.git Chef.tmbundle
osascript -e 'tell app "TextMate" to reload bundles'

Using VIM:

If textmate is not your thing, here is how you can pimp up your vim:

When you look around for puppet/vim integration there seem to have been some re-incarnations:

The most advanced vim-puppet integration I could currently(Dec/2011) find is : - the vim-puppet Tim Sharpe created. - https://github.com/rodjek/vim-puppet

To use the vim-puppet plugin, you're best to use pathogen written by Tim Pope. I've followed the instructions at http://tammersaleh.com/posts/the-modern-vim-config-with-pathogen.

I've enabled the following plugins in my update_bundles script

git_bundles = [
  "git://github.com/astashov/vim-ruby-debugger.git",
  "git://github.com/ervandew/supertab.git",
  "git://github.com/godlygeek/tabular.git",
  "git://github.com/hallison/vim-rdoc.git",
  "git://github.com/msanders/snipmate.vim.git",
  "git://github.com/pangloss/vim-javascript.git",
  "git://github.com/scrooloose/nerdtree.git",
  "git://github.com/timcharper/textile.vim.git",
  "git://github.com/tpope/vim-cucumber.git",
  "git://github.com/tpope/vim-fugitive.git",
  "git://github.com/tpope/vim-git.git",
  "git://github.com/tpope/vim-haml.git",
  "git://github.com/tpope/vim-markdown.git",
  "git://github.com/tpope/vim-rails.git",
  "git://github.com/tpope/vim-repeat.git",
  "git://github.com/tpope/vim-surround.git",
  "git://github.com/tpope/vim-vividchalk.git",
  "git://github.com/tsaleh/taskpaper.vim.git",
  "git://github.com/tsaleh/vim-matchit.git",
  "git://github.com/tsaleh/vim-shoulda.git",
  "git://github.com/tsaleh/vim-tcomment.git",
  "git://github.com/tsaleh/vim-tmux.git",
  "git://github.com/vim-ruby/vim-ruby.git",
  "git://github.com/vim-scripts/Gist.vim.git",
  "git://github.com/scrooloose/syntastic",
  "git://github.com/rodjek/vim-puppet.git",
  "git://github.com/vim-scripts/Specky.git"
]

Most notable plugins:

  • Tabular gives you automatic => alignment
  • Syntastic gives you syntax feedback while you edit files
  • Snipmate gives you the snippets on tab expansion
  • Specky gives you functionality for rspec files
  • vim-ruby gives you extra functionality for ruby files
  • vim-cucumber gives you functionality for cucumber files

For more information on the vim-puppet project go to:

https://github.com/rodjek/vim-puppet/

The snippets that are expanded in the vim-puppet plugin can be found at:

https://github.com/rodjek/vim-puppet/blob/master/snippets/puppet.snippets

Tip 2: don't create modules structure by hand

I keep forgetting the correct structure, files etc.. when I create a new module. Luckily there is an easy way to generate a puppet module structure using the puppet-module gem

$ gem install puppet-module
$ puppet-module
Tasks:
  puppet-module build [PATH_TO_MODULE]                 # Build a module for release
  puppet-module changelog                              # Display the changelog for this tool
  puppet-module changes [PATH_TO_MODULE]               # Show modified files in an installed module
  puppet-module clean                                  # Clears module cache for all repositories
  puppet-module generate USERNAME-MODNAME              # Generate boilerplate for a new module
  puppet-module help [TASK]                            # Describe available tasks or one specific task
  puppet-module install MODULE_NAME_OR_FILE [OPTIONS]  # Install a module (eg, 'user-modname') from a repositor...
  puppet-module repository                             # Show currently configured repository
  puppet-module search TERM                            # Search the module repository for a module matching TERM
  puppet-module usage                                  # Display detailed usage documentation for this tool
  puppet-module version                                # Show the version information for this tool

Options:
  -c, [--config=CONFIG]  # Configuration file
$ puppet-module generate puppetmodule-apache
=========================================================================================
Generating module at /Users/patrick/demo-puppet/modules/puppetmodule-apache
-----------------------------------------------------------------------------------------
puppetmodule-apache
puppetmodule-apache/tests
puppetmodule-apache/tests/init.pp
puppetmodule-apache/spec
puppetmodule-apache/spec/spec_helper.rb
puppetmodule-apache/spec/spec.opts
puppetmodule-apache/README
puppetmodule-apache/Modulefile
puppetmodule-apache/metadata.json
puppetmodule-apache/manifests
puppetmodule-apache/manifests/init.pp

 

Tip 3 - Geppetto: a Puppet IDE

The folks from cloudsmith have created an Eclipse based editor called Geppetto. It integrates the syntax highlighting, module creation etc... and has nice integration with the Puppet forge

Note: this NOT related with the Gepetto (one P) project by Alban Peignier

James Turnbull was so kind to make a quick screencast on how it works:

Geppetto tutorial from Mitch Sonies on Vimeo.

 

Source: http://www.jedi.be/blog/2011/12/05/puppet-editing-like-a-pro
Published at DZone with permission of Patrick Debois, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Amara Amjad replied on Sun, 2012/03/25 - 12:44am

Note that newer versions of Geppetto has a smaller footprint and starts much quicker as we were able to take out functionality not needed when working with puppet code.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.