VIM settings for Ansible playbooks

Writing yaml for ansible

When writing Ansible playbooks and other files, the language is somewhat picky on syntax and spacing.
My prefered editor is VIM, so some help in the settings is welcome. This page is dedicated on collecting usefull VIM configuration bits and pieces.

Configuration settings for VIM are done in a hidden file .vimrc in the user home directory.

The line below helps when editing .yml files.

autocmd FileType yaml setlocal ai ts=2 sw=2 et

Test yaml files

To test you yaml file a python syntax check can be used. Im not a python programmer so i have to ‘cheat’ a bit by adding an alias in my environment. So i added in my user .bashrc (/home/myname/.bashrc) the line:

alias ycheck="python -c 'import yaml, sys; print yaml.load(sys.stdin)' < "

After editing this file you need to source it again with
source .bashrc

This allows me to use ycheck [filename.yml] to check for syntax errors.

Rik has written 7 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>