What are a key-value pair, an object and a list in YAML, and when do you use a dash?
A key-value pair is key: value. An object (mapping) groups several key-value pairs at the same indentation, without dashes. A list (sequence) groups items, each starting with a dash and a space.
* Dashes mark list items; keys at the same indentation without dashes form one object. *
name: "Alice" # key-value pair
name: "Bob" # object: three pairs belong together
age: 30
active: true
- apple # list of scalars
- banana
- cherry
The rule that resolves most confusion: a dash starts a new list item, nothing else. Keys of an object need no dash, because the parser can already tell from the indentation and the key: colons which pairs belong together. If you put a dash in front of each key of what should be one object, you get a list of three one-key objects instead.
In Ansible's own vocabulary you will also meet "dictionary" or "mapping" for object, and "sequence" for list.
Go deeper:
YAML Syntax: YAML basics (official docs) — lists start with "- ", dictionaries are
key: value.YAML (Wikipedia) — mappings and sequences with examples.