YAML语法

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

  • 所有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
posted @ 2019-11-26 20:43  忘川的彼岸  阅读(349)  评论(0编辑  收藏  举报