Wednesday, June 20, 2018

YAML Fundamentals


Notes
All Ansible playbooks are written in YAML.
YAML - is a data structure format.
The # precedes all comments.
All YAML files can optionally begin with “----”
All YAML files can optionally end with “…”

Concepts
List/Array use Dictionaries to define the items within them.
Invalid number of spaces will generate an error message.


Key Value Pair
YAML’s fundamental data handlings are “Key Value Pair.”
Key - a variable.
Value - the value of the variable.
Key Value Pair = Key + Pair.
Syntax:
Key:(space)Value
A space after the semicolon is required.


How to type an Array/List
The Dash ( - ) means that the Pair that follows it is a part of an Array/List.
Syntax:
    Key:
         - (space)Key
  
Use a List/Array when it is multiple types of items of the same type of object.
For multiple List/Arrays the order of the Keys must be identical to each other.


How to type a Dictionary/Map
Syntax:
    Key:
        Key:(space)Pair
        Key: Pair

Use Dictionaries to add specific details about a specific individual item.
For multiple Dictionaries the Keys can be defined in any order as long as the values to those Keys exactly match.


List/Array with nested Dictionary
Syntax:
    Key/List_Name:
        - Key/List_Item:
            Key/Attribute_Detail: Pair
            Key/Attribute_Detail: Pair

Start your List/Array with a Key which will serve as the “Name” of the List/Array followed by a semi colon. Individual List/Array entries will follow the List/Array syntax. To add Attributes or Details to an individual item of the list nest a Dictionary under the specific List/Array entry following the Dictionary syntax.


Additional Educational Resources
1. Official YAML documentation.
2. Official Ansible documentation.