YAML
Multiline
- yaml-multiline.info
- Multiline explained on stackoverflow
- See also
~/projects/yaml/examples/multiline.yml
Parse yaml
General issues
All cli parsers were, as of today (2019-10) not able to handle custom data types like ansible-vault uses them. Here are the issues:
- yq-python: Won't fix b/c of the
nature of yq-python, which converts data to json and uses
jq
for parsing. - shyaml
- yq-go is using
go-yaml
, and the bug is still open in go-yaml. - yaml-cli (Anyhow, yaml-cli stalled development, last commit 2016)
Example:
export YAML="/home/varac/projects/yaml/examples/ansible-vault-example.yml"
yq -y . < $YAML
yq -Y . < $YAML
dasel -f $YAML .
Tools
mikefarah/yq (go)
See yq.md
yq-python
Converts yaml to json and uses jq
for parsing.
- Can process
yaml
andxml
. - Con only parse, not modify yaml
Install:
pipx install yq
Usage:
yq .services.kubelet.extra_args < /var/lib/OpenAppStack/rke/cluster.yml
Issues:
dasel
https://github.com/TomWright/dasel
shyaml
Can only parse yaml.
Install
pipsi install shyaml
or
wget https://raw.githubusercontent.com/0k/shyaml/master/shyaml \
-O /usr/local/bin/shyaml && chmod a+x /usr/local/bin/shyaml
query
show all values:
cd ~/leap/git/bitmask
cat hiera/local1.yaml| shyaml get-values
get particular value:
cat hiera/local1.yaml| shyaml get-value domain
cat hiera/local1.yaml| shyaml get-value sources.apt
cat hiera/local1.yaml| shyaml sources.platform.apt.basic
Deprecated
yaml-cli (Warning: Last commit 2016)
https://github.com/pandastrike/yaml-cli
Validate / lint yaml
yamllint
- Docs
- Megalinter integration
- Megalinter looks for a
.yamllint.yml
config file
- Megalinter looks for a
- pre-commit hook
Install:
apt install yamllint
Usage:
yamllint hiera/local1.yaml
v8r
A command-line JSON, YAML and TOML validator that's on your wavelength v8r is a command-line validator that uses Schema Store to detect a suitable schema for your input files based on the filename.
- GitHub
- Javascript
- Megalinter integration
Other linters
or
cat hiera/local1.yaml| shyaml get-values
cat .gitlab-ci.yml| ysh
Format/fix yaml
prettier l.yml
prettier --write l.yml
Sort yaml
https://github.com/ddebin/yaml-sort
npm install -g yaml-sort
Yaml formaters
- prettier
- yamlfmt
- yamlfix
- Project is in Pull Request maintenance only
- Bug: Link with anchor gets split in comment
- Doesn't Crop long lines
- Bug: Re-joins multiline string values even when resulting line is longer
than the
YAMLFIX_LINE_LENGTH
Merging
https://stackoverflow.com/questions/66694238/merging-two-yaml-documents-while-concatenating-arrays
Convert json to yaml
yq eval -j resume.json > resume.yaml