In this post, You learn frequently questions and answers

what is YAML?

YAML abbreviated as Ain’t Markup Language, serialization for storing configuration data. It is easy to read by humans.

It is similar and superset to JSOn with easy readable with minimal syntax It supports multiple programming languages for read and write yaml files and extension is .yaml these can also used by automation build tool like ansible, Kubernets for resources configuration and deployment pipelines.

YAML file contains key and value pairs with data format syntax rules.

Key can be string and values can be scalar as well as list and map types.

These files can be opened and created with popular IDE as well as simple notepad editor. Syntax and yamllint provided by plugins or extensions of IDE can be used to auto format and validation errors. Content of the file can validated using validation tools.

How to create yaml files?

YAML files can be created with simple notepad tool or popular IDES like Visual studio, Sublime and ATOM.

YAML file can be created like text or json file with extension is .yaml. These extensions are not standard, but can also use .yml extension.

Writing a content in yaml file follows some syntax rules for key and value types.

There is no support for format in notepad. IDE’s provides plugins or extension to auto format, syntax validation and linting the content of an file.

Some online tools also provides to create and validate yaml files .

Does Ansible uses YAML or JSON files?

Ansible uses YAML for writing playbooks by default. Ansible does not support json format as YAML is easy to read and write with human readable data format. Ansible playbooks contains play to automate process with yaml file format.

IS YAML and JSON are same or different?

YAML and json both are used as data format serialization language used to configure environment details.

YAML is an superset of JSOn with more advanced features.

Both are supported by popular languages java,python and nodejs.

YAML files are more readable than JSON, However processing JSON files are faster compared with YAML files.

JSON content in yaml file is a valid whereas valid yaml is not included in JSON file.

JSON is more of data agreement format used to send and received between client and server systems. YAML is more of configuration storing data for different environments like QA,STAGE and PRODUCTIOn for deployments and build process

for example, YAML array example can be declared as follows

countries: [INDIA,USA, EUROPE,GERMANY,SINGAPORE]

the same above can be rewritten in json as follows

{
  "countries": [
    "INDIA",
    "USA",
    "EUROPE",
    "GERMANY",
    "SINGAPORE"
  ]
}