Finding YAML errors in puppet

I love tabs, they’re so much easier to work with, but YAML doesn’t like them. I’m constantly adding them in accidentally, and puppet’s error message is a bit cryptic:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: malformed format string - %S at /etc/puppet/manifests/foo.pp:18 on node

This happens during a puppet run, which in my case loads up YAML files. The tricky part was that the error wasn’t at all related to the foo.pp file, it just happened to be the first time hiera was run. So where’s the real error?

$ cd /etc/puppet/hieradata/; for i in `find . -name '*.yaml'`; do echo $i; ruby -e "require 'yaml'; YAML.parse('$i'))"; done

Run this one liner on your puppetmaster, and hiera should quickly point out which files have errors, and exactly which lines (and columns) they’re on.

Happy hacking,




2 thoughts on “Finding YAML errors in puppet

  1. Here’s what the pro’s use:

    find . -name “*.yaml” -print0 | xargs -0rt -I ^ ruby -e “require ‘yaml’; YAML.parse(‘^’)) or puts(‘^’)”

    Only files with a parse error will be output. This is sure to handle files with spaces or weird characters.

  2. Here’s what the pros use:

    find . -name “*.yaml” -print0 | xargs -0rt -I ^ ruby -e “require ‘yaml’; YAML.parse(‘^’)) or puts(‘^’)”

    The filename is output only if there is a parser error. This version handles unlimited files with spaces or other odd characters in the path names.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s