Joys of YAML parsing

Yaml parsing is tricky and sometimes puppet will complain about syntactically incorrect YAML file without actually telling which YAML file is causing the problem. In such scenarios the following ruby code can help in locating the problematic YAML file.

 require 'yaml'
 d = Dir["./**/*.yaml"]
 d.each do |file|
 begin
 puts "Loading file : #{file}"
 f =  YAML.load_file(file)
 rescue Exception
 puts "Found the culprit #{file}: #{$!}"
 end
 end

Put the above code in parse.rb file and now you can execute it using ‘ruby parse.rb’ from any top level dir which contains your YAML files.