Skip to content

Instantly share code, notes, and snippets.

@dmitryd
Last active February 8, 2022 10:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmitryd/791c6860660a68736e199891909f9710 to your computer and use it in GitHub Desktop.
Save dmitryd/791c6860660a68736e199891909f9710 to your computer and use it in GitHub Desktop.
Validate YAML file using Python one-liner
python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < file.yml
Needs "pip install pyyaml".
Source: https://liquidat.wordpress.com/2016/01/21/short-tip-verify-yaml-in-shell-via-python-one-liner/
@tdsan
Copy link

tdsan commented Dec 31, 2020

Z:\Cloud\yaml>pip install pyyaml
Requirement already satisfied: pyyaml in c:\users\v-csanders\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (5.3.1)

Z:\Cloud\yaml>python -c 'import yaml, sys;yaml.safe_load(sys.stdin))' < nginx.yaml
File "", line 1
'import
^
SyntaxError: EOL while scanning string literal

Seems like there seems to be a problem with the code, not sure why this does not work.

Todd

@johnstcn
Copy link

@tdsan you have a duplicated close parenthesis, it should work if you remove it.

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