G
GuideDevOps
Lesson 3 of 9

Scalars, Lists & Mappings

Part of the YAML tutorial series.

1. Scalars (Simple Values)

Scalars are the most basic data types. They represent a single value.

Strings

In YAML, quotes are usually optional for strings.

name: GuideDevOps      # No quotes needed
path: /usr/local/bin   # No quotes needed

However, you must Use Quotes if:

  • The string contains special characters like : or #.
  • The string looks like a number but should be treated as text (e.g., "1.0").

Numbers & Booleans

YAML natively understands integers, floats, and booleans (true/false).

⚠️ The "Norway Problem"

One of the most famous bugs in programming history happened because of YAML scalars. In older versions of YAML, the countries abbreviations NO (Norway) and OFF were automatically parsed as Booleans (false).

countries:
  - US
  - NO   # THIS BECOMES 'false' INSTEAD OF 'NO'!

The Fix: Always wrap short country codes or "Yes/No" style strings in quotes: "NO".


2. Lists (Sequences)

A List is an ordered collection of items. Each item is denoted by a Hyphen and a Space (- ).

environments:
  - production
  - staging
  - development

Flow Style (JSON-like)

You can also write lists on a single line using square brackets, though this is less common in DevOps:

environments: [production, staging, development]

3. Mappings (Dictionaries)

A Mapping is a collection of Key-Value pairs. This is how you represent complex objects.

server:
  host: 127.0.0.1
  port: 8080
  protocol: https

Combining Them Together

The true power of YAML comes from nesting these types. In Kubernetes, almost every file is a Mapping that contains other Mappings and Lists.

# A Mapping (the document)
metadata:
  name: my-web-app   # A Scalar
  labels:            # A Mapping
    app: frontend
    tier: web
containers:          # A List
  - name: nginx
    image: nginx:latest
  - name: redis
    image: redis:alpine