Search code examples
pythonyamlsalt-project

YAML syntax for Salt and Python


What is the diference between this:

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

and This:

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

I know the first one evaluates to a list of dictionaries. but what is the second one? isn't also a list of dictionaries?


Solution

  • No, it is just a nested dictionary.

    Example

    YAML code:

    first_level_dict_key:
      second_level_dict_key: value_in_second_level_dict
    

    Results in Python:

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

    Explanation from salt docs.

    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