Slide 1
Most trusted JOB oriented professional program
DevOps Certified Professional (DCP)

Take your first step into the world of DevOps with this course, which will help you to learn about the methodologies and tools used to develop, deploy, and operate high-quality software.

Slide 2
DevOps to DevSecOps – Learn the evolution
DevSecOps Certified Professional (DSOCP)

Learn to automate security into a fast-paced DevOps environment using various open-source tools and scripts.

Slide 2
Get certified in the new tech skill to rule the industry
Site Reliability Engineering (SRE) Certified Professional

A method of measuring and achieving reliability through engineering and operations work – developed by Google to manage services.

Slide 2
Master the art of DevOps
Master in DevOps Engineering (MDE)

Get enrolled for the most advanced and only course in the WORLD which can make you an expert and proficient Architect in DevOps, DevSecOps and Site Reliability Engineering (SRE) principles together.

Slide 2
Gain expertise and certified yourself
Azure DevOps Solutions Expert

Learn about the DevOps services available on Azure and how you can use them to make your workflow more efficient.

Slide 3
Learn and get certified
AWS Certified DevOps Professional

Learn about the DevOps services offered by AWS and how you can use them to make your workflow more efficient.

previous arrow
next arrow

What is YAML and How it works? An Overview and Its Use Cases

What is YAML?

  • YAML means  another markup language. It is a data serialization language that works well with the modern programming language, and it is human-friendly.
  • It is used to define the data structures that are very easy to understand. These data structures are very easy to manage and maintain by the users.
  • YAML uses space to define something. If we use a single space or double space, it has different meanings in YAML. Spaces change the meaning of data structure.
  • YAML is case sensitive.
  • YAML is language independent. If we define the YAML once, the same YAML file can be invoked in Python file, Ruby, etc.
  • In the starting, YAML was very useful and friendly to people who work with data. YAML uses Unicode printable characters. In Unicode, some provide the information of structure, and others contain the data itself. Using the minimization of structural characters, a unique cleanness can be achieved by YAML. YAML is used to show the data itself in a meaningful and natural way. For example, bullet lists are created by dashes, key: value pairs are separated by a colon, and structure may be used by indentation.
  • To work well with the common use cases, YAML language was specialty designed. Common-use cases are cross-language data sharing, log files, debugging of complex data structure, interprocess messaging, object persistence, and configuration files. The programming becomes an easy task when data is easy to understand and view.

How To Write YAML

The basic structure of a YAML file is a map. You might call this a dictionary, hash or object, depending on your programming language or mood.

Very generally, it’s keys and values all the way down:

key: value

YAML Example: Scalar Types

You can use all sorts of scalar types as values: numbers, booleans, and strings (quoted or not). The first line of a config.yml, for example, is usually:

version: 2

Words in keys can be separated by underscores, dashes, or spaces. At CircleCI, we use underscores.

If the value of a key is a multi-line string, you can use either the ‘literal block’ style using the ‘|’ character. This is particularly helpful when defining shell commands:

command: 
    if [ "${CIRCLE_BRANCH}" == "master" ];
      then ansible-playbook site.yml -i production;
    fi

Note that the leading indentation for the multi-line string will be stripped.

YAML Example: Collection Types

All you have to do to create collections is Use Indentation:

environment:
    TEST_REPORTS: /tmp/test-reports

If you have a list of things (like images), you can denote that sequence using dashes:

docker:
    - image: ubuntu:14.04
    - image: mongo:2.6.8
      command: [mongod, --smallfiles]
    - image: postgres:9.4.1

Note that the second item in the sequence has two keys: image and command. The command key uses a JSON-style sequence because (remember!) YAML is a superset of JSON.

Finally, YAML doesn’t allow tab characters, so if you’re using those to indent, have your text editor convert those to spaces. Syntax errors in your YAML can sometimes cause CircleCI builds to hang, but they’re also easily preventable by running your circle.yml/config.yml through an online validator.

What is the file extension for YAML

yaml files are created with extension .yaml or .yml. You can use any IDE or text editor to open this file.

All the popular IDE supports the yaml file extension and also provides plugins to validate the yaml file content.

Advantages of YAML

  • Files are easy to work in a text editor.
  • Files are portable between programming languages.
  • Files are expressive and also extensible.
  • Files support the Unicode character set.
  • Support for major programming languages.

Disadvantages of YAML

  • It is a new format introduced recently, a learning curve exists.
  • Not much popular other than XML and JSON.
  • It is very complex to represent configuration in the hierarchy of data.

Conclusion

In this guide, we covered the steps of preparing the development environment in both Windows as well as Linux to get started with YAML. We nearly discussed all the concepts of YAML’s basic data types, YAML editor, and YAML Parser.

We have also highlighted the benefits of using YAML vis-a-vis other markup languages and provided code examples with the help of a supporting sample project. We hope that now the learners can use YAML to abstract data from application logic to write efficient and maintainable code.

Happy Learning!!

Rajesh Kumar
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x