YAML

YAML is the syntax used for Ansible playbooks and some other files. The official YAML documentation contains the full specifications of the syntax. Here is a compact version as it pertains to the most common usage for Ansible:

  • A YAML file starts with three dashes (---)
  • Whitespace indentation is used to denote structures when they are lined up, just like Python
  • Comments begin with the hash (#) sign
  • List members are denoted by a leading hyphen (-), with one member per line
  • Lists can also be denoted via square brackets ([]), with elements separated by a comma (,)
  • Dictionaries are denoted by key: value pairs, with a colon for separation
  • Dictionaries can be denoted by curly braces, with elements separated by a comma (,)
  • Strings can be unquoted, but can also be enclosed in double or single quotes

As you can see, YAML maps well into JSON and Python datatypes. If I were to rewrite df_playbook.yml into df_playbook.json, this is what it would look like:

        [
{
"hosts": "192.168.199.170",
"tasks": [
"name": "check disk usage",
"shell": "df > df_temp.txt"
]
}
]

This is obviously not a valid playbook, but serves as an aid in helping to understand the YAML formats while using the JSON format as a comparison. Most of the time, comments (#), lists (-), and dictionaries (key: value) are what you will see in a playbook.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset