Chapter 8. Code Workflow Management

All the Puppet manifests, public shared modules, site modules, and (Hiera) data are the code and data we create. We need tools and workflows to manage them.

In this chapter, we are going to review the existing tools and techniques to manage Puppet's code workflow, from when it is written to when it is deployed to production.

Most of the people in the Puppet world use Git to version their code, so we will refer mostly to Git, but similar processes can be followed if we manage our code with subversion, mercurial, or any other source code management tool.

In this chapter, we give an overview of the tools that can help us with our Puppet code. We will cover the following topics:

  • Write with Geppetto and Vim
  • Manage with Git
  • Review with Gerrit
  • Test modules with rspec-puppet
  • Test Puppet runs with Beaker and Vagrant
  • Deploy with librarian-puppet or r10k
  • Automate with Travis or Jenkins

Write Puppet code

Each of us has a favorite tool for code writing. It may change according to the language we are using, our familiarity with the software or a preference of the moment.

Whatever tool we use, it should make our experience as smooth, productive, and enjoyable as possible.

I am a Vim guy, without being a guru. Having a system admin background, grown with bread and shell, I am comfortable with the possibility of using the same tool, wherever I am, on the local terminal or the remote SSH session: more or less we can expect to find Vim on any system under our keyboard.

A developer, I guess, may feel more comfortable with a tool that runs on his computer and can greatly enhance the writing experience, with syntax checks, cross references, and all the power of an IDE.

For this, there is Geppetto, a full-featured IDE, based on Eclipse and dedicated to Puppet code. Other popular editors also have Puppet plugins that can be quite useful.

The good news is that all of them can make life more enjoyable and productive when we write Puppet code.

Geppetto

Geppetto (http://puppetlabs.github.io/geppetto/) is one of the tools of reference for writing Puppet code. It is an open source software by Puppet Labs, which is a result of the acquisition of the startup Cloud smith that developed it.

We can install Geppetto as a standalone application or as an Eclipse plugin, if we are already using it.

It has very useful features such as:

  • Code syntax and style checking
  • Contextual documentation
  • Integration with the Puppet Forge
  • Integration with PuppetDB
  • All the features inherited from Eclipse

When we launch it, we are prompted for a directory from which to create our Geppetto workplace. In a workplace, we can create projects that most of the time are modules we can directly import from the Forge or a SCM repository.

Note

Geppetto may be memory hungry with large projects; if we bump into Internal Error: Java heap space, we probably have to enlarge the memory pools for the JVM Geppetto runs into. In geppetto.ini (or eclipse.ini if we use Geppetto as a plugin), we can set something like this:

-XX:MaxPermSize=256m

-vmargs

-Xms384m

-Xmx512m

Vim

If we have to think about an evergreen tool that has accompanied many sys admins' keyboards for many years, I think that Vim is one of the first names that comes to mind.

Its power and flexibility is also well expressed in how it can be made to manage Puppet code effectively.

There are two Vim bundles that are particularly useful for us:

  • vim-puppet (https://github.com/rodjek/vim-puppet): This is a syntax highlighter and formatting tool, written by Tim Sharpe, well known in the Puppet community for being the author of hugely popular tools such as librarian-puppet, puppet-lint, and rspec-puppet (all of which are going to be discussed in this chapter).
  • Syntastic: This is a syntax-checking tool that works for many popular languages and has the capability to check the style and syntax of our manifests right when we save them.

To install them easily we need to install Pathogen (a Vim extension that allows easy management of plugins) by copying the ~/.vim/autoload/pathogen.vim file from https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim.

Then, be sure to have Pathogen installed in the ~/.vimrc of our home directory:

call pathogen#infect()
syntax on
filetype indent plugin on

Once we have Pathogen loaded, we can easily add bundles in the .vim/bundle directory:

git clone git://github.com/rodjek/vim-puppet.git .vim/bundle/puppet
git clone git://github.com/scrooloose/syntastic.git .vim/bundle/syntastic

Now, we can use Vim with these powerful plugins that make coding with Puppet DSL definitively more comfortable.

Note

If, after these changes, we have problems when pasting multiple lines of text from the clipboard (each new line has one more indent level and # signs at the beginning), try to issue the Vim command : set paste.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset