Skip to content

Instantly share code, notes, and snippets.

@xiii
Last active April 20, 2020 06:10
Show Gist options
  • Save xiii/96381e41f66e5cf6a72d to your computer and use it in GitHub Desktop.
Save xiii/96381e41f66e5cf6a72d 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
#
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
@xiii
Copy link
Author

xiii commented Apr 20, 2020

Looks much better! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment