1
0

salt.renderers.yaml.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ===================
  2. salt.renderers.yaml
  3. ===================
  4. Understanding YAML
  5. ==================
  6. The default renderer for SLS files is the YAML renderer. YAML is a
  7. markup language with many powerful features. However, Salt uses
  8. a small subset of YAML that maps over very commonly used data structures,
  9. like lists and dictionaries. It is the job of the YAML renderer to take
  10. the YAML data structure and compile it into a Python data structure for
  11. use by Salt.
  12. Though YAML syntax may seem daunting and terse at first, there are only
  13. three very simple rules to remember when writing YAML for SLS files.
  14. Rule One: Indentation
  15. ---------------------
  16. YAML uses a fixed indentation scheme to represent relationships between
  17. data layers. Salt requires that the indentation for each level consists
  18. of exactly two spaces. Do not use tabs.
  19. Rule Two: Colons
  20. ----------------
  21. Python dictionaries are, of course, simply key-value pairs. Users from other
  22. languages may recognize this data type as hashes or associative arrays.
  23. Dictionary keys are represented in YAML as strings terminated by a trailing colon.
  24. Values are represented by either a string following the colon, separated by a space:
  25. .. code-block:: yaml
  26. my_key: my_value
  27. In Python, the above maps to:
  28. .. code-block:: python
  29. {"my_key": "my_value"}
  30. Dictionaries can be nested:
  31. .. code-block:: yaml
  32. first_level_dict_key:
  33. second_level_dict_key: value_in_second_level_dict
  34. And in Python:
  35. .. code-block:: python
  36. {"first_level_dict_key": {"second_level_dict_key": "value_in_second_level_dict"}}
  37. Rule Three: Dashes
  38. ------------------
  39. To represent lists of items, a single dash followed by a space is used. Multiple
  40. items are a part of the same list as a function of their having the same level of indentation.
  41. .. code-block:: yaml
  42. - list_value_one
  43. - list_value_two
  44. - list_value_three
  45. Lists can be the value of a key-value pair. This is quite common in Salt:
  46. .. code-block:: yaml
  47. my_dictionary:
  48. - list_value_one
  49. - list_value_two
  50. - list_value_three
  51. Reference
  52. ---------
  53. .. automodule:: salt.renderers.yaml
  54. :members: