Skip to content

Vim for Ansible playbooks: omni-completion, abbreviations, syntax, folding, K-docs, and colorscheme

Notifications You must be signed in to change notification settings

MicahElliott/Rocannon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rocannon: Operator of the Ansible

Command the Ansible, Relish the Rainbow. Never visit the Ansible docs again.

Rocannon!

Ansible is a unique DSL with semantics way beyond an editor’s simple built-in YAML treatment. Thus, Ansible files need a totally different type of syntax highlighting — and of course completion of actions and their args.

Features

  • Completion system that’s aware of all ansible modules/actions and their args, and even the unique state= values
  • Syntax for semantics of Ansible, way beyond vanilla YAML
  • A 256-color scheme to make use of the extended syntax
  • Local, comprehensive documentation system that mirrors online docs (use K)
  • Folding regions to collapse task blocks into simple, readable lists
  • Simple skeleton for new .ans/.yaml files
  • “Bouncing” between related roles files
  • Execution of individual plays (via implicit tags and :make)

(This is a somewhat simplistic Vim implementation, but mostly works if you stick to Ansible best practices http://docs.ansible.com/playbooks_best_practices.html.)

Demo

  • Vanilla YAML file with default highlighting
  • Change the filetype to ansible (can be done in other ways)
  • Reopen file to reflect filetype
  • Notice the folding
  • Create a new "stat" play to not install pbzip2 otherwise
  • Notice the completion of action and arg (other args also completable)
  • Pull up documentation for stat with K

Rocannon Demo!

Installation

Here I’m using Vundle (but Pathogen should also work):

% vim ~/.vimrc " add line inside vundle block
Plugin 'MicahElliott/Rocannon'

Then install it with Vundle.

% vim +PluginInstall +qa

I recommend the above, but — just for fun — you could even use Ansible to get it! (This also assumes Vundle is managing your ~/.vim/bundle area, and that you’ve added the Plugin line above to your ~/.vimrc.)

% ansible localhost -m git -a 'repo=https://github.com/MicahElliott/Rocannon dest=~/.vim/bundle/Rocannon'

Rocannon should automatically detect a file with extension .yaml (but not .yml) as an Ansible file type. If you want to be explicit, though, you could add to the top (or bottom) of each Ansible YAML file:

# vim:ft=ansible:

Now open an Ansible file and your should notice that the filetype is “ansible”, and you’ll see some fancy colors, completions, etc:

% vim foo.yaml

(It would be really nice if Ansible supported a *.ans file extension.)

Comprehensive Help

This README is just to get you started. Use the extensive vim help to learn the important details:

:help rocannon

Every Ansible module’s online documentation is also available via vim’s K.

Completions

All known Ansible actions are omni-completed, and a short description is shown. Actions also have abbreviations, so that when you type yum: it will complete to yum: name=. There are also completions for each arg, so if you type yum: name=zsh <C-x><C-o> you will see a list of all possible args. Even state values are completed.

Syntax/Highlighting (colorscheme)

Yes, it’s very colorful. Although initially jarring, I find this quite helpful. The scheme is called rocannon. I recommend that you embrace this rainbow (though it can be turned off).

Folding

Plays can be folded into a single line containing just the name: description.

Jumping between files (like vim-rails)

Several files in a role often need to be bounced around between. Vim-Rails supports this nicely, bouncing between controllers, views, models, tests, etc. Rocannon should do the same between tasks, handlers, templates, files, and vars.

To its fullest

It’s helpful to have a terminal and font that fully support 256 colors, bold, underline, italic, etc. If you don't already have that covered, I recommend Urxvt and Orp-Font (if you like bitmapped).

License

Copyright © Micah Elliott. Distributed under the same terms as Vim itself. See :help license.

About

Vim for Ansible playbooks: omni-completion, abbreviations, syntax, folding, K-docs, and colorscheme

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published