Overview Of YAML

Tetteh Israel
FAUN — Developer Community 🐾
4 min readFeb 21, 2022

--

yaml.org

What Is YAML?

YAML is a digestible data serialization language often used to create configuration files with any programming language

The recursive YAML acronym stands for “YAML Ain’t Markup Language,” denoting it as flexible and data-oriented. In fact, it can be used with nearly any application that needs to store or transmit data. It’s essentially a structured data format that can be read by humans. It’s less complicated and unwieldy than XML or JSON, yet it offers equivalent functionality. It essentially enables you to provide powerful configuration settings without having to master more complex code types such as CSS, JavaScript, or PHP. YAML is designed to be straightforward to use from the start. A YAML file is used to define data at its core. One of the advantages of utilizing YAML is that the data in a single YAML file may be simply translated into a variety of languages.

Basic YAML Rules

YAML has specific restrictions in place to avoid concerns with ambiguity in regards to different languages and editing tools. These rules allow a single YAML file to be interpreted uniformly regardless of the application or library used to do so.

  • YAML files should end in .yml or .yaml
  • YAML case is sensitive
  • YAML does not allow the use of tabs

YAML Structure

---
# An employee record
name: Martin
job: Developer
skill: Elite
employed: True
foods:
- Apple
- Orange
- Strawberry
language:
perl: Elite
python: Elite
education: |
4 GCSEs
3 A-levels
  • Above are building blocks of YAML and every item in a YAML document is a member of at least one dictionary.
  • Everything in the YAML is a key-value pair; also known as Dictionary/Hash/Object/Map.
  • The keys are always strings and values can be of any data type that YAML supports like booleans, numbers, lists, arrays, and strings including multiline strings.
  • YAML doesn't allow the use of tab characters for indentations. Use spaces instead.
  • The files start with three dashes to indicate the start of a new YAML document.
  • Newlines indicate the end of a field

YAML Data Types

Comments

# this is a separate line comment
service: https # this is an inline-comment
  • comments begin with a # sign
  • Can be inline or on a separate line
  • They are ignored by YAML parsers

Numbers

---
integer: 99
float: 99.887
exponential: 1.43e+3
octal: 0123
not_a_number: .NAN
infinity: .inf
negative_infinity: -.inf
  • YAML supports integers, floats, and exponential
  • It’s also supports numbers like decimal, octal, hexadecimal, NAN ( Not A Number ), and infinity

Strings

string1: Hello there, this is Israel and i teach DevOps
string2: Hello there, this is Israel and \n i teach DevOps # escape sequences are not evaluated
string3: "Hello there, this si Israel \n i teach DevOps" # escape sequences are evaluated if enclosed in quotes
  • strings in YAML can be represented with or without quotes
  • But, escape sequences are evaluated only when strings are enclosed in double-quotes

Multiline Strings

---
string_with_fold: >
This is Israel
and I work as
DevOps Engineer.
string_with_pipe: |
This is Israel
and I work as
DevOps Engineer.
  • YAML supports multiline strings as a value to a key using the characters:

Fold (>): Does not interpret new lines.

Block (|): Interpret new lines.

List

---
list_01: [ 1, 2, 3 ]
list_02:
- 4
- 5
- 6
list_03:
- "one"
- "two"
- "three"
spec:
type: Nodeport
ports:
- port: 80
name: http
- port: 443
name: https

list in YAML supports both scalars and complex types like dictionaries/mappings.

Use Of YAML In DevOps

Many DevOps teams use YAML to design their development pipelines. Users can use pipeline features as a markup file and manipulate them like any other source file using YAML. Pipelines are versioned together with the code, allowing teams to quickly spot problems and undo changes. A developer uploads a source file to the repository’s root to add a YAML build definition.

Several tools with a prominent role in DevOps rely on YAML

  • Azure DevOps provides a YAML designer to simplify defining build and release tasks.
  • Kubernetes uses YAML to create storage and lightweight Linux virtual machines.
  • Docker features YAML files called Dockerfiles. Dockerfiles are blueprints for everything you need to run the software, including codes, runtime, tools, settings, and libraries.

Key Takeaway

  • YAML is a data-oriented language that has features derived from Perl, C, HTML, and other languages.
  • YAML is a superset of JSON that comes with multiple built-in advantages such as including comments, self-referencing, and support for complex data types.

Thanks for taking the time to read my blog ❤️. You can reach out to me on Twitter and LinkedIn

Please do leave a comment if you have any thoughts on the topic — I am open to learning and continuous improvement!

Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

--

--