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 @   忘川的彼岸  阅读(350)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示