Skip to content

Latest commit

 

History

History
96 lines (63 loc) · 2.55 KB

File metadata and controls

96 lines (63 loc) · 2.55 KB

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.

References

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

https://spacelift.io/blog/yaml

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

http://yaml.org/refcard.html

Key Points

Yaml better than JSON, adds:

  • comments

  • extensible data types

  • relational anchors

  • strings without quotation marks

  • mapping types preserving key order

  • must quote these constructs:

    • colon followed by space or EOL
    • string literal "True" (otherwise assumes boolean)
    • string literal "1.2" (otherwise assumes float)
- list_item1
- list_item2:
  key1: val1
  key2: val2

        |
        line1
        line2
        line3

        >
        single
        long
        line

YAML Linting

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

From DevOps-Bash-tools, recursively find and lint all *.yaml / *,yml files:

check_yaml.sh

From DevOps-Python-tools, recursively find and lint all *.yaml / *,yml files:

validate_yaml.py .

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

Readme Card

Readme Card

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.

Meme

Fixing YAML

Fixing YAML