About Ansible YAML Basics
YAML can be understood as a human-readable data serialization language generally used for writing configuration files. It is abbreviated to highlight that it is a markup language, not a document, depending on who you ask. It stands for Yet Another Markup Language or YAML ain’t markup language. It can be used to store data.

YAML is preferred over other commonly used data formats like XML or JSON because it is easy for people to read and write. Additionally, most programming languages include libraries that can be used with YAML.
YAML has one more small quirk: all the YAML files may optionally start with “....” and end with “....”. This indicates a document’s start and end and is considered the preferred YAML format.

That’s all about the introduction to YAML. Let us now learn about key-value pairs, which are an essential part of Ansible YAML basics.
Key-Value Pair

To represent the data in the form of dictionaries, YAML uses a key-value pair. The syntax for the dictionary is = key: value (a space must follow the colon):
Example: A Student record
…#Optional YAML start syntax
Ninja:
Name: Coding Ninja
Roll Number: 21
Contact: XXXXXXXXXX
… #Optional YAML end syntax
This complete record can also be abbreviated in a single line as:
Ninja: {name: coding ninja, roll number: 21, contact: XXXXXXXXXX}
Representing List
Almost all YAML files for Ansible start with a list. The items in the list are all lists of key/value pairs, often called hashes or dictionaries. As a result, we must understand how to write lists and dictionaries in YAML. A list’s members are on the new line starting with a “-” (a dash and a space), with the same level of indentation:
…
# A list of courses on coding ninjas
course:
- Data Structures and Algorithms
- Machine Learning
- MERN Stack
- Competitive Programming
…

You can also try this code with Online C Compiler
Run Code
Like key-value pair, a list can also be abbreviated as
Course: [‘Data Structures and Algorithms, ‘Machine Learning, ‘MERN Stack’, ‘Competitive Programming’]
List Inside Dictionaries
Now that we know lists and dictionaries let us write List inside Dictionaries where the value of a key is the list.

…
Ninja:
Name: Coding Ninja
Roll Number: 21
Contact: XXXXXXXXXX
Course:
- Data Structures and Algorithms
- Machine Learning
- MERN Stack
- Competitive Programming
…

You can also try this code with Online C Compiler
Run Code
List of Dictionaries
We can also make a list of dictionaries by repeating the syntax of ‘course’ in the above code.
…
Ninja:
Name: Coding Ninja
Roll Number: 21
Contact: XXXXXXXXXX
Course:
- Data Structures and Algorithms
- Machine Learning
- MERN Stack
- Competitive Programming
Test Series:
- Amazon
- Microsoft
- Google
- Uber
…

You can also try this code with Online C Compiler
Run Code
Boolean
YAML also supports boolean values, i.e., True or False, which are not case sensitive.
…
Ninja:
Name: Coding Ninja
Roll Number: 21
Contact: XXXXXXXXXX
Qualified: True
…

You can also try this code with Online C Compiler
Run Code
Now it’s time for the questions. Let us now move to FAQs.
Frequently Asked Questions
Why does Ansible use YAML?
Ansible uses YAML as it is very easy for humans to understand, write, and read as compared to other data formats like JSON and XML. Every YAML file optionally starts with “...” and ends with “...”.
What is YAML used for?
YAML is a human-understandable data serialization language which is used for writing configuration files. YAML stands for YAML ain’t markup language (a recursive acronym) or yet another markup language..
What is an Ansible configuration file?
A file that governs the behavior of all interactions made by the control node, which is the brain and the heart. The default configuration file for Ansible is located in the /etc/ansible/ansible.cfg.
Is it easy to learn YAML?
YAML is an easy, expressive, data-oriented language that distinguishes itself from document markup languages. YAML Ain't a Markup Language (YAML), and as configuration formats go, it's easy on the eyes.
Is coding necessary for Ansible?
Ansible is an open-source, free application that is simple to set up and utilize. Playbooks from Ansible don't need any specialized coding knowledge. Without the necessity for configuration files, Ansible may be used to perform basic tasks like rebooting from the command line or ensuring that a service is operating.
Conclusion
In this article, we discussed the introduction to Ansible and Ansible YAML basics and some basic things like key-value pairs, lists representation, and lists inside dictionaries. You can also visit our other suggested articles to learn more about Ansible, apart from Ansible YAML basics, if you are eager to enhance your knowledge regarding Ansible.
Please refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. And also, enroll in our courses and refer to the mock test and problems available. Have a look at the interview experiences and interview bundle for placement preparations.
Also check out - Data Dictionary In Software Engineering
Do upvote our blog to help other ninjas grow.
Happy Learning!