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
相關文章
相關標籤/搜索