YAML syntaxcheck

Since some years I do a lot of my configuration management of linux hosts with puppet. In puppet itself I use Hiera as a key/value lookup tool. Over the years the amount of keys in hiera are growing and growing. Therefore I was looking for a tool/programm to check all hiera yaml files for doublicate keys and/or syntax errors. After some searching I found yamllint a linter for YAML files. yamllint does not only check for syntax validity, but for weirdnesses like key repetition and cosmetic problems such as lines length, trailing spaces, indentation and some more things.


The installation itself on a debian host can be done on two/three ways:

debian packages

sudo apt-get install yamllint

Python package manager

sudo pip install yamllint

Installing from source

For a detailed description of how to install it from source, please take a look at the project documentation.


To use yamllint you can just execute the programm with the yaml files as parameters:

yamllint file.yml other-file.yaml

  1:4       error    trailing spaces  (trailing-spaces)
  4:4       error    wrong indentation: expected 4 but found 3  (indentation)
  5:4       error    duplication of key "id-00042" in mapping (key-duplicates)
  6:6       warning  comment not indented like content (comments-indentation)
  12:6      error    too many spaces after hyphen  (hyphens)
  15:12     error    too many spaces before comma  (commas)

  1:1       warning  missing document start "---"  (document-start)
  6:81      error    line too long (87 > 80 characters) (line-length)
  10:1      error    too many blank lines (4 > 2)  (empty-lines)
  11:4      error    too many spaces inside braces  (braces)

Thats all I needed right now. For more information and options, just take a look at the documentation page.

comments powered by Disqus