YAML语法

YAML语法是ansible剧本的表达方式。python

  • 全部YAML均可以选择以--—开始和...结束
  • 列表的全部成员都是以“-”开头的相同缩进级别的行(一个破折号和一个空格):
---
# A list of tasty fruits
- Apple
- Orange
- Strawberry
- Mango
...
  • 字典以简单的形式表示(冒号后面必须有一个空格)
# An employee record
martin:
    name: Martin D'vloper
    job: Developer
    skill: Elite
  • 更为复杂的数据结构
# Employee records
-  martin:
    name: Martin D'vloper
    job: Developer
    skills:
      - python
      - perl
      - pascal
-  tabitha:
    name: Tabitha Bitumen
    job: Developer
    skills:
      - lisp
      - fortran
      - erlang

也能够用缩写形式:数据结构

---
martin: {name: Martin D'vloper, job: Developer, skill: Elite}
['Apple', 'Orange', 'Strawberry', 'Mango']
  • 值可使用|或>跨多行。使用“文字块标量”|跨越多行将包括新行和任何尾随空格。使用“折叠块标量”>将新行折叠到空格;它被用来使本来很长的一行更容易阅读和编辑。
include_newlines: |
            exactly as you see
            will appear these three
            lines of poetry

fold_newlines: >
            this is really a
            single line of text
            despite appearances
  • 示例
---
# An employee record
name: Martin D'vloper
job: Developer
skill: Elite
employed: True
foods:
    - Apple
    - Orange
    - Strawberry
    - Mango
languages:
    perl: Elite
    python: Elite
    pascal: Lame
education: |
    4 GCSEs
    3 A-Levels
    BSc in the Internet of Things
相关文章
相关标签/搜索