* [Topics](/en/topics "Topics")
* [Automation and management](/en/topics/automation "Automation and management")
* What is YAML?
What is YAML?
=============
Published  March 3, 2023•*7*-minute read
Copy URL
Jump to section
---------------
OverviewYAML syntaxSyntax exampleYAML usesWhy Red Hat?
Overview
--------
YAML is a human-readable data serialization language that is often used for writing configuration files. Depending on whom you ask, YAML stands for yet another markup language or YAML ain’t markup language (a recursive acronym), which emphasizes that YAML is for data, not documents.
YAML is a popular programming language because it is designed to be easy to read and understand. It can also be used in conjunction with other programming languages. Because of its flexibility, and accessibility, YAML is used by [Ansible®](/en/technologies/management/ansible/compare-awx-vs-ansible-automation-platform) to create automation processes, in the form of [Ansible Playbooks](/en/topics/automation/what-is-an-ansible-playbook).
[Learn the YAML essentials for Ansible](https://developers.redhat.com/learn/ansible/yaml-essentials-ansible "Interactive lab: write your first Ansible Playbook")
YAML syntax
-----------
YAML files use a .yml or .yaml extension, and follow specific syntax rules.
YAML has features that come from Perl, C, XML, HTML, and other programming languages. YAML is also a superset of JSON, so JSON files are valid in YAML.
There are no usual format symbols, such as braces, square brackets, closing tags, or quotation marks. And YAML files are simpler to read as they use Python-style indentation to determine the structure and indicate nesting. Tab characters are not allowed by design, to maintain portability across systems, so whitespaces—literal space characters—are used instead.
Comments can be identified with a pound or hash symbol (#). It’s always a best practice to use comments, as they describe the intention of the code. YAML does not support multi-line comment, each line needs to be suffixed with the pound character.
A common question for YAML beginners is “What do the 3 dashes mean?” 3 dashes (---) are used to signal the start of a document, while each document ends with three dots (...).
This is a very basic example of a YAML file:
```
#Comment: This is a supermarket list using YAML
#Note that - character represents the list
---
food: 
  - vegetables: tomatoes #first list item
  - fruits: #second list item
      citrics: oranges 
      tropical: bananas
      nuts: peanuts
      sweets: raisins
```
Note that the structure of a YAML file is a map or a list, and it follows a hierarchy depending on the indentation, and how you define your key values. Maps allow you to associate key-value pairs. Each key must be unique, and the order doesn't matter. Think of a Python dictionary or a variable assignment in a Bash script.
A map in YAML needs to be resolved before it can be closed, and a new map is created. A new map can be created by either increasing the indentation level or by resolving the previous map and starting an adjacent map.
A list includes values listed in a specific order and may contain any number of items needed. A list sequence starts with a dash (-) and a space, while indentation separates it from the parent. You can think of a sequence as a Python list or an array in Bash or Perl. A list can be embedded into a map.
In the example provided above “vegetables” and “fruits” represent items that are part of the list named “food”.
YAML also contains scalars, which are arbitrary data (encoded in Unicode) that can be used as values such as strings, integers, dates, numbers, or booleans.
When creating a YAML file, you’ll need to ensure that you follow these syntax rules and that your file is valid. To achieve it, you can use a linter—an application that verifies the syntax of a file. The yamllint command can help to ensure you’ve created a valid YAML file before you hand it over to an application.
[Get started with YAML for beginners](/sysadmin/yaml-beginners "Yaml for beginners blog")
Red Hat Ansible Automation Platform learning hub
------------------------------------------------
[Keep reading](/en/technologies/management/ansible/learn "Keep reading")
YAML syntax example
-------------------
Here's an example of a simple YAML file for a student record that demonstrates the syntax rules:
```
#Comment: Student record
#Describes some characteristics and preferences
---
name: Martin D'vloper #key-value
age: 26
hobbies: 
  - painting #first list item
  - playing_music #second list item
  - cooking #third list item
programming_languages:
  java: Intermediate
  python: Advanced
  javascript: Beginner
favorite_food: 
  - vegetables: tomatoes 
  - fruits: 
      citrics: oranges 
      tropical: bananas
      nuts: peanuts
      sweets: raisins
```
When we translate this file into Python, using PyYAML library, you will obtain the following data structure:
```
[
    {
        "name": "Martin D'vloper",
        "age": 26,
        "hobbies": ["painting", "playing_music", "cooking"],
        "programming_languages": {
            "java": "Intermediate",
            "python": "Advanced",
            "javascript": "Beginner",
        },
        "favorite_food": [
            {"vegetables": "tomatoes"},
            {
                "fruits": {
                    "citrics": "oranges",
                    "tropical": "bananas",
                    "nuts": "peanuts",
                    "sweets": "raisins",
                }
            },
        ],
    }
]
```
What is YAML used for?
----------------------
One of the most common uses for YAML is to create [configuration files](/en/topics/automation/what-is-configuration-management). It's recommended that configuration files be written in YAML rather than JSON, even though they can be used interchangeably in most cases, because YAML has better readability and is more user-friendly.
In addition to its use in Ansible, YAML is used for Kubernetes resources and deployments.
A benefit of using YAML is that YAML files can be added to source control, such as Github, so that changes can be tracked and audited.
#### YAML in Ansible
[Ansible Playbooks](/en/topics/automation/what-is-an-ansible-playbook) are used to orchestrate IT processes. A playbook is a YAML file containing 1 or more plays, and is used to define the desired state of a system.
Each play can run one or more tasks, and each task invokes an [Ansible module](/en/topics/automation/what-is-an-ansible-module). Modules are used to accomplish automation tasks in Ansible. Ansible modules can be written in any language that can return JSON, such as Ruby, Python, or bash.
An Ansible Playbook consists of maps and lists. To create a playbook, start a YAML list that names the play, and then lists tasks in a sequence. Remember that indentation is not an indication of logical inheritance. Think of each line as a YAML data type (a list or a map).
By using YAML templates, Ansible users can program repetitive tasks to happen automatically without having to learn an advanced programming language. Developers can also use the [ansible-lint command](/en/technologies/management/ansible/development-tools), a YAML linter for Ansible Playbooks, to identify mistakes so errors don't occur during a critical stage of operation.
With the introduction of [Ansible Lightspeed with IBM Watson Code Assistant](/en/technologies/management/ansible/ansible-lightspeed), a generative AI service, developers can create Ansible automation content more efficiently. Users can enter a task request in plain English and get clean and compliant YAML code recommendations for automation tasks that are then used to create Ansible Playbooks.
[Learn the basics of Ansible](/en/topics/automation/learning-ansible-tutorial)
#### YAML for Kubernetes
[Kubernetes](/en/topics/containers/what-is-kubernetes) works based on defined state and actual state. Kubernetes objects represent the state of a cluster and tell Kubernetes what you want the workload to look like. Kubernetes resources, such as pods, objects, and deployments can be created using YAML files.
When creating a Kubernetes object, you’ll need to include specifications to define the object's desired state. The [Kubernetes API](/en/topics/containers/what-is-the-kubernetes-api) can be used to create the object. The request to the API will include the object specifications in JSON, but most often you’ll provide the required information to kubectl as a YAML file. Kubectl will convert the file into YAML for you when it makes the API request.
Once an object has been created and defined, Kubernetes works to make sure that the object always exists.
Developers or sysadmins specify the defined state using the YAML or JSON files they submit to the Kubernetes API. Kubernetes uses a controller to analyze the difference between the new defined state and the actual state in the cluster.
[Get an introduction to enterprise Kubernetes](/en/engage/introduction-enterprise-kubernetes-s-202003040257 "SOLP: An introduction to enterprise Kubernetes")
Why Red Hat?
------------
[Red Hat Ansible Automation Platform’s](/en/technologies/management/ansible) human-readable YAML automation language makes it possible for users across an organization to share, vet, and manage automation content. It includes all the tools needed to implement enterprise-wide automation, including playbooks and analytics. And it allows users to centralize and control their IT infrastructure with a visual dashboard, role-based access control, and more to reduce operational complexity.
With a Red Hat subscription, you get certified content, a robust partner ecosystem, access to hosted management services, and life cycle technical support that allows your teams to create, manage, and scale automation across your organization. And you’ll get expert knowledge gained from our success with thousands of customers.
[Learn more about Ansible Automation Platform](/en/technologies/management/ansible)
[Red Hat OpenShift](/en/technologies/cloud-computing/openshift) is Kubernetes for the enterprise. It includes all of the extra pieces of technology that make Kubernetes powerful and viable for the enterprise, including registry, networking, telemetry, security, automation, and services.
With Red Hat OpenShift, developers can make new containerized apps, host them, and deploy them in the cloud with the scalability, control, and orchestration that can turn a good idea into new business quickly and easily.
[Learn more about OpenShift](/en/technologies/cloud-computing/openshift "product | red hat openshift")
Resource
Red Hat Ansible Automation Platform: A beginner’s guide
-------------------------------------------------------
Your organization’s IT processes can be improved with the right automation solution. Learn about the benefits of Red Hat Ansible Automation Platform.
[Get the resource](/en/resources/ansible-automation-platform-beginners-guide-ebook "Red Hat Ansible Automation Platform: A beginner’s guide")
All Red Hat product trials
--------------------------
Our no-cost product trials help you gain hands-on experience, prepare for a certification, or assess if a product is right for your organization.
[Keep reading](/en/products/trials "All Red Hat product trials")
Keep reading
------------
### The journey from observability to AIOps automation
Learn how organizations can rely on observability, AIOps, and IT automation to deliver reliable services and applications efficiently.
[Read the article](/en/topics/automation/observability-to-aiops-automation "article | The journey from observability to AIOps automation")
### What is infrastructure automation?
Infrastructure automation is the use of technology that performs tasks with reduced human assistance.
[Read the article](/en/topics/automation/what-is-infrastructure-automation "article | what is infrastructure automation")
### What is patch management?
Patch management is the process of identifying, testing, and installing system updates to improve security and performance in operating systems and applications.
[Read the article](/en/topics/management/what-patch-management-and-automation "article | what is patch management")
Automation and management resources
-----------------------------------
### Featured product
* #### [Red Hat Ansible Automation Platform](/en/technologies/management/ansible)
  A platform for implementing enterprise-wide automation, no matter where you are in your automation journey.
[See all products](/en/technologies/all-products "See all products")
### Related content
* Checklist
  [Automate virtual machines at scale](/en/resources/automate-virtual-machines-at-scale-checklist)
* Blog post
  [Planning your upgrade path to Ansible Automation Platform 2.6](/en/blog/planning-your-upgrade-path-ansible-automation-platform-26)
* E-book
  [[node:rh-smart-meta-title]](/en/engage/it-automation-in-ai-era-ebook)
* Overview
  [Oil and gas giant achieves millions in savings with Red Hat](/en/resources/oil-and-gas-anon-overview)
### Related articles
* [The journey from observability to AIOps automation](/en/topics/automation/observability-to-aiops-automation)
* [What is infrastructure automation?](/en/topics/automation/what-is-infrastructure-automation)
* [What is patch management?](/en/topics/management/what-patch-management-and-automation)
* [What is security automation?](/en/topics/automation/what-is-security-automation)
* [Why choose Red Hat for automation?](/en/topics/automation/why-choose-red-hat-for-automation)
* [What is an Ansible Playbook?](/en/topics/automation/what-is-an-ansible-playbook)
* [What is SOAR?](/en/topics/security/what-is-soar)
* [How to build an IT automation strategy](/en/topics/automation/build-an-automation-strategy)
* [Learning Ansible basics](/en/topics/automation/learning-ansible-tutorial)
* [Ansible vs. Puppet: What you need to know](/en/topics/automation/ansible-vs-puppet)
* [Ansible vs. Salt: What you need to know](/en/topics/automation/ansible-vs-salt)
* [Ansible vs. Chef: What you need to know](/en/topics/automation/ansible-vs-chef)
* [Ansible vs. Terraform](/en/topics/automation/ansible-vs-terraform)
* [What is IT service management (ITSM)?](/en/topics/automation/what-is-it-service-management-itsm)
* [Automating Microsoft Windows with Red Hat Ansible Automation Platform](/en/technologies/management/ansible/automate-microsoft-windows-with-ansible)
* [What is DevOps automation?](/en/topics/automation/what-is-devops-automation)
* [What is Infrastructure as Code (IaC)?](/en/topics/automation/what-is-infrastructure-as-code-iac)
* [Ansible vs. Kubernetes: how they work together](/en/topics/automation/Ansible-vs-Kubernetes)
* [What is a configuration management database (CMDB)?](/en/topics/automation/what-is-a-configuration-management-database-cmdb)
* [What is cloud migration? And how can automation help?](/en/topics/automation/what-is-cloud-migration)
* [What is a software-defined data center (SDDC)?](/en/topics/automation/what-is-a-sddc)
* [What is IT automation?](/en/topics/automation/what-is-it-automation)
* [Why choose Red Hat Ansible Automation Platform as your AI foundation?](/en/topics/automation/automation-and-ai)
* [What is access control?](/en/topics/security/what-is-access-control)
* [What is virtual infrastructure management? And how can automation help?](/en/topics/automation/virtual-infrastructure-management)
* [What is IT migration?](/en/topics/automation/what-is-it-migration)
* [How to automate migrations with Red Hat Ansible Automation Platform](/en/technologies/management/ansible/automate-migrations-with-red-hat-ansible-automation-platform)
* [Why use Red Hat Ansible Automation Platform with Red Hat OpenShift?](/en/technologies/cloud-computing/openshift/ansible-on-openshift)
* [What is CloudOps?](/en/topics/automation/what-is-cloudops)
* [Red Hat Satellite on Red Hat Enterprise Linux](/en/technologies/management/satellite/satellite-for-rhel)
* [What is role-based access control (RBAC)?](/en/topics/security/what-is-role-based-access-control)
* [Which Red Hat Ansible Automation Platform deployment option is right for you?](/en/technologies/management/ansible/ansible-deployment-options)
* [What is an Ansible module—and how does it work?](/en/topics/automation/what-is-an-ansible-module)
* [How to manage and automate applications at the edge](/en/topics/edge-computing/how-to-manage-automate-applications-edge)
* [How to build an automation Center of Excellence](/en/topics/automation/how-to-build-automation-center-of-excellence)
* [What is orchestration?](/en/topics/automation/what-is-orchestration)
* [How to adopt Automation as Code: Extending Infrastructure as Code into Policy as Code](/en/topics/automation/how-to-adopt-automation-as-code)
* [What is a webhook?](/en/topics/automation/what-is-a-webhook)
* [Red Hat Lightspeed data and application security](/en/topics/management/data-application-security)
* [What is an Ansible Role—and how is it used?](/en/topics/automation/what-is-an-ansible-role)
* [What is data management?](/en/topics/data-services/what-is-data-management)
* [Gain security with Red Hat Ansible Automation Platform](/en/technologies/management/ansible/gain-security-with-red-hat-ansible-automation-platform)
* [What is NetOps?](/en/topics/automation/what-is-netops)
* [What is an Ansible Rulebook?](/en/topics/automation/what-is-an-ansible-rulebook)
* [What is configuration management](/en/topics/automation/what-is-configuration-management)
* [What is event-driven automation?](/en/topics/automation/what-is-event-driven-automation)
* [Zero-Touch Provisioning and telco automation with Red Hat](/en/topics/telecommunications/zero-touch-provisioning-and-telco-automation-at-red-hat)
* [What is provisioning?](/en/topics/automation/what-is-provisioning)
* [What is compliance management?](/en/topics/management/what-is-compliance-management)
* [Understanding Ansible, Terraform, Puppet, Chef, and Salt](/en/topics/automation/understanding-ansible-vs-terraform-puppet-chef-and-salt)
* [What is cloud orchestration?](/en/topics/automation/what-is-cloud-orchestration)
* [What is a configuration file?](/en/topics/linux/what-configuration-file)
* [Ansible vs. Red Hat Ansible Automation Platform](/en/technologies/management/ansible/ansible-vs-red-hat-ansible-automation-platform)
* [What is cloud automation?](/en/topics/automation/what-is-cloud-automation)
* [What is network automation?](/en/topics/automation/what-is-network-automation)
* [What are managed IT services?](/en/topics/cloud-computing/what-are-managed-it-services)
* [What is business process management?](/en/topics/automation/what-is-business-process-management)
* [What is the Red Hat Ansible Automation Platform automation controller?](/en/technologies/management/ansible/automation-controller-product-feature)
* [What is business process automation?](/en/topics/automation/what-is-business-process-automation)
* [What is IT process automation?](/en/topics/automation/what-is-it-process-automation)
* [What is deployment automation?](/en/topics/automation/what-is-deployment-automation)
* [What is business optimization?](/en/topics/automation/business-optimization)
* [What is Kubernetes cluster management?](/en/topics/containers/what-is-kubernetes-cluster-management)
* [What is SRE?](/en/topics/devops/what-is-sre)
* [What is risk management?](/en/topics/management/what-is-risk-management)
* [What is an SOE?](/en/topics/management/what-is-an-soe)
* [What is IT system life-cycle management?](/en/topics/management/it-system-life-cycle-management)
* [What is robotic process automation (RPA?)](/en/topics/automation/what-is-robotic-process-automation)
* [What is network management?](/en/topics/management/what-is-network-management)
* [What is cloud management?](/en/topics/cloud-computing/what-is-cloud-management)
* [What's business automation?](/en/topics/automation/whats-business-automation)
[More about this topic](/en/topics/automation "More about this topic")