YAML
YAML is a specialized language for storing structured information with a simple syntax. This tool allows you to store complex data in a compact and easy-to-read format (.yml file). This feature can be extremely useful in the context of DevOps and virtualization.
What is YAML?
YAML is a language designed to store information in a human-readable format. Its name stands for “Yet Another Markup Language.” However, this definition was later changed to “YAML is not a markup language” to clearly distinguish it from other languages in that category.
This language is similar to XML and JSON, but uses a more sophisticated syntax while maintaining similar capabilities. YAML is typically used to create configuration files within the Infrastructure as Code (IaC) approach, as well as for container management in the context of DevOps.
YAML is most often used to create automation protocols that can execute sequences of commands specified in a .yml file. This allows your system to function more quickly and independently, without additional developer involvement.
A growing number of companies are actively implementing DevOps practices and virtualization in their operations. For this reason, YAML proficiency is becoming an essential requirement for modern developers. Particularly valuable is the language’s compatibility with Python (including the PyYAML library), as well as popular technologies like Docker and Ansible, which significantly simplify integration.
Comparison of YAML, JSON, and XML
YAML (.yml)
Peculiarities:
- has a human-readable code;
- has a minimalistic syntax;
- data-oriented;
- includes a structure resembling JSON (YAML is an extended version of JSON);
- allows you to add comments;
- supports the use of unquoted strings;
- considered cleaner than JSON;
- provides additional features such as extensible data types, relative anchors, and preservation of key order.
Usage: YAML is ideal for data-intensive applications that rely on DevOps processes or use virtual machines. Increased data readability is especially useful in teams where developers regularly interact with this data.
JSON
Peculiarities:
- requires more effort to read.
- The syntax has strict and clear requirements.
- similar to the inline YAML style (some YAML parsers can interpret JSON files);
- There is no option to add comments.
- Strings must be enclosed in double quotes.
Usage: JSON is used in web development, representing the best format for serializing and transmitting data over an HTTP connection.
XML
Peculiarities :
- Requires more effort to read.
- Has a more complex structure.
- Serves as a markup language, while YAML is used to format data.
- Provides a wider range of possibilities, such as the use of tag attributes.
- Has a more rigid document structure.
Usage: XML is ideal for complex projects requiring careful control over validation, schema, and namespaces. XML is difficult to read, consumes more bandwidth, and requires more storage space, but it provides an unrivaled level of control.
What makes YAML unique?
Multiple document support
You have the ability to group multiple YAML documents into a single file, making file management and information processing much easier.
Documents are separated by a triple hyphen (-):
Ability to add comments
YAML allows comments to be inserted after the # symbol, similar to how Python does it:
Clear syntax
YAML file syntax uses an indentation system similar to that of the Python programming language. It’s important to use spaces instead of tabs to avoid confusion.
This approach eliminates the redundant use of characters common to JSON and XML (such as quotation marks, parentheses, and curly braces). As a result, the file becomes much more readable.
YAML:
JSON:
Explicit and implicit typing
YAML implements both explicit and implicit data typing. It provides the ability to automatically detect types and specify them explicitly. To use a specific data type, simply add
Examples of implicit typing:
No embedded executable files
The language does not contain embedded executables. This ensures the secure exchange of YAML files with other parties.
To work with executable files, you will need to integrate YAML with other languages such as Perl or Java.
YAML syntax
The YAML language has several fundamental concepts that enable the processing of a wide variety of data.
Key-value pairs
The bulk of the data in the yml file is in the form of key-value pairs, where the key represents a name and the value represents the corresponding data.
Scalars and mapping
A scalar denotes a single value associated with a particular name.
The YAML language supports standard types: int and float, boolean, string, and null.
These types can be represented in a variety of formats, including hexadecimal, octal, and scientific notation. Additionally, there are special types for mathematical concepts such as infinity, negative infinity, and NaN.
Lines
A line is a sequence of characters that can include words or entire sentences. Lines are denoted by the symbols | for individual lines and > for paragraphs.
It is important to note that YAML does not require quotation marks.
Sequences
Sequences are data structures similar to lists or arrays that store multiple values under a single key. They are defined using indentation or [].
Single-line sequences look more compact, but their readability suffers:
Dictionaries
Dictionaries are collections of key-value pairs grouped under a single key. They allow you to structure data into logical categories.
Anchors
Anchors are a unique feature of the YAML language, allowing you to create links to specific data elements within the document structure. This is especially useful when the same data is repeated in different places in the document, as anchors help avoid duplication of information.
Anchors work quite simply: you define a data element using an anchor, and then you can reference that anchor in other parts of the document. This allows you to store data in one place and reference it as needed.
Example of using anchors:
In this example, the &details anchor creates an anchor containing general data for a person. The data defined in the anchor is then linked <<: *detailsin sections using a link. This avoids duplication and simplifies data updates, as changes in one location are automatically reflected elsewhere.employee1employee2
Integration with Docker, Ansible, and other tools
YAML is actively used for integration with various automation, deployment, and management tools, such as Docker, Ansible, and many others. This integration enables more efficient configuration management, deployment, and task automation.
Docker Integration:
Docker uses YAML files to define container configurations. The docker-compose.yml file is an example of how to use the language to define multi-container applications, including containers, networks, and volumes.
Example of a service definition in Docker Compose:
Ansible integration:
Ansible uses YAML files to define infrastructure configurations and automate tasks. YAML files in Ansible contain “playbooks”—sets of tasks that describe what should be done on target systems and how.
Example Ansible playbook:
Extended forms of sequences and mapping
YAML has extended forms for describing sequences (lists) and mappings (dictionaries) that add additional capabilities and flexibility to structuring data.
Sequence forms:
- Multi-line strings within a sequence:
In this example, the second element “banana” is represented by a multi-line string, allowing for longer, more descriptive data to be included.
- Nested sequences:
Mapping forms:
- Block mapping style:
- Nested mappings:
Extended data types (timestamp, null, and others)
YAML supports extended data types in addition to the standard types (string, number, Boolean, etc.). These extended data types allow for more precise and concise descriptions of various entities.
Examples of extended data types in YAML:
- Timestamp:
Here timestamp_exampleis a timestamp in ISO 8601 format.
- Null (Empty value):
This example demonstrates the use of a value nullthat can denote the absence of a value.
- NaN (Not a Number):
The value .nanrepresents “not a number”, which can be used to denote undefined numeric values.
- Infinity:
The value .infrepresents positive infinity.
- Negative infinity:
The value -.infrepresents negative infinity.
Explore More IT Terms
#
- Using an integrating factor
- Equations in total differentials
- Bernoulli's equation
- Linear differential equations of the first order
- 10 Mixed C++ Challenges to Test Your Skills
- 11 Tricky Non-Technical Questions to Ask in a Recruiting Interview
- 50 Terms Every Programmer Should Know
- 52 Java Thread Interview Questions
- 7 Levels of Using the Zip Function in Python
- 7 Python Code Bugs You Need to Fix
- 70+ Free Resources for Learning Programming
A
- A Comprehensive Guide to HTML and CSS
- A Comprehensive Guide to MODX CMS
- A computer science question tests your ability to work with IP addresses and network masks
- A Guide to SQL Query Formatting for Beginners
- A/B testing
- Abstract Data Type (ADT)
- AES Encryption Algorithm: How It Works and Where It's Used
- Agile
- Algorithm
- Algorithm Analysis
- Algorithm Complexity-Key Points
- Algorithm complexity: deep parsing O(log n)
- Algorithm vs. Program
- Algorithms and Data Structures in C#
- An overview of the C # programming language
- An overview of the Python programming language
- Anaconda Python
- Analysis of graphs and adjacency matrices question
- Android
- Android App Bundle
- Android SDK
- Angular
- Ansible
- Apache
- Apache Airflow
- Apache Kafka
- Apache Tomcat
- App Store
- AppCode
- Applications of microcontrollers: From simple circuits in electronics to complex systems
- Applications of the derivative
- Arduino: How to Program It: Basics for Beginners
- Array-based stack
- ArrayList
- ASCII
- ASP.NET
- Assembly Language Lessons
B
C
- C++ Lessons
- Cache
- Calculating Memory Capacity
- Character sets and encodings
- Characteristics of a good Algorithm
- Circular singly linked list
- Coding Tests with Answers
- Combinational Circuits Solved Questions
- Compiler
- Complexity of algorithms-Tutorial
- Computer Science Fundamentals Test with Answers (47 questions)
- Computer science tests with answers (More than 100 Questions)
- Constants
- Creating a Table in HTML
- Creating Forms in HTML
- Creating Lists
- Cybernetics and informatics
- Cycles
D
- Data Analytics: applications of data analysis in companies
- Data Engineer - Who is it, what does a data engineer do, and an overview of the profession
- Data modeling: what it is, types, and process steps.
- Data preprocessing: a complete guide for beginners and professionals.
- Data structure
- Data Structures and Algorithms (DSA)
- Data types vs. Data structures
- Database Tests with Answers
- Deep Learning
- Defining Aliases
- Defining Arrays
- Deque
- Detailed articles and tutorials on PHP
- Developing a Website from Scratch
- Differential Equations
- Differentiation of functions
- Digital data: understand the importance of this asset for businesses.
- Double integrals
- Doubly linked lists
- DSA Tutorial
E
F
G
H
- Handling errors and exceptions
- Heads or Tails? How Probability Theory Is Used in IT
- History of the development of computer science
- Homogeneous equations
- Homogeneous vs. non-homogeneous structures
- How to effectively organize your workflow
- How to Learn Java: Tips for Beginner Developers
- How to Learn PHP: A Beginner's Guide
- How to Use S3 Storage in Kubernetes with CSI
- HTML
- HTML and CSS: Definition, Application, and Operating Principles
- HTML and CSS. Layout from Scratch: What to Learn, Where to Learn, and How Long Will It Take?
- HTML Frame Structure
- HTML Link Formatting
- HTML Quizzes with Answers
I
- if..else construction
- Infinite sequences and series
- Information properties
- Inheritance in Java: A Complete Guide to Principles and Implementation
- Inserting an Image
- Integration of functions
- Interactive Python Tutorial – Learn Programming from Scratch
- Interpreter
- Interview Problem: Finding a Deleted Element in O(N)
- Interview Scare: The FizzBuzz Challenge
- Introduction to C++
- Introduction to Machine Learning
- Introduction to Networking | Network Fundamentals Part 1
- Introduction to Number Systems (Binary, Octal, Hexadecimal) | Math for CS Foundations #1
- IT Specialist Resume (CV)
J
K
L
M
- Machine Learning
- Machine Learning Basic Tool: NumPy
- Machine Learning Basic Tool: Pandas
- Machine Learning Mathematics
- Mathematics for programmers: what is really needed?
- MD5 encryption algorithm: What is it and why is it needed?
- Microcontroller and Microprocessor - what's the difference?
- ML Engineer: Who They Are, What They Do, How Much They Earn, and How to Become a Neural Network Specialist
- Monte Carlo Simulation: How It Works and What It's For
O
P
- PHP lessons
- Private DNS server and its configuration
- Program code
- Programmer's Dictionary
- Programming
- Programming with pseudocode
- Python Code Formatting Guide: PEP8
- Python for data analysis: how to do it and main libraries
- Python Lessons
- Python Superstar: 5 Ways to Use the * Operator
- Python vs. Julia: Should You Replace Python with Julia?
R
S
- SFML Graphics Library Tutorials
- Sorting Algorithms in Programming: Types, Descriptions, and Comparisons
- SQL commands: see what they are, what the main ones are + examples
- SQL Interview Questions and Tasks
- SQL Lessons
- SQL Stored Procedures
- SQL Syntactic Sugar: The COALESCE Function
- Stack
- Start in analytics: Python or R
- Static vs. dynamic data structures
- Statistical analysis: importance for decision making.
- String formatting in Python
- Structure of computer science
- Swift Lessons
- switch/match construct
- Syntax
T
- Terms in programming
- Text and paragraph formatting tags
- The Complete Guide to Bootstrap
- The Complete Guide to JavaScript
- The concept of information and its transmission
- The Future of Python: Key Trends and Insights from Global Researc
- The Infrastructure of Code: A Complete Guide to Repositories for Languages, Frameworks, and Compilers
- The pip package manager in Python
- The role of informatization in the development of society
- Transfers
- Tricky Java Questions Often Asked in Interviews
- Tutorials / Articles
- TypeScript: What It Is and Why Developers Need It
W
- What are databases, and why do they need DBMS and SQL?
- What do Linux distributions consist of?
- What is .NET and what is it used for?
- What is a data structure?
- What is a GPU in a computer, in simple terms?
- What is a quantum computer: 100,500 problems in one second
- What Is an Algorithm?
- What is Arduino: How it Works and the Platform's Capabilities
- What is Big Data? Introduction, Types, Characteristics, and Examples
- What is FizzBuzz Challenge?
- What is Golang and what is it used for?
- What is Haskell and what is it used for?
- What is Kotlin and what is it used for?
- What is Linux? The History of Linux
- What is machine learning, and how does it work?
- What is Power BI: everything about the data analytics software
- What is recursion, recursive and iterative process in programming?
- What is the C++ programming language?
- What is the OSI Model: A Complete Explanation of the Seven Layers and Their Role in Networking
- What's the difference between x86 and ARM processors?
- Where to start learning the C programming language?
- Which Linux distribution should you choose? A Linux distribution overview






