Ask Your Question

Does Puppet provide a validation/syntax checker for Hiera?

asked 2014-06-27 19:39:16 -0600

The tool puppet parser validate will check the syntax of my Puppet manifests:

[root@puppet3 ~]# puppet parser validate /etc/puppet/manifests/site.pp
Warning: The use of 'import' is deprecated at /etc/puppet/manifests/site.pp:18. See
   (at grammar.ra:610:in `_reduce_190')
Error: Could not parse for environment production: No file(s) found for import of 'nodes/*.pp' at /etc/puppet/manifests/site.pp:18
[root@puppet3 ~]#

And I can check my manifests against the Puppet Style Guide using puppet-lint:

[root@puppet3 ~]# puppet-lint /etc/puppet/modules/hosts/manifests/init.pp 
WARNING: class not documented on line 1
[root@puppet3 ~]#

Is there a Puppet validation tool for Hiera or for my YAML files?

edit retag flag offensive close merge delete

6 Answers

Sort by ยป oldest newest most voted

answered 2014-06-29 05:42:49 -0600

daff gravatar image

A dead-simple way to check a YAML file for correct syntax is parsing the file with your favourite scripting language. Here's a Ruby one-liner:

ruby -e "require 'yaml'; YAML.load_file('common.yaml')"

If the YAML file is valid there will be no output, otherwise you'll get exceptions of type Psych::SyntaxError.

edit flag offensive delete link more


And, if I wanted to do this for all files in my Hiera datadir, I could do something like this: `find /etc/puppet/hieradata/ -name "*.yaml" | while read file; do echo "file=$file"; ruby -e "require 'yaml'; YAML.load_file('$file')"; done`

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-02 18:47:27 -0600 )edit

Unfortunately, this still doesn't catch typos which trigger a failure with `puppet agent --test`. This one, for example:

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-02 19:00:29 -0600 )edit

As I said, this verifies correct YAML syntax, nothing more. Supplying data types incompatible with Hiera lookup functions is not a YAML syntax error. Neither is looking up non-existent keys or keys with empty values. Take care of such cases by using default values and conditionals where appropriate.

daff gravatar imagedaff ( 2014-07-03 05:54:02 -0600 )edit

My error was caused by an empty `classes:` array. Does that not count as a invalid YAML, or is that more of an error with Puppet/Hiera?

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-08 13:59:03 -0600 )edit

answered 2016-12-22 10:40:48 -0600

jack9 gravatar image

for simple checks i use yaml-lint

gem install yaml-lint
yaml-lint filename.yaml
yaml-lint hiera/
edit flag offensive delete link more

answered 2014-10-31 14:35:48 -0600

I'm looking at the Kwalify gem for this. You basically define a schema for your hiera yaml files and then it validates against the schema. Makes for a good CI workflow.

edit flag offensive delete link more

answered 2016-05-06 22:57:29 -0600

mike.r gravatar image

I wrapped this around

ruby -e "require 'yaml'; YAML.load_file('common.yaml')"

in a bash script to parse a dir and output any files w bad syntax.


edit flag offensive delete link more

answered 2016-12-23 07:40:16 -0600

DarylW gravatar image

In some of your comments, it seems like you want to validate that your hiera data can compile your manifests.

I asked a similar question at You can loop through all of your roles and do a 'it { should compile.withalldeps } across all of your roles

edit flag offensive delete link more

answered 2014-06-28 08:04:57 -0600

starkb gravatar image

There are a couple one is , but in the class they have you use validate_yaml. You can do a search on this on Google and get a lot more info.

edit flag offensive delete link more


To be clear, that is a shell function we use in the class.

validate_yaml() {
      ruby -ryaml -e "YAML.load_file '$1'"

binford2k gravatar imagebinford2k ( 2015-08-20 11:31:34 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-06-27 19:39:16 -0600

Seen: 12,339 times

Last updated: Dec 23 '16