updated yaml syntax and gotchas

specifically added example for getting strings that match boolean values
pull/13189/head
Brian Coca 9 years ago
parent 355fa4797a
commit 1f34c6b214

@ -20,52 +20,52 @@ Each item in the list is a list of key/value pairs, commonly
called a "hash" or a "dictionary". So, we need to know how called a "hash" or a "dictionary". So, we need to know how
to write lists and dictionaries in YAML. to write lists and dictionaries in YAML.
There's another small quirk to YAML. All YAML files (regardless of their association with There's another small quirk to YAML. All YAML files (regardless of their association with Ansible or not) can optionally
Ansible or not) should begin with ``---``. This is part of the YAML begin with ``---`` and end with ``...``. This is part of the YAML format and indicates the start and end of a document.
format and indicates the start of a document.
All members of a list are lines beginning at the same indentation level starting All members of a list are lines beginning at the same indentation level starting with a ``"- "`` (a dash and a space)::
with a ``"- "`` (a dash and a space)::
--- ---
# A list of tasty fruits # A list of tasty fruits
- Apple fruits:
- Orange - Apple
- Strawberry - Orange
- Mango - Strawberry
- Mango
...
A dictionary is represented in a simple ``key: value`` form (the colon must be followed by a space):: A dictionary is represented in a simple ``key: value`` form (the colon must be followed by a space)::
---
# An employee record # An employee record
name: Example Developer - martin:
job: Developer name: Martin D'vloper
skill: Elite job: Developer
skill: Elite
Dictionaries can also be represented in an abbreviated form if you really want to:: Dictionaries and lists can also be represented in an abbreviated form if you really want to::
--- ---
# An employee record employees:
{name: Example Developer, job: Developer, skill: Elite} - martin: {name: Martin D'vloper, job: Developer, skill: Elite}
fruits: ['Apple', 'Orange', 'Strawberry', 'Mango]
.. _truthiness: .. _truthiness:
Ansible doesn't really use these too much, but you can also specify a Ansible doesn't really use these too much, but you can also specify a boolean value (true/false) in several forms::
boolean value (true/false) in several forms::
---
create_key: yes create_key: yes
needs_agent: no needs_agent: no
knows_oop: True knows_oop: True
likes_emacs: TRUE likes_emacs: TRUE
uses_cvs: false uses_cvs: false
Let's combine what we learned so far in an arbitrary YAML example. This really
has nothing to do with Ansible, but will give you a feel for the format:: Let's combine what we learned so far in an arbitrary YAML example.
This really has nothing to do with Ansible, but will give you a feel for the format::
--- ---
# An employee record # An employee record
name: Example Developer name: Martin D'vloper
job: Developer job: Developer
skill: Elite skill: Elite
employed: True employed: True
@ -79,8 +79,7 @@ has nothing to do with Ansible, but will give you a feel for the format::
python: Elite python: Elite
dotnet: Lame dotnet: Lame
That's all you really need to know about YAML to start writing That's all you really need to know about YAML to start writing `Ansible` playbooks.
`Ansible` playbooks.
Gotchas Gotchas
------- -------
@ -100,6 +99,14 @@ with a "{", YAML will think it is a dictionary, so you must quote it, like so::
foo: "{{ variable }}" foo: "{{ variable }}"
The same applies for strings that start or contain any YAML special characters `` [] {} : > | `` .
Boolean conversion is helpful, but this can be a problem when you want a literal `yes` or other boolean values as a string.
In these cases just use quotes::
non_boolean: "yes"
other_string: "False"
.. seealso:: .. seealso::

Loading…
Cancel
Save