cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Commander Commander
Commander
  • 706 Views

Programming Languages and YAML

Jump to solution

YAML is can be used with programming languages, such as Ruby,
Python, or Bash.  Are there others?

Trevor "Red Hat Evangelist" Chandler
Labels (2)
2 Solutions

Accepted Solutions
bonnevil
Starfighter Starfighter
Starfighter
  • 689 Views

Yeah, many other languages. YAML's just a data serialization language that's typically UTF-8 encoded text, so really you could use it with any arbitrary programming language as a way to structure objects. The real question is whether the language in question has libraries or other facilities that make it easy to parse YAML files/input or to provide YAML output.

There's a fairly long list at yaml.org under "YAML Frameworks and Tools" that includes, in addition to the languages you mention, C/C++, C#/.Net, Golang, Haskell, Java, JavaScript, PHP, Rust, and a bunch I'm skipping over.

Ansible uses YAML for a bunch of things, of course. If you think of a playbook as a series of structured objects (plays) that contain other structures (hosts, tasks, handlers, play variables), it's really reasonable for that.  Likewise, structuring an inventory as YAML is also a reasonable application.  You should be aware that Ansible (to the best of my knowledge) uses YAML 1.1 syntax; YAML 1.2 has some additional restrictions, including the requirement that Booleans are `true` or `false`; not `True`, `yes`, or other variations that Ansible currently accepts.  (This is one reason why Red Hat teaches `true` and `false` as the preferred syntax for Booleans in playbooks, if at some point upstream decides to switch to YAML 1.2.)

View solution in original post

Travis
Moderator
Moderator
  • 681 Views

@Trevor -

Additionally, YAML is just a file format with lists, dictionaries, and key value pairs. It is very useful for Ansible, Python, and programming languages, but we are also able to use it for a ton of other things. For example, it can be even used in BASH scripts to get things like environment variables, etc.

Both YAML and JSON are used quite often to get formatted data and values because there are such nice tools like jq and yq for processing and accessing this data. I prefer the structure of YAML quite a bit for readability, but for programming languages and parsing things out, sometimes JSON is easier.

 

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training

View solution in original post

2 Replies
bonnevil
Starfighter Starfighter
Starfighter
  • 690 Views

Yeah, many other languages. YAML's just a data serialization language that's typically UTF-8 encoded text, so really you could use it with any arbitrary programming language as a way to structure objects. The real question is whether the language in question has libraries or other facilities that make it easy to parse YAML files/input or to provide YAML output.

There's a fairly long list at yaml.org under "YAML Frameworks and Tools" that includes, in addition to the languages you mention, C/C++, C#/.Net, Golang, Haskell, Java, JavaScript, PHP, Rust, and a bunch I'm skipping over.

Ansible uses YAML for a bunch of things, of course. If you think of a playbook as a series of structured objects (plays) that contain other structures (hosts, tasks, handlers, play variables), it's really reasonable for that.  Likewise, structuring an inventory as YAML is also a reasonable application.  You should be aware that Ansible (to the best of my knowledge) uses YAML 1.1 syntax; YAML 1.2 has some additional restrictions, including the requirement that Booleans are `true` or `false`; not `True`, `yes`, or other variations that Ansible currently accepts.  (This is one reason why Red Hat teaches `true` and `false` as the preferred syntax for Booleans in playbooks, if at some point upstream decides to switch to YAML 1.2.)

Travis
Moderator
Moderator
  • 682 Views

@Trevor -

Additionally, YAML is just a file format with lists, dictionaries, and key value pairs. It is very useful for Ansible, Python, and programming languages, but we are also able to use it for a ton of other things. For example, it can be even used in BASH scripts to get things like environment variables, etc.

Both YAML and JSON are used quite often to get formatted data and values because there are such nice tools like jq and yq for processing and accessing this data. I prefer the structure of YAML quite a bit for readability, but for programming languages and parsing things out, sometimes JSON is easier.

 

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
Join the discussion
You must log in to join this conversation.