Taking a look at the Cisco DevNet Associate exam topics (DEVASC 200-901), one of the first objectives is to compare different data formats. Those data formats you should be able to compare are XML, JSON, and YAML.
To start, I decided to take a look at YAML and what it has to offer from a very basic overview. I’m very new when it comes to DevOps or NetDevOps but this will become my notes of sorts as I look into the DevNet Associate certification.
Studying for the Cisco DevNet Associate Certification?
Let me know what your coding experience is in the comments below.
YAML is a human-readable structured data format which stands for Stands for Yet Another Markup Language or now YAML Ain’t Markup Language, depending on where you look 😉 The official documentation page states the latter.
Goals of YAML
- Data serialization standard for programming languages.
- Human-readable structured data format.
- Portable between programming languages.
- Consistent model.
- Expressive and extensible.
- Easy to implement and use.
A quick overview of YAML
- Writable and readable.
- Case sensitive
- Files end in
.yaml
or.yml
- Spaces are used instead of tabs (because various tools treat tabs differently)
- Indentation is used for structure
- Colons separate key-value pairs
- Dashes create bullet lists
- The start of a YAML file begins with three dashes
Data structures:
- Mappings (hashes/dictionaries)
- Sequences (arrays/lists)
- Scalars (strings/numbers)
Working with Blocks
Block collections use indentation for scope and begin each entry on its new line. Block sequences use a dash and space to indicate each entry. Mappings use a colon and space to mark a key-value pair.
To create a comment, you must use a hash tag.
Sequence
A sequence entry will be denoted by a dash -
.
- netsw-idf-01
- netsw-idf-02
- netsw-idf-03
Scalar
A scalar is just a single value. They can be strings, numbers, Boolean, or null values.
# scalars can be quoted
“GigabitEthernet1/0/1”
# scalars can also be unquoted
GigabitEthernet1/0/2
Mapping Scalars to Sequences
Also creates an array.
routers:
- rtr-idf-01
- rtr-idf-02
switches:
- netsw-idf-01
- netsw-idf-02
Sample Inventory in YAML
—--
sites:
- name: san-jose # This is a comment. Begin block 1.
hosts:
- hostname: r1
host: 192.168.1.1
os: cisco_ios
- hostname: sw1
host: 192.168.1.5
os: cisco_ios
- hostname: sw2
host: 192.168.1.6
os: junos
- name: san-diego # This is a comment. Begin block 2.
hosts:
- hostname: r2
host: 192.168.2.1
os: cisco_ios
- hostname: sw1
host: 192.168.2.5
os: cisco_ios
Have we created a list or a dictionary? List items which is a dictionary.
Here’s a sample YAML script used to configure a VLAN on a Cisco switch.
---
- hosts: cisco
connection: network_cli
tasks:
- nxos_vlan:
vlan_id: 10
name: STORAGE
Short and simple read. I will be looking forward to more blog posts on your site.
I had studied basic programming probably 10 years back and still remember few things here and there. I have started studying Python and its fun so far but when it comes to integrating it with other DevOps tools, it gets on my nerves 🙂