Skip to main content

Command Palette

Search for a command to run...

YAML for DevOps Engineers: YAML Overview

This article gives an overview to YAML specifically for DevOps engineers.

Updated
7 min read
YAML for DevOps Engineers: YAML Overview
S
Security Engineer and Technical Writer

You've cloned a repo, opened a .yml file, and instantly felt lost. You're not alone — and by the end of this, you won't be

What is YAML?

Depending on whom you ask, YAML stands for "Yet Another Markup Language" or "YAML ain’t markup language".The latter is recursive acronym, which emphasizes that YAML is for data, not documents.

YAML is a human-readable data serialization language used for configuration files, data exchange, and storing structured data.

YAML being a data serialization language just means it’s a way to write down information — like settings, lists, or instructions — in a simple, organized text format that both people and machines can understand. It was designed to be simple, intuitive, and easy to read and write for both humans and machines.

For example, imagine telling a friend how to set up your coffee maker:

coffee-maker:
  brand: XYZ
  settings:
    strength: strong
    cups: 2
  extras:
    - milk
    - sugar   

That’s YAML. It’s not code, it’s just a clear way to save or share data. Computers can read it, change it, and use it — and you can look at it and instantly get what it means, no decoder ring needed.

So in plain terms:
YAML = A simple, clean way to write down data so both you and a computer know what’s going on.

Why YAML Matters for DevOps Engineers

YAML matters for DevOps engineers because it’s the go-to language for infrastructure as code (IaC) and it is highly used for automation in DevOps automation tools.

It’s used in key DevOps tools like Kubernetes, Ansible, Docker Compose, and CI/CD pipelines (e.g., GitHub Actions, GitLab CI) to define configurations in a clear, readable way.

DevOps teams rely on YAML to version-control infrastructure, making infrastructure setups repeatable, consistent, and easy to share.

YAML is also has a human-friendly syntax (no brackets, simple indentation) thereby reducing errors and speeds up editing compared to JSON or XML. YAML integrates smoothly across systems and platforms.

In a nutshell, YAML allows DevOps engineers write, manage, and automate infrastructure like code — clearly and reliably.

YAML Syntax

YAML files use a .yml or .yaml extension, and follow specific syntax rules. It's syntax is clean and indentation-based, making it easy to read and write. In this section we will cover Key-Value pairs, Lists, Dictionaries, Anchors, Aliases, Comments and Multi-line Strings.

  1. Key-Value Pairs

The most basic structure in YAML is the key-value pair, where a key is associated with a specific value using a colon.

To write a Key-Value Pair, you write the key accompanied with a colon and space.

In this example, name, language, and version are keys with the values YAML in DevOps, yaml, and 1.0 respectively.

name: DevOps Pipeline
language: yaml
version: 1.0
  1. Lists (Sequences)

In YAML, you use lists to mention a collection of items. Items can be similar or dissimilar. Coming from the angle of data types, YAML lists can contain different items of variable data types. Use - followed by a space to list items in a List.

Lists are commonly used in configurations for:

  • Pipeline steps on GitLab

  • Container definitions

  • Dependency lists

Content:
  - Apple
  - 2
  - 1.0
  - Sang
  1. Multi-line Strings

You can write String data types in YAML in different ways. One common way is the use of "" and '' .

But what if you want to write a string that has multiple lines and you don't want to use line breaks?

The only answer to that is to use | (literal) or > (folded). The literal allows you to write your string in lines without using line breaks \n .

The Folded on the other hand picks your lines and puts them in a paragraph for you. It is the opposite of the literal string format.

literal: |
  This keeps
  line breaks.

folded: >
  This folds lines
  into one paragraph.
  1. Comments

The best DevOps Engineers use Comments in their YAML configurations for clarity and organization to whoever reads it and for documentation purposes as well.

Comments allow you to explain the configuration within your YAML file in the file.

All you have to do is start your comments with the # symbol.

Comments are always ignored when your YAML file is being executed as it is for other programming languages.

# This is comment and it is ignored
active: true
  1. Dictionaries (Maps)

Dictionaries or maps are collections of key-value pairs grouped together as a value to a parent key. Here, the server is the key, while host, port, and environment are the values in this dictionary.

server:
  host: localhost
  port: 8080
  environment: development
  1. Anchors and Aliases

YAML provides a way to reuse configuration using anchors and aliases. You write anchors with the & symbol, and call the anchor with an * .

The anchor stores the configuration you want to reuse while the alias calls the configuration for reuse instead of re-writing it from scratch.

default: &default_settings
  retries: 3
  timeout: 30

service1:
  <<: *default_settings

service2:
  <<: *default_settings

In this example:

  • &default_settings creates an anchor

  • *default_settings references the anchor

This allows you to reuse configuration without repeating code.

Differences Between YAML, JSON, and XML

Feature YAML JSON XML
Full Name YAML Ain't Markup Language JavaScript Object Notation eXtensible Markup Language
Readability Very high (designed for humans) Moderate Low (more verbose)
Syntax Style Indentation-based Brackets {} and [] Tags <tag></tag>
Comments Support Yes (#) No Yes
Data Structure Support Key-value pairs, lists, dictionaries Objects and arrays Nested elements
Verbosity Low Medium High
Ease of Writing Very easy Easy More complex
Common Use Cases DevOps configs, CI/CD pipelines, container orchestration APIs, web applications, data exchange Legacy systems, document markup
DevOps Tool Usage Very common Occasionally used Rare
Example Tools Kubernetes, GitHub Actions, Docker Compose Web APIs, configuration files Enterprise integrations

Simple Example Comparison Between YAML, JSON and XML

YAML

name: DevOps
tools:
  - Docker
  - Kubernetes

JSON

{
  "name": "DevOps",
  "tools": ["Docker", "Kubernetes"]
}

XML

<config>
  <name>DevOps</name>
  <tools>
    <tool>Docker</tool>
    <tool>Kubernetes</tool>
  </tools>
</config>

Application of YAML in DevOps

YAML is used in different aspects of DevOps. Some of the Tools and concepts that leverage YAML for configuration, automation, setup, etc, as as follows:

  • CI/CD Pipelines: YAML allow DevOps engineers to describe the steps required to build, test, and deploy applications automatically. Platforms like GitHub Actions, GitLab CI, and CircleCI use YAML for CI/CD Pipelines.

  • Infrastructure as Code (IaC): Tools like Terraform and AWS CloudFormation use YAML to define cloud resources like servers, networks, and databases.

  • DevOps & Automation: YAML is used to write playbooks and automate server setup and deployment. A tool like Ansible is used for this.

  • Container Management: YAML is heavily used in container orchestration platforms like Kubernetes. Docker Compose use YAML to define how apps should run, what resources they need, and how they’re connected. DevOps engineers use YAML files to define the desired state of containerized applications.

  • Application Configs: Many apps use YAML files to store settings (like database connections or feature flags) because it’s clear and supports comments.

Conclusion

YAML lets DevOps engineers write, manage, and automate infrastructure like code — clearly and reliably.

As a DevOps Engineer, the earlier you learn and master it, the better your debugging and configuration setup gets.

This article is one out of a series of YAML articles on my blog on Hashnode. Checkout my blog for upcoming YAML articles about Mistakes DevOps Engineers make when writing YAML, YAML Best Practices, YAML for Kubernetes, YAML in CI/CD Pipelines, etc.

YAML for DevOps Engineers

Part 1 of 1

Explaining and understanding YAML for DevOps Engineers. This series covers common mistakes DevOps engineers do when writing YAML, best practices when writing YAML, YAML in CI/CD, Kubernetes, etc.