YAML Basics
Ansible uses YAML syntax for expressing Ansible playbooks. In this section we summarize some of the syntax needed in this exercise.
Key-value pair
YAML uses simple key-value pair to represent the data. The dictionary is
represented in key: value
(keep the blank space) pair. For instance:
--- # Optional YAML start syntax
Richard:
name: Richard Berger
age: 0
occupation: HPC guru
... # Optional YAML end syntax
You can also represent dictionaries in abbreviated form.
Richard: {name: Richard Berger, age: 0, occupation: HPC guru}
Lists
We can also represent List in YAML. Every member of a list should be written in a new line with same indentation starting with -
(- and space). Example:
---
Series:
- GOT
- Money heist
- The Simpsons
- Lost
- Friends
...
Lists also can be represented in the abbreviated form:
Series: ['GOT', 'Money heist', 'The Simpsons', 'Lost', 'Friends']
It is possible to have lists inside dictionaries:
---
Fernando:
name: Fernando Posada
age: xx
Series:
- GOT
- Money heist
- The Simpsons
- Lost
- Friends
...
or even, lists of dictionaries
---
hpc:
- Fernando:
name: Fernando Posada
age: xx
Series:
- GOT
- Money heist
- The Simpsons
- Lost
- Friends
- Richard:
name: Richard Berger
age: 0
occupation: HPC guru
...
Finally, it is possible to use boolean values in YAML, for instance, passed: True
. You can check whether your YAML scripts are valid using any on-line checker, for instance this one