Skip to content

Instantly share code, notes, and snippets.

@weirdbricks
Forked from xiii/ruby-yaml-validate.sh
Created January 27, 2017 01:11
Show Gist options
  • Save weirdbricks/0551992d946956844caf043779818979 to your computer and use it in GitHub Desktop.
Save weirdbricks/0551992d946956844caf043779818979 to your computer and use it in GitHub Desktop.
Validate YAML in ruby - useful for hiera
#!/bin/bash
#
# Efstathios Xagoraris <sxagoraris@gmail.com>
# Validate YAML files using ruby
#
ruby=/usr/share/logstash/vendor/jruby/bin/jruby
if [ $# -eq 0 ]
then
echo "Please provide a yaml file as argument eg $0 file.yaml"
exit 1
fi
$ruby -ryaml -e "YAML.parse(File.open('${1}'))"
if [[ $? -ne 0 ]]
then
echo "$1 is not valid YAML"
exit 1
else
echo "$1 is a valid YAML"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment