YAML is a data-representation format. There are no executable commands, which makes the language highly secure when exchanging files with third parties. If a user wishes to add an executable command, YAML must be integrated with other languages. Add Perl parsers, for example, to enable Perl code execution. It also derives features from other languages:. YAML supports all essential data types, including nulls, numbers, strings, arrays, and maps. It recognizes some language-specific data types, such as dates, timestamps, and special numerical values.
Maps associate name-value pairs, a vital aspect of setting up data. A YAML configuration file can start like this:. Both codes have two values, v3 and Pod , mapped to two keys, apiVersion and kind. In YAML, the quotation marks are optional, and there are no brackets. This markup language allows you to specify more complex structures by creating a key that maps to another map rather than a string.
See the YAML example below:. We have a key metadata with two other keys as its value name and labels. The labels key has another map as its value. YAML allows you to nest maps as far as you need to. The number of spaces does not matter, but it must be consistent throughout the file. In our example, we used two spaces for readability.
Name and labels have the same indentation level, so the processor knows both are part of the same map. A list may contain any number of items. An item starts with a dash, while indentation separates it from the parent. You can also store maps within a list:. We have a list of containers objects. Each consists of a name, an image, and a list of ports. Each item under ports is a map that lists the containerPort and its value.
However, there are significant differences between the two:. The best example of this is the official YAML homepage. That website is itself valid YAML, yet it is easy for a human to read.
Users can also convert most documents between the two formats. These files store parameters and settings for the desired cloud environment. Ansible users create so-called playbooks written in YAML code that automate manual tasks of provisioning and deploying a cloud environment.
Once set, a playbook is run from the command line. While the path varies based on the setup, the following command runs the playbook:. YAML allows users to approach pipeline features like a markup file and manage them as any source file. YAML handcrafted anchors and references as well as key merging are preserved.
The merged keys can transparently be accessed using [] and. The CommentedMap , which is the dict like construct one gets when round-trip loading, supports insertion of a key into a particular position, while optionally adding a comment:.
The above was inspired by a question posted by demux on StackOverflow. By default ruamel. You can change this default indentation by e.
0コメント