Understanding Yamla - 了解 Yamla

Understanding Yamla

The default renderer SLS file is YAML renderer. YAML markup language is a kind of a number of powerful features. However, Salt used to map a small portion YAML very common data structures such as lists and dictionaries. Principle is to use the renderer YAML YAML data structure and data structure compiled into the Python Salt for use.

Although YAML syntax that it may seem daunting and simple, but when writing YAML for the SLS file, just remember three very simple rules.

Similar information also can refer to: Understanding YAML

RULE ONE: INDENTATION - Indent

YAML fixed indentation scheme shows the relationship between the data layer. Salt requirements for each level of indentation exactly two spaces. Do not use tab.

RULE TWO: COLONS - colon separator

Python dictionary just pairs. Other languages ​​may use this user data type identified as a hash or associative array.

Dictionary keyshown in YAML by the end of the string is terminated by a colon, valueby following the colon represents a string, separated by spaces:

my_key: my_value

In python, the above data is translated into:

{'my_key': 'my_value'}

There is an alternative method may be used in the form of the following expression dictionary key / value mapping relationship:

my_key:
  my_value

NOTE: The above syntax is valid YAML, but not common in the SLS file, because in most cases, the key value is not singular, but a list of values.

Dictionary structure can be nested:

first_level_dict_key:
  second_level_dict_key: value_in_second_level_dict

It corresponds in Python is:

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

RULE THREE: DASHES - dash

To show the list of items using a single dash followed by a space, the plurality of items when they have the same level of indentation, they are part of the same list.

- list_value_one
- list_value_two
- list_value_three

The list can also be of value in the form of key-value pairs. This is very common in the Salt:

my_dictionary:
  - list_value_one
  - list_value_two
  - list_value_three

In Python, which is translated as:

{'my_dictionary': ['list_value_one', 'list_value_two', 'list_value_three']}

LEARNING MORE

Learn more about how to YAML presented as more information Python data structures, a simple method is to use online YAML parser to see Python output.

This site offers a good choice to experience YAML parsing: http://yaml-online-parser.appspot.com/

TEMPLATING

The default file in the SLS are allowed Jinja statements and expressions. Refer to understand Jinja .

Guess you like

Origin blog.csdn.net/watermelonbig/article/details/91489192