YAML(YML)语法详解

ansible playbook是由yaml(yml)语法书写,结构清晰,可读性强,所以必须掌握yaml(yml)基础语法

语法 描述
锁进  YAML使用固定的缩进风格表示层级结构,每个缩进由两个空格组成,不能使用tabs键
冒号 以冒号结尾的除外,其他所有冒号后面必须有空格
短横线 表示列表项,使用一个短横杠加一个空格,多个项使用同样的缩进级别作为同一列表

 官方事例:https://yaml.org/start.html

Structure is shown through indentation (one or more spaces). Sequence items are denoted by a dash, and key value pairs within a map are separated by a colon.

结构通过缩进显示(一个或多个空格)。序列项用破折号表示,映射中的键值对用冒号分隔。

--- !clarkevans.com/^invoice
invoice: 34843
date   : 2001-01-23
bill-to: &id001
    given  : Chris
    family : Dumars
    address:
        lines: |
            458 Walkman Dr.
            Suite #292
        city    : Royal Oak
        state   : MI
        postal  : 48046
ship-to: *id001
product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball
      price       : 450.00
    - sku         : BL4438H
      quantity    : 1
      description : Super Hoop
      price       : 2392.00
tax  : 251.42
total: 4443.52
comments: >
    Late afternoon is best.
    Backup contact is Nancy
    Billsmer @ 338-4338.
原文地址:https://www.cnblogs.com/faberbeta/p/yml001.html