# Prevent YAML errors with a linter

**URL:** <https://forum.ansible.com/t/prevent-yaml-errors-with-a-linter/21596>\
**Category:** Ansible Developer\
**Created:** [May 29, 2016, 1:13pm UTC](https://forum.ansible.com/t/prevent-yaml-errors-with-a-linter/21596 "2016-05-29T13:13:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrien\_Verge](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Adrien\_Verge](https://forum.ansible.com/u/Adrien_Verge)\
**Post date:** [May 29, 2016, 1:13pm UTC](https://forum.ansible.com/t/prevent-yaml-errors-with-a-linter/21596/1 "2016-05-29T13:13:22Z")

</div>

Hi all o/

Unlike Python, YAML source is not checked and some errors like key duplicates  
enter the code base. For example, `wait_timeout` key is repeated twice at some  
places (with different values).

I propose the use of `yamllint` to check for such problems on Travis, hence  
preventing new ones from sneaking in. I made a pull request at:  
[https://github.com/ansible/ansible/pull/15678](https://github.com/ansible/ansible/pull/15678)

Feedback is most welcome. In particular, I disabled all cosmetic rules (checks  
for whitespaces, indentation, etc.)

Cheers,

Adrien

[1]: Documentation for this linter: [http://yamllint.readthedocs.io/en/latest/](http://yamllint.readthedocs.io/en/latest/)

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [May 31, 2016, 5:13pm UTC](https://forum.ansible.com/t/prevent-yaml-errors-with-a-linter/21596/2 "2016-05-31T17:13:07Z")

</div>

I have a wip branch at [https://github.com/alikins/ansible/tree/yamllint\_on\_yaml\_error](https://github.com/alikins/ansible/tree/yamllint_on_yaml_error) that  
will also show yamllint output when yaml errors occur.

I found it useful when tracking down some bad yaml I was generating in unit tests, but might not be generally useful. For the most part, to get to the point where we throw yaml errors, the yaml is in bad enough shape yamllint doesn’t provide much info. Aside from a differently worded version of ‘there is a syntax error in the yaml’.

Other variations:

- run it on all loaded yaml, and if in a verbose or debug mode, show the warnings
