YAML TutorialThis document is intended to be a short YAML tutorial, sufficient to get you started with YAML language. YAML is an indentation-based markup language which aims to be both easy to read and easy to write. Many projects use it because of its readability, simplicity and good support for many programming languages. Here’s an example of YAML document (which is actually a Taurus config): execution: - concurrency: 10 hold-for: 5m ramp-up: 2m scenario: yaml_example scenarios: yaml_example: retrieve-resources: false requests: - http://example.com/ reporting: - module: final-stats - module: console settings: check-interval: 5s default-executor: jmeter provisioning: local As you can see, YAML uses indentation to represent document structure (as opposed to JSON, which uses brackets and braces). Other than that, JSON and YAML are very similar. Here's the same YAML document converted to JSON: { "execution": [ { "concurrency": 10, "hold-for": "5m", "ramp-up": "2m", "scenario": "json_example" } ], "scenarios": { "json_example": { "retrieve-resources": false, "requests": [ "http://example.com/" ] } }, "reporting": [ { "module": "final-stats" }, { "module": "console" } ], "settings": { "check-interval": "5s", "default-executor": "jmeter" }, "provisioning": "local" } YAML SyntaxYAML document consists of the following elements. ScalarsScalars are ordinary values: numbers, strings, booleans. number-value: 42 floating-point-value: 3.141592 boolean-value: true # strings can be both 'single-quoted` and "double-quoted" string-value: 'Bonjour' YAML syntax also allows unquoted string values for convenience reasons: unquoted-string: Hello World Lists and DictionariesLists are collections of elements: jedis: - Yoda - Qui-Gon Jinn - Obi-Wan Kenobi - Luke Skywalker Every element of the list is indented and starts with a dash and a space. Dictionaries are collections of key: value mappings. All keys are case-sensitive. jedi: name: Obi-Wan Kenobi home-planet: Stewjon species: human master: Qui-Gon Jinn height: 1.82m Note that a space after the colon is mandatory. Dictionaries can be nested in lists (and vice versa) to create more complex structures: requests: # first item of `requests` list is just a string - http://example.com/ # second item of `requests` list is a dictionary - url: http://example.com/ method: GET You can also use inline syntax for lists and dictionaries, if you want: episodes: [1, 2, 3, 4, 5, 6, 7] best-jedi: {name: Obi-Wan, side: light} YAML Multi DocumentsYAML format allows multiple documents to be embedded in a single file. They only have to be separated with a line containing triple-dash separator ---. document: this is document 1 --- document: this is document 2 When reading multi-document YAML, Taurus will treat multiple documents as multiple configs and will load them one by one. YAML Debugging tipsThere's a number of tools you can use to help you to locate and fix syntactical errors in your YAML document.
YAML GotchasDue to the format aiming to be easy to write and read, there are some ambiguities in YAML. Special characters in unquoted stringsYAML has a number of special characters you cannot use in unquoted strings: ` [] {} : > | `. You should quote all strings that contain any of the following characters the following way: special-characters: "[all] {quoted} :like> this|" Tabs versus spaces for indentationDo not use tabs for indentation. While resulting YAML can still be valid, this can be a source of many subtle parsing errors. Just use spaces. Additional YAML resources
|
On this page:
Quick Links: |