23
Write Puppet manifests and modules faster with VIM Pierre Mavro www.enovance.com September 4, 2013

Write Puppet manifests and modules faster with VIM

Embed Size (px)

DESCRIPTION

Those slides presents VIM modules to help on writing Puppet manifests and modules.

Citation preview

Page 1: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM

Pierre Mavro

www.enovance.com

September 4, 2013

Page 2: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Summary

Summary

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 2 / 23

Page 3: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Introduction

Plan

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3I Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3I History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 3 / 23

Page 4: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Introduction

Puppet Labs

Puppet is IT automation software that gives system administrators the power to easilyautomate repetitive tasks, quickly deploy critical applications, and proactively manageinfrastructure, on-premises or in the cloud.Puppet is a scalable and open source solution. A lot of modules exists on the officialrepository called Puppet forge : https://forge.puppetlabs.com/

If you search a specific module not available on Puppet forge and you will need tocreate your own. This task would take some time at first. To create Puppet manifests,it will be easier, but the required time to know the syntax is a problem for newbies.

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 4 / 23

Page 5: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Introduction

eNovance

eNovance, an innovative French company that delivers services in two key areas:

I Integrating and operating public and private open source clouds and 24/7 managed

I Services for the world’s largest public clouds (Cloudwatt, AWS, Google ComputeEngine, etc.).

With its extensive investment in R&D, in less than three years eNovance has become theworld’s 7th largest contributor to the OpenStack initiative, and the only European companyon the foundation’s board of directors alongside Rackspace, Redhat, Cisco and HP.

Today, we’re using Puppet in production and need to often write Puppet manifests andmodules. That’s why we needed to have an IDE or something similar to win time whenwriting them.

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 5 / 23

Page 6: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Introduction

Plan

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3I Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3I History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 6 / 23

Page 7: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Introduction

History

Puppet announced in 2011 an IDE plugin for Eclipse called Geppetto. I used it formore than a year and it really helps me to write manifests. Unfortunately, the latestsversions purposed by Cloudsmith (Geppetto editor) get stability problems, even withthe "all in one" version. In addition, Eclipse consume a lot of resources just for writingPuppet manifests.Another solution exist, this is set of VIM plugins which provide a lightweight solution.It gives more advanced features and automatically checks Puppet syntax (Geppettotoo).This is what we’re going to see here with the usage.http://puppetlabs.com/blog/geppetto-a-puppet-ide/http://cloudsmith.github.io/geppetto/

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 7 / 23

Page 8: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Plan

2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11I VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14I Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16I Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 8 / 23

Page 9: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Vundle

What is Vundle ? Vundle is short for Vim bundle and is a Vim plugin manager. It willhelps on install the next VIM modules (download and install fromgithub/vimscripts...). To install it :

Grab it from GitHub and add it to your vim personal foldergit clone https :// github .com/ gmarik / vundle .git ~/. vim/ bundle / vundle

To finish, add this at the beginning of your /.vimrc file :

/.vimrcset nocompatible " be iMprovedfiletype off " required!set rtp+=~/.vim/bundle/vundle/call vundle#rc()

" My Bundles here:Bundle ’gmarik/vundle’" Additional bundles:

filetype plugin indent on " required!

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 9 / 23

Page 10: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Vundle

When you will add new lines to declare new bundles, you’ll install them by runningthat command :

Install bundles with vundlevim + BundleInstall +qall

Link : https://github.com/gmarik/vundle

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 10 / 23

Page 11: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Plan

2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11I VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14I Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16I Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 11 / 23

Page 12: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Ultisnips

Ultisnips helps on writing Puppet type refences (file, cron, user...). To install it addthis line after ’Additional bundle’ part of your vimrc and install this new bundle :

.vimrc" Additional bundles:Bundle ’SirVer/ultisnips’

To test it, edit a file with ’.pp’ extension and type as follow :

I class <tab> : you’ll see a class block

I user <tab> : a block with most used option will appear

I cron <tab> : a block ...

I ... <tab>

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 12 / 23

Page 13: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

UltisnipsHere is the result :

test.ppclass name {

# body}

user { ’username’:ensure => present,uid => uid,gid => gid,comment => gecos,home => homedirectory,managehome => false,require => Group[’group’],

}

cron { ’name’:user => user,command => ’command’,minute => minute,hour => hour,

}

Link : https://github.com/SirVer/ultisnipsPierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 13 / 23

Page 14: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Plan

2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11I VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14I Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16I Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 14 / 23

Page 15: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

VIM Puppet

VIM Puppet provides :

I Formatting based on the latest Puppetlabs Style Guide

I Syntax highlighting

I Automatic => alignment (when the tabular plugin is also installed)

To install it add this line after ’Additional bundle’ part of your vimrc and install thisnew bundle :

/.vimrc" Additional bundles:Bundle ’rodjek/vim-puppet’

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

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 15 / 23

Page 16: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Plan

2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11I VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14I Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16I Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 16 / 23

Page 17: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Tabular

This plugins helps on having signs alignments on multiple lines. It’s usually better toread good formated code. For instance having ’=’ sign aligned or ’=>’ sign forPuppet. Coupled with VIM Puppet, it will automatically align the signs when you willwrite your manifests.To install it add this line after ’Additional bundle’ part of your vimrc and install thisnew bundle :

.vimrc" Additional bundles:Bundle ’godlygeek/tabular’

To use it with Puppet manifests/modules, you don’t have nothing to do as it willautomatically align from the previous lines.

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 17 / 23

Page 18: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Tabular

Anyway, for any reasons you want to do it manually, this is easy. In VIM, place yourcursor on the first line containing the symbol on which the alignment should be done,then type :

This will align from the ’=’ symbol: Tabularize /=

Example :

toto = tototiti =titi

toto = tototiti = titi

Link : https://github.com/godlygeek/tabular

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 18 / 23

Page 19: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Plan

2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8I Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11I VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14I Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16I Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 19 / 23

Page 20: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Syntastic

Syntastic is a syntax checking plugin that runs files through external syntax checkersand displays any resulting errors to the user. This can be done on demand, orautomatically as files are saved.If syntax errors are detected, the user is notified and is happy because they didn’thave to compile their code or execute their script to find them.To install it add this line after ’Additional bundle’ part of your vimrc and install thisnew bundle :

.vimrc" Additional bundles:Bundle ’scrooloose/syntastic’

On the next slide, you’ll find a screenshot example.

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 20 / 23

Page 21: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Syntastic

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 21 / 23

Page 22: Write Puppet manifests and modules faster with VIM

Write Puppet manifests and modules faster with VIM: Setup and usage

Syntastic

When you move your cursor on a line beginning with the ’»’ symbol, you’ll see the lineerror message on the bottom of the screen.If you want to see all errors, you need to type this in VIM :

Install bundles with vundle: Errors

And the bottom of the screen will look likes the screenshot above.Link : https://github.com/scrooloose/syntastic

Pierre Mavro www.enovance.comWrite Puppet manifests and modules faster with VIM 22 / 23

Page 23: Write Puppet manifests and modules faster with VIM