Introduction to Yaml

Introduction to Yaml

·

2 min read

YAML is quite popular in the DevOps tools. One of the main reasons why YAML's popularity has increased so much over the past few years is that it is super human-readable and intuitive which makes it a great tool for writing configuration files for DevOps tools like Docker, Kubernetes, Ansible, Prometheus, etc.

YAML - YET ANOTHER MARKUP LANGUAGE OR YAML AIN'T MARKUP LANGUAGE

  • YAML IS A DATA SENSATIONAL LANGUAGE LIKE XML AND JSON

  • EASY TO UNDERSTAND, HUMAN READABLE, CAN BE EASILY CONVERTED TO JSON, XML FILES

  • YAML is a superset of JSON: Any valid JSON file is also a valid YAML file.

So as YAML uses line separation and spaces with indentation instead of tags with angle brackets in XML and curly brackets in JSON. It’s a lot easier to understand by others than XML or JSON.

That is why DevOps tools like (Docker, Kubernetes, Ansible, Prometheus, etc.) use YAML for writing configuration files.

DATA Serialization LANGUAGE

Data Serialization is a process of converting the data objects that is present in some complex data structure into a stream of bytes that can be used to store, transfer and distribute on physical devices.
The reverse process of data serialization is called data deserialization.

File extensions must be .yaml or .yml

The --- symbol mark represents the start of a document.
The ... symbol mark represents the end of a document.
---     # DOCUMET STARTS HERE 

# KEY-VALUE PAIR 
    KEY: VALUE    
# OR CAN BE WRITTEN AS  
    KEY: "VALUE"

LISTS CAN BE WRITTEN AS

   hello: 
         - YAML
         - JSON
         - XML
# OR can be written as
-YAML -JSON -XML

lists mean SEQUENCE OF DATA

SEND:|     # THIS ALLOWS AS TO WRITE MULTIPLE LINES
THIS ALLOWS TO WRITE
IN MULTIPLE 
LINES
OF CODES
#MULTIPLE LINES OF CODE CAN BE CONSIDERED AS SINGLE LINE USING '>'

SEND:>
THIS IS
CONSIDERED 
AS SINGLE LINE
EVEN IT IS WRITTEN IN 
MULTIPLE LINES

#SAME AS 

SEND: THIS IS CONSIDERED AS SINGLE LINE EVEN IT IS WRITTEN IN MULTIPLE LINES
# LISTS CAN BE WRITTEN AS VALUES OF KEY AS

HEY:  !!seq
 [FRUIT: BANANA,VEGITABLE: CARRORT,JUICE: FROOTI]

# is SAME AS 

---
hEY:
 - FRUIT:BANANA
 - VEGITABLE:CARRORT
 - JUICE:FROOTI
---
# nested lists 
 hEY:
 - FRUIT:BANANA
   - VEGITABLE:CARRORT
 - JUICE:FROOTI
---

#THIS IS CALLED AS PAIRS 
#SAME KEY POINTING TOWARDS DIFFERENT VALUE

school: [job: teacher,job: principal]
#Data TYPES INT FLOAT DOUBLE LONG STRING BOOLEAN ect...

numbers:!!int 12 numbers:!!float 12.02 numbers:!!double 12_000_02 name:!!String
hello yep:!!boolean y

no :!!boolean No

Did you find this article valuable?

Support THARUN by becoming a sponsor. Any amount is appreciated!