CCNA 200-901: The Network Engineer’s Guide to YAML Data Types | Knowledgestreams
If you are gearing up for the CCNA Automation (200-901) exam, you already know that the days of managing networks purely through the CLI are fading fast. Modern network programmability relies heavily on structured data, and at the heart of tools like Ansible and Python-driven automation is YAML.
| Master YAML |
YAML (YAML Ain't Markup Language) is incredibly human-readable, but if you don't understand its core data types, a single misplaced space can break your entire automation script.
Welcome to another deep dive by Knowledgestreams. Today, we are stripping away the complexity and breaking down the basic YAML data types you absolutely need to know to crush your 200-901 exam and build rock-solid network automation.
The Big Three: Basic YAML Data Types
YAML was designed to be cross-compatible with most modern programming languages (like Python, JavaScript, Ruby, and PHP). It accomplishes this by relying on three foundational data structures:
Scalars (Strings, numbers, and booleans)
Sequences (Lists or arrays)
Mappings (Hashes, dictionaries, or key-value pairs)
Let’s look at exactly how they work in a networking context.
1. Scalars: The Building Blocks
Think of scalars as the actual "data" on your page. They are the individual strings, IP addresses, or integers you are trying to configure. YAML gives you five different styles for writing scalars, depending on how complex your text is.
Plain: No quotes or indicators. Used for simple text or numbers.
Single-quoted (
'): Wraps the value. It prevents YAML from treating special characters as syntax. (Note: No escaping occurs here, except that duplicate quotes''are read as a single quote).Double-quoted (
"): Used when you need to use escape sequences like\u****for Unicode characters or\x**for ASCII.Literal block (
|): Perfect for multi-line configurations (like banners or certificates). It preserves all your exact line breaks.Folded block (
>): Similar to the literal style, but it automatically folds consecutive non-empty lines into a single line separated by spaces. It only preserves forced blank lines.
Cisco Official link
YAML Scalar Examples:
YAML Scalar Example |
2. Sequences: Making Lists
In network automation, you rarely deal with just one of anything. You have multiple VLANs, multiple routing peers, and multiple interfaces. In YAML, we handle these using Sequences.
Sequences are simply lists. Each item in the list is placed on its own line and starts with an opening dash (-) followed by a space.
Basic Sequence Example
Sequence Example |
Nested Sequences
You can create lists within lists (sub-items) by indenting the child items. In YAML, indentation is strictly enforced using spaces (never tabs!).
| Nested Sequences Example |
You can go as many levels deep as your automation logic requires, simply by maintaining proper space indentation.
3. Mappings: Key-Value Pairs
Mappings are exactly what they sound like: they map a specific key to a specific value. If you are familiar with Python dictionaries (a massive part of the CCNA 200-901 curriculum), mappings are the exact YAML equivalent.
They are created using a colon and a space (: ).
Basic Mapping Example
Mapping Example |
Combining Mappings and Sequences (Real-World Usage)
In the real world of DevNet and CCNA automation, you will almost always combine mappings and sequences. For example, if you are writing a playbook to configure a list of interfaces, you map a key (like interfaces) to a sequence (your list of ports).
| Combining Mappings and Sequences |
Wrapping Up
Mastering these three basic structures—Scalars, Sequences, and Mappings—is your first major step toward passing the CCNA Automation (200-901) exam. Once you know how to format your data, pushing configurations to Cisco devices via Python or Ansible becomes incredibly straightforward.
Ready to take your network programmability skills to the next level? Stay tuned to Knowledgestreams for more hands-on DevNet tutorials, labs, and exam prep guides!