Getting Started

Two Documents

---
document: this is doc 1
---
document: this is doc 2

YAML uses --- to separate directives from document content.

Folded strings

description: >
 hello
 world

#↓ Equivalent JSON

{"description": "hello world\n"}

Reference

values: &ref
  - Will be
  - reused below

other\_values:
  i\_am\_ref: \*ref

#↓ Equivalent JSON

{
  "values": [
    "Will be",
    "reused below"
  ],
  "other\_values": {
    "i\_am\_ref": [
      "Will be",
      "reused below"
    ]
  }
}

Inheritance

parent: &defaults
  a: 2
  b: 3
child:
  <<: \*defaults
  b: 4

#↓ Equivalent JSON

{
  "parent": {
    "a": 2,
    "b": 3
  },
  "child": {
    "a": 2,
    "b": 4
  }
}

Multiline strings

description: |
 hello
 world

#↓ Equivalent JSON

{"description": "hello\nworld\n"}

Comments

# A single line comment example
# block level comment example
# comment line 1
# comment line 2
# comment line 3

Variables

some\_thing: &VAR\_NAME foobar
other\_thing: \*VAR\_NAME

#↓ Equivalent JSON

{
  "some\_thing": "foobar",
  "other\_thing": "foobar"
}

Scalar types

n1: 1            # integer 
n2: 1.234        # float 
s1: 'abc'        # string 
s2: "abc"        # string 
s3: abc          # string 
b: false         # boolean type 
d: 2015-04-05    # date type

#↓ Equivalent JSON

{
  "n1": 1,
  "n2": 1.234,
  "s1": "abc",
  "s2": "abc",
  "s3": "abc",
  "b": false,
  "d": "2015-04-05"
}

Use spaces to indent. There must be space between the element parts.

Introduction

YAML is a data serialisation language designed to be directly writable and readable by humans

  • YAML does not allow the use of tabs
  • Must be space between the element parts
  • YAML is CASE sensitive
  • End your YAML file with the .yaml or .yml extension
  • YAML is a superset of JSON
  • Ansible playbooks are YAML files
Comments