Skip to content

Yaml

Overview

YAML (YAML Ain't Markup Language) is a human-readable serialization format commonly used for configuration files and data exchange between web servers, in particular, in cloud computing and DevOps.

YAML is often confused with JSON, but they are different. JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. JSON is a subset of the object literals of JavaScript. Although JSON is a subset of JavaScript, it is language-independent and so can be used with many programming languages including Python, Java, C#, and many others.

The main difference between YAML and JSON is that YAML is more human-readable and easier to write, while JSON is more machine-readable and easier to parse. YAML also supports more advanced data structures such as sets, ordered maps, and Unicode strings, which are not available in JSON.

Tools using YAML

Some of the most popular tools using YAML include:

  • Kubernetes (k8s): uses YAML to define the configuration of its resources, such as pods, services, and deployments.
  • Ansible: uses YAML to define the configuration of its playbooks, which are used to automate the deployment and management of infrastructure.
  • Docker: uses YAML to define the configuration of its Compose files, which are used to define and run multi-container Docker applications.
  • OpenAPI: uses YAML to define the configuration of its API definitions, which are used to describe RESTful APIs.
  • Terraform: uses YAML to define the configuration of its infrastructure as code, which is used to provision and manage infrastructure.
  • AWS CloudFormation: uses YAML to define the configuration of its templates, which are used to provision and manage AWS infrastructure.
  • CircleCI: uses YAML to define the configuration of its workflows, which are used to automate the testing and deployment of software.
  • GitLab CI/CD: uses YAML to define the configuration of its pipelines, which are used to automate the testing and deployment of software.

Concepts

Data Types

Type Description
Scalar Single value, e.g. string, number, etc.
Sequence Ordered list of values, e.g. list, array.
Mapping Unordered dictionary of key-value pairs.
Set Unordered collection of unique values.
Null Represents the absence of a value.
Boolean Represents true or false values.

There are different treatmeant within string scalars |-, |, |+ and >

Handlers

Handler Description
\|- Verbatim text, no escaping, no newlines.
\| Verbatim text, no escaping, with newlines.
\|+ Indented text, no escaping, with newlines.
> Interpreted text, with newlines, single string.

Read this: https://www.baeldung.com/yaml-multi-line