Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Write Puppet manifests and modules faster with VIM: Summary Summary 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 2 / 23

Slide 3

Slide 3 text

Write Puppet manifests and modules faster with VIM: Introduction Plan 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 3 / 23

Slide 4

Slide 4 text

Write Puppet manifests and modules faster with VIM: Introduction Puppet Labs Puppet is IT automation software that gives system administrators the power to easily automate repetitive tasks, quickly deploy critical applications, and proactively manage infrastructure, on-premises or in the cloud. Puppet is a scalable and open source solution. A lot of modules exists on the official repository called Puppet forge : https://forge.puppetlabs.com/ If you search a specific module not available on Puppet forge and you will need to create 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.com Write Puppet manifests and modules faster with VIM 4 / 23

Slide 5

Slide 5 text

Write Puppet manifests and modules faster with VIM: Introduction eNovance eNovance, an innovative French company that delivers services in two key areas: Integrating and operating public and private open source clouds and 24/7 managed Services for the world’s largest public clouds (Cloudwatt, AWS, Google Compute Engine, etc.). With its extensive investment in R&D, in less than three years eNovance has become the world’s 7th largest contributor to the OpenStack initiative, and the only European company on 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 and modules. That’s why we needed to have an IDE or something similar to win time when writing them. Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 5 / 23

Slide 6

Slide 6 text

Write Puppet manifests and modules faster with VIM: Introduction Plan 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 6 / 23

Slide 7

Slide 7 text

Write Puppet manifests and modules faster with VIM: Introduction History Puppet announced in 2011 an IDE plugin for Eclipse called Geppetto. I used it for more than a year and it really helps me to write manifests. Unfortunately, the latests versions purposed by Cloudsmith (Geppetto editor) get stability problems, even with the "all in one" version. In addition, Eclipse consume a lot of resources just for writing Puppet 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 (Geppetto too). 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.com Write Puppet manifests and modules faster with VIM 7 / 23

Slide 8

Slide 8 text

Write Puppet manifests and modules faster with VIM: Setup and usage Plan 2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 8 / 23

Slide 9

Slide 9 text

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 will helps on install the next VIM modules (download and install from github/vimscripts...). To install it : Grab it from GitHub and add it to your vim personal folder git clone https :// github.com/gmarik/vundle.git ~/. vim/bundle/vundle To finish, add this at the beginning of your /.vimrc file : /.vimrc set nocompatible " be iMproved filetype 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.com Write Puppet manifests and modules faster with VIM 9 / 23

Slide 10

Slide 10 text

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 running that command : Install bundles with vundle vim + BundleInstall +qall Link : https://github.com/gmarik/vundle Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 10 / 23

Slide 11

Slide 11 text

Write Puppet manifests and modules faster with VIM: Setup and usage Plan 2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 11 / 23

Slide 12

Slide 12 text

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 add this 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 : class : you’ll see a class block user : a block with most used option will appear cron : a block ... ... Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 12 / 23

Slide 13

Slide 13 text

Write Puppet manifests and modules faster with VIM: Setup and usage Ultisnips Here is the result : test.pp class 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/ultisnips Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 13 / 23

Slide 14

Slide 14 text

Write Puppet manifests and modules faster with VIM: Setup and usage Plan 2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 14 / 23

Slide 15

Slide 15 text

Write Puppet manifests and modules faster with VIM: Setup and usage VIM Puppet VIM Puppet provides : Formatting based on the latest Puppetlabs Style Guide Syntax highlighting Automatic => alignment (when the tabular plugin is also installed) To install it add this line after ’Additional bundle’ part of your vimrc and install this new bundle : /.vimrc " Additional bundles: Bundle ’rodjek/vim-puppet’ Link : https://github.com/rodjek/vim-puppet Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 15 / 23

Slide 16

Slide 16 text

Write Puppet manifests and modules faster with VIM: Setup and usage Plan 2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 16 / 23

Slide 17

Slide 17 text

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 to read good formated code. For instance having ’=’ sign aligned or ’=>’ sign for Puppet. Coupled with VIM Puppet, it will automatically align the signs when you will write your manifests. To install it add this line after ’Additional bundle’ part of your vimrc and install this new bundle : .vimrc " Additional bundles: Bundle ’godlygeek/tabular’ To use it with Puppet manifests/modules, you don’t have nothing to do as it will automatically align from the previous lines. Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 17 / 23

Slide 18

Slide 18 text

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 your cursor 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 = toto titi =titi toto = toto titi = titi Link : https://github.com/godlygeek/tabular Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 18 / 23

Slide 19

Slide 19 text

Write Puppet manifests and modules faster with VIM: Setup and usage Plan 2 Setup and usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Vundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Ultisnips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 VIM Puppet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Syntastic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 19 / 23

Slide 20

Slide 20 text

Write Puppet manifests and modules faster with VIM: Setup and usage Syntastic Syntastic is a syntax checking plugin that runs files through external syntax checkers and displays any resulting errors to the user. This can be done on demand, or automatically as files are saved. If syntax errors are detected, the user is notified and is happy because they didn’t have 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 this new bundle : .vimrc " Additional bundles: Bundle ’scrooloose/syntastic’ On the next slide, you’ll find a screenshot example. Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 20 / 23

Slide 21

Slide 21 text

Write Puppet manifests and modules faster with VIM: Setup and usage Syntastic Pierre Mavro www.enovance.com Write Puppet manifests and modules faster with VIM 21 / 23

Slide 22

Slide 22 text

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 line error 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.com Write Puppet manifests and modules faster with VIM 22 / 23

Slide 23

Slide 23 text

No content