YAML (YAML Ain't Markup Language)

*Shreyash Bhise | Aspiring Mern Stack Developer and DevOps enthusiast,
Key-Value pair in YAML:
"apple" : "I am a red fruit"
1 : "This is kunal roll number"
{mango: "yellow fruit", age : 23}
List in YAML :
- apple
- banana
- cherry
- mango
cities:
- new delhi
- mumbai
- gujrat
cities: [new delhi, mumbai]
"apple" : "I am a red fruit"
1 : "This is kunal roll number"
---
- apple
- banana
- cherry
- mango
---
cities:
- new delhi
- mumbai
- gujrat
...
(---) You can see in the above program we can use --- to tell yaml that this are three different documents.
(...) You can use this to stop your yaml file
Data Type in YAML:
String Data Type:
domain: DevOps
fruit : "mango"
job : 'Software engineer'
Interger, Float,Boolean Data Type:
numbers: 5473
marks: 98.74
booleanvalue: No # n , N , false , FALSE
booleanvalue: yes # y , Y , true , TRUE
Sparse Sequence DataType:
sparse seq:
- hey
- how
-
- are you
- rutuja
Nested Sequences:
-
- mango
- cherry
- banana
-
- marks
- roll no
- dates
Ansible playbook example:
---
- name: Install and Start Nginx
hosts: webservers
become: true
tasks:
- name: Install Nginx package
apt:
name: nginx
state: present
- name: Start Nginx service
service:
name: nginx
state: started
enabled: yes
ansible-playbook -i inventory.ini playbook.yml
n this playbook:
The play is named "Install and Start Nginx" and targets the hosts in the
webserversgroup.The
become: truestatement allows the playbook to run with escalated privileges.Two tasks are defined:
The first task uses the
aptmodule to install the Nginx package, specifying the package name (nginx) and the desired state (present).The second task uses the
servicemodule to start the Nginx service, ensuring it is running and enabled to start at boot (enabled: yes).
Make sure you have an inventory file (e.g., inventory.ini) that lists the target hosts under the [webservers] group.




