Vim for Ansible playbooks: omni-completion, abbreviations, syntax, folding, K-docs, and colorscheme
Command the Ansible, Relish the Rainbow. Never visit the Ansible docs again.
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.
state=
valuesK
).ans
/.yaml
files: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.)
stat
with K
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.)
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
.
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.
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).
Plays can be folded into a single line containing just the name:
description.
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.
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).
Copyright © Micah Elliott. Distributed under the same terms as Vim itself. See
:help license
.