Salt 和 Python 的 YAML 语法

YAML syntax for Salt and Python

这有什么区别:

dic1: 
  - subdict1.1: value11.1
  - subdict1.2: value1.2
  - cubdict1.3: value1.3

和这个:

dict2:
  subdict2.1: value2.2
  subdict2.1: value2.2
  subdict2.3: value2.3

我知道第一个评估为字典列表。但是第二个是什么?不也是字典列表吗?

不,它只是一个嵌套字典。

例子

YAML代码:

first_level_dict_key:
  second_level_dict_key: value_in_second_level_dict

结果 Python:

{
    'first_level_dict_key': {
        'second_level_dict_key': 'value_in_second_level_dict'
    }
}

解释来自saltdocs.

RULE TWO: COLONS

Python dictionaries are, of course, simply key-value pairs. Users from other languages may recognize this data type as hashes or associative arrays.

Dictionary keys are represented in YAML as strings terminated by a trailing colon. Values are represented by either a string following the colon, separated by a space