Information Technology Reference
In-Depth Information
Lists are the other kind of data that can be stored in a YAML file. Lists contain ordered data.
Each value is not associated with a key, like in a key-value pair. Lists are used when having a
key for each value does not make sense. The items in a list are on separate lines, similar to
nested key-value pairs. The items start with a dash followed by a space. Here's an example
from a
.kitchen.yml
for a list of supported platforms, as key-value pairs with the name key,
name
:
platforms
:
-
name
:
ubuntu
-
10
.
04
-
name
:
ubuntu
-
12
.
04
-
name
:
ubuntu
-
12
.
10
-
name
:
ubuntu
-
13
.
04
-
name
:
centos
-
5
.
9
-
name
:
centos
-
6
.
4
-
name
:
debian
-
7
.
1
.
0
The previous example also shows how you can put key-value pairs inside of a list. (You can
also put lists inside of a key-value pair as well.) Similar to key-value pairs, the items in a list
can have any number of spaces before, as long as all the items have the same number of
spaces. The following would be equivalent to the last example:
platforms
:
-
name
:
ubuntu
-
10
.
04
-
name
:
ubuntu
-
12
.
04
-
name
:
ubuntu
-
12
.
10
-
name
:
ubuntu
-
13
.
04
-
name
:
centos
-
5
.
9
-
name
:
centos
-
6
.
4
-
name
:
debian
-
7
.
1
.
0
Values can also have a type.
kitchen.yml
files mostly deal with integers, strings, or arrays.
Values that start with a digit are interpreted as integers. Values that start with an alphabetical
character, enclosed by single quotes ('') or double quotes (“”), are interpreted as strings. Ar-
rays are enclosed by square brackets ([ ]), with values separated by commas. Here's an ex-
ample that puts all these concepts together:
network
:
- [
"forwarded_port"
, {
guest
:
80
,
host
:
8080
}
]
- [
"private_network"
, {
ip
:
"192.168.33.33"
}
]