Skip to content

Instantly share code, notes, and snippets.

@HariSekhon
Created June 7, 2024 10:50
Show Gist options
  • Save HariSekhon/4b7fc45150d990eb706e807a65c7772c to your computer and use it in GitHub Desktop.
Save HariSekhon/4b7fc45150d990eb706e807a65c7772c to your computer and use it in GitHub Desktop.
yaml.md from HariSekhon/Knowledge-Base repo: https://github.com/HariSekhon/Knowledge-Base

YAML - Yet Another Markup Language

YAML is used for configuration by many technologies as it's easier and cleaner to read and write than JSON / XML.

Worth a read:

https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html

https://spacelift.io/blog/yaml

https://www.educative.io/blog/advanced-yaml-syntax-cheatsheet

YAML Linting

Always lint your YAML to catch otherwise hard to spot whitespace errors such as inconsistent indentation or tabs vs spaces.

I use YAMLLint which is automatically installed by DevOps-Bash-tools and you can run the check_yaml.sh script in that repo to recurse the current or given directory and check all the YAML files.

I run this automatically in all my GitHub repos via CI/CD.

Advanced YAML

Anchors and References

Use & prefix anchor to mark a section and * to reference to it later in the same YAML to reduce duplication.

Override / Extend - Anchors and References

Prefix the *<name> reference with <<: to allow you to add more fields underneath it. Same name fields are overridden.

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