YAML In Ansible

Ansible makes use of YAML syntax for expressing Ansible playbooks.

GOING THROUGH YAML

Key-value pair
YAML uses an easy key-value pair to represent the information. The lexicon is depicted in key: worth combine.

Note-There ought to be house between : and worth

Example: A person record

--- #Optional YAML start syntax 
janardhan: 
   name: janardhan 
   age: 34 
   city: Noida 
   sex: male 
... #Optional YAML end syntax 

Abbreviation

You may also use abbreviation to represent dictionaries.

Example

janardhan: {name: janardhan, age: 34, city: Noida, sex: male}

List inside Dictionaries

We can use a list inside dictionaries, i.e., the value of the key is listed.

Example

---  
janardhan: 
   name: janardhan 
   age: 34 
   city: Noida 
   sex: male 
   likes: 
      - cricket 
      - driving 
      - gaming
... 

List of Dictionaries

We can also make a list of dictionaries.

Example

---  
- janardhan: 
   name: janardhan 
   age: 34 
   city: Noida 
   sex: male 
   likes: 
     - cricket 
      - driving 
      - gaming 

- ravikishan: 
    name: ravikishan 
    age: 53 
    city: patna 
    sex: male 
    likes: 
      - computers 
      - chess 
... 

Newlines in multiple lines are displayed using “|” in YAML file and newlines are suppressed using “>” in YAML file. Because of this we are able to scan and edit massive lines. In each case intendentation are going to be unheeded.

We can additionally represent Boolean (True/false) values in YAML. wherever Boolean values will be case insensitive.

Example

---  
- janardhan: 
   name: janardhan 
   age: 34 
   city: Noida 
   sex: male 
   likes: 
      - cricket 
      - driving 
      - gaming

   
   messageIncludeNewLines: | 
      Congratulation!! 
      You are awesome 
Subscribe Now