CiscoCCNPEnterprise NetworkingBeginner21 min read

What Is YAML for Network Config in Networking?

Also known as: YAML, YAML network configuration, network automation YAML, CCNP ENCOR YAML, Ansible YAML network config

Reviewed byJohnson Ajibi· Senior Network & Security Engineer · MSc IT Security
On This Page

Quick Definition

YAML for Network Config is a way of writing network settings in a simple text file using indentation and key-value pairs, instead of typing commands one by one. It helps network engineers automate tasks like setting up VLANs, interfaces, or routing protocols across many devices at once. You can think of it as a recipe card that tells the network equipment exactly what to do, written in a format that is easy for people to read and write.

Must Know for Exams

In the Cisco CCNP ENCOR (350-401) exam, YAML for Network Config appears primarily under the Automation and Programmability domain, which accounts for a significant portion of the exam. The exam objectives explicitly require candidates to understand data formats used for network automation, including YAML, JSON, and XML. The ENCOR exam expects you to know how YAML structures data, how it compares to other formats, and how it is used in conjunction with RESTful APIs, NETCONF, and RESTCONF to automate Cisco devices.

You are likely to encounter questions that test your ability to interpret a YAML file. For example, you might be shown a snippet of YAML defining interface configurations and asked to identify which interface has a specific IP address or which VLAN is configured on which port. The exam may also test your understanding of YAML syntax rules, such as the importance of consistent indentation, the use of dashes for lists, and the colon and space for key-value pairs. A common question type presents a block of YAML and asks whether it is valid or what error exists in the file (e.g., mixing tabs and spaces, which YAML forbids).

Beyond syntax, the exam may ask about the role of YAML in network automation workflows. For instance, you could be asked to select the correct sequence of steps to deploy a configuration using Ansible and a YAML playbook. The exam also tests your ability to translate between YAML and other formats like JSON, as many APIs accept both. You might see a question where a JSON payload is displayed, and you need to identify the equivalent YAML representation, or vice versa. Understanding YAML deeply helps you answer these questions confidently, especially because the ENCOR exam is known for including detailed automation scenarios that require careful reading of configuration files.

Simple Meaning

Imagine you are trying to give someone directions to your house. You could write a long paragraph full of street names and landmarks, but it might be easy to get lost or misread. Instead, you could write a simple list with clear steps: turn left on Main Street, then turn right on Oak Avenue, then stop at the blue house on the corner. This list is easy to follow because it is structured and uses plain language.

YAML works in a similar way for network devices like routers and switches. Instead of typing complex command line instructions that look like a foreign language, you write a simple list of configuration settings using words and indentation. For example, you might write a section called interfaces, then underneath it list each interface name, and under each interface name, list the IP address and status. The indentation tells the computer which items belong together, just like an outline for a school paper.

YAML stands for YAML Ain't Markup Language, which means it is designed to hold data in a clean, readable way, not to format a web page. It uses a few basic structures: key-value pairs, where a setting name is followed by a colon and its value; lists, where items start with a dash; and nested blocks, which are created by adding spaces at the beginning of a line. For network configuration, these structures let you define complex setups like a VLAN database, interface configurations, routing policies, and more, all in one file.

The real power of YAML in network automation comes when you combine it with tools like Ansible or Python scripts. A network engineer can write a single YAML file that defines the desired state of an entire network, then use automation software to apply that configuration to hundreds of devices in minutes. This reduces errors caused by manual typing and makes it easy to standardize configurations across the organization.

Full Technical Definition

YAML (YAML Ain't Markup Language) is a data serialization standard that uses human-readable text to represent structured data. In the context of network configuration, it serves as a declarative input format for automation frameworks, allowing network engineers to define the intended operational state of network devices without writing procedural code. YAML files typically use a .yaml or .yml extension and rely on indentation to indicate hierarchy, avoiding the use of brackets, tags, or quotation marks for basic structures.

The core components of YAML include scalars, mappings, and sequences. Scalars are single values such as strings, integers, or booleans. Mappings, also called dictionaries or hashes, consist of key-value pairs separated by a colon and a space. Sequences are ordered lists, indicated by a dash and a space before each item. These three building blocks can be nested arbitrarily to represent complex network configurations. For example, a YAML file defining an interface configuration on a Cisco device might look like:

interfaces: GigabitEthernet0/1: description: "Link to Core Switch" ip_address: 10.0.0.1 255.255.255.0 duplex: full speed: 1000

In real IT environments, YAML is commonly used with automation platforms such as Ansible, which uses YAML to define playbooks that declare automation tasks. For Cisco networking, Ansible modules like ios_config or nxos_config can read YAML variables and generate the corresponding CLI commands. YAML also integrates with other tools such as SaltStack, Puppet, and Chef, and is natively supported by many network programmability interfaces including NETCONF and RESTCONF, where it can be used to represent YANG data models.

The technical advantage of YAML lies in its readability and its suitability for version control. Network teams can store YAML configuration files in Git repositories, enabling change management, collaboration, and rollback. YAML also supports anchors and aliases to reduce duplication, which is useful when applying similar configurations across multiple interfaces or devices. Additionally, YAML is language-agnostic, meaning it can be parsed by Python, Go, Ruby, and many other programming languages, making it a flexible choice for network automation pipelines.

Real-Life Example

Think of a building manager who needs to set up security key cards for a large office. The office has 100 doors, and each door may allow access to different employees based on their roles. If the manager had to program each door individually with a keypad, it would take days, and it would be easy to accidentally give a cleaner access to the server room. Instead, the manager uses a simple chart. On the chart, they list all employees down the left side. Across the top, they list all doors. In each cell, they put a checkmark or an X to indicate who can enter which door. This chart is easy to read, easy to update, and can be followed by a technician to program all doors at once.

YAML works exactly like this chart for network devices. The YAML file is your chart. The keys are the settings you want to configure, like the name of a VLAN or the IP address of an interface. The values are the actual settings, like VLAN ID 10 or IP 192.168.1.1. The indentation in YAML is like the rows and columns of the chart it keeps things organized so that the computer understands which settings belong to which part of the device. For example, if you want to configure three VLANs, you would list VLAN as a section, then under it, list each VLAN with its ID and name. This makes it impossible to accidentally assign a setting to the wrong VLAN because the structure clearly groups them.

Once the YAML file is created, an automation tool like Ansible reads it just like the technician reads the chart. The tool then applies the correct configuration to each device automatically. If you need to change a setting, you edit the YAML file instead of logging into each device. This reduces human error and saves time, especially when managing networks with hundreds of routers and switches.

Why This Term Matters

YAML for Network Config matters because it fundamentally changes how network engineers design, deploy, and manage network infrastructure. In the past, configuring a router meant logging in via SSH and typing command after command, a process that was slow, error-prone, and difficult to scale. With YAML, engineers can define the entire desired state of a network in a single text file. This file becomes the single source of truth, meaning there is one place to look to understand how the network is supposed to behave.

In real IT work, this has practical benefits. When a network grows from 10 devices to 1000 devices, manually configuring each one becomes impossible. YAML files, combined with automation tools, allow a small team to configure and maintain thousands of devices consistently. This consistency is critical for security and reliability. If every switch has the same VLAN configuration expressed in YAML, there is less chance of a misconfigured port causing a security vulnerability or a network outage.

YAML also supports version control. Network teams can commit YAML files to Git repositories, which means every change is tracked, reviewed, and reversible. This brings software engineering best practices to networking. If a YAML change accidentally breaks a configuration, the team can quickly revert to a previous version. This is especially important in enterprise environments where downtime costs thousands of dollars per minute.

Furthermore, YAML enables collaboration. Junior engineers can write YAML files because the syntax is simple, while senior engineers can review them before deployment. This separation of concerns reduces the risk of errors and makes the network team more productive. YAML also integrates with CI/CD pipelines, so network changes can be tested in a lab environment before being pushed to production, exactly like software updates. This level of automation and precision is the foundation of modern network operations, often called NetDevOps.

How It Appears in Exam Questions

Learners encounter YAML for Network Config in several types of exam questions. The most common is the syntax identification question. In these, you are shown a YAML code block and asked to determine if it is correctly formatted. For example, you might see:

vlans: - id: 10 name: Sales - id: 20 name: Engineering

And the question asks: Is this YAML valid? If not, why? The trap here is that YAML requires spaces after indentation, not tabs. Another variation asks you to correct an improperly indented file.

The second type is the interpretation question. You are given a YAML file that defines network parameters, and you must answer questions about it. For instance: Based on the YAML snippet, which interface is configured with IP address 192.168.1.1? Or: How many VLANs are defined in the file? These questions test your reading comprehension of structured data.

The third type is the comparison question. You might be asked to distinguish YAML from JSON or XML. For example: Which data format uses indentation to denote hierarchy? Or: Which format is considered most human-readable? The exam expects you to know that YAML is the most human-readable, JSON is more compact, and XML uses nested tags.

The fourth type is the application scenario. A question might describe a problem: A network engineer needs to automate the configuration of OSPF on 50 routers. Which tool and data format would be most appropriate? The correct answer typically involves Ansible with YAML because Ansible playbooks are written in YAML. You might also need to identify the correct YAML structure for a given task, such as defining an OSPF area.

Finally, troubleshooting questions sometimes present a YAML file that fails to apply correctly, and you must identify the issue, such as a missing space after a colon or inconsistent indentation. These questions test both your attention to detail and your knowledge of YAML rules.

Study encor

Test your understanding with exam-style practice questions.

Practise

Example Scenario

A network administrator named Sam is responsible for configuring 20 new switches that have just been installed in a company office. Traditionally, Sam would connect to each switch with a console cable, type the same commands 20 times, and hope no mistakes occur. This time, Sam decides to use YAML to automate the task.

Sam first creates a YAML file called switch_config.yaml. In the file, Sam writes the desired configuration for all VLANs, interface descriptions, and access ports. The file looks like this:

vlans: - id: 10 name: Sales - id: 20 name: Engineering

interfaces: - name: GigabitEthernet0/1 description: Sales Desktop vlan: 10 - name: GigabitEthernet0/2 description: Engineering Desktop vlan: 20

Sam then runs an Ansible playbook that reads this YAML file and applies the configuration to each switch over SSH. Within minutes, all 20 switches are configured exactly the same way. Later, when the company decides to rename the Sales VLAN to Retail, Sam simply updates the YAML file and runs the playbook again. The entire network is updated in one operation, without any risk of missing a switch or making a typo. This scenario shows how YAML makes network configuration fast, consistent, and easy to maintain.

Common Mistakes

Using tab characters for indentation instead of spaces.

YAML strictly defines that indentation must be done with spaces. Using tabs causes a parsing error because different text editors or systems can interpret tabs differently, breaking the indentation rule.

Always configure your text editor to insert spaces when you press the Tab key. Most editors have a setting to use spaces for indentation, usually set to 2 spaces per indentation level.

Forgetting to put a space after the colon in a key-value pair.

In YAML, the key and value must be separated by a colon followed by a space. Without the space, the parser treats the whole thing as a single string, not as a key-value pair, leading to incorrect data structure.

Always write key: value with exactly one space after the colon. For example write vlan: 10, not vlan:10.

Mixing different indentation levels in the same block.

YAML uses consistent indentation to determine parent-child relationships. If one line is indented by 2 spaces and the next by 3 spaces, the parser cannot determine the hierarchy and will throw an error.

Choose a consistent number of spaces for each indentation level (usually 2 or 4) and stick to it throughout the entire file. Use the same indentation for all items at the same level.

Thinking YAML is a programming language instead of a data format.

YAML does not execute commands or run logic. It only holds data. Some learners try to write conditional statements or loops inside YAML, which will not work. YAML is read by automation tools that perform the actual logic.

Understand that YAML is a data description language, like a configuration file. It stores values and structures. The logic happens in the automation tool (like Ansible) that reads the YAML file.

Not quoting strings that contain special characters like colons, dashes, or pound signs.

YAML interprets certain characters as syntax. For example, a colon used in a description could be mistaken for a key-value separator. This can cause parsing errors or unexpected data truncation.

Enclose any string that contains special characters in double quotes. For example write description: "Configuration for VLAN 10: Sales" to ensure the colon inside the string is not misinterpreted.

Exam Trap — Don't Get Fooled

An exam question shows a YAML snippet where indentation appears correct, but one line uses a TAB while others use spaces. The candidate thinks it is valid because it looks aligned visually. Remember the rule: YAML only allows spaces for indentation.

A single tab character, even if it looks aligned, will cause a parse error. In the exam, if you see a code snippet, assume that tabs are not allowed. Check for the absence of tab characters in any YAML-related question.

Commonly Confused With

YAML for Network ConfigvsJSON

JSON uses curly braces, brackets, and commas to structure data, making it more compact but less human-readable than YAML. YAML relies on indentation and newlines, which makes it easier to read for configuration files. Both can represent the same data but in different syntax.

In JSON, a VLAN configuration looks like: {"vlans": [{"id": 10, "name": "Sales"}]}. In YAML, the same data is: vlans: - id: 10 name: Sales. YAML is cleaner for network configs.

YAML for Network ConfigvsXML

XML uses opening and closing tags like <vlan><id>10</id></vlan> to define structure. This is very verbose compared to YAML. YAML is preferred in automation tools like Ansible because it is less cluttered and reduces the chance of missing a closing tag.

An XML interface config: <interface><name>Gig0/1</name><ip>10.0.0.1</ip></interface>. In YAML: interface: name: Gig0/1 ip: 10.0.0.1. The YAML version uses fewer characters and is easier to write.

YAML for Network ConfigvsAnsible Playbook

An Ansible Playbook is a YAML file that contains tasks and automation steps, not just data. YAML for network config is a data file that holds settings like IP addresses or VLANs, while an Ansible Playbook is the script that uses that data to perform actions on devices.

A YAML data file might list VLANs. An Ansible Playbook in YAML format would include a task like: - name: Configure VLANs ios_vlan: vlan_config: "{{ vlan_data }}". The two work together but serve different purposes.

YAML for Network ConfigvsTerraform HCL

HCL (HashiCorp Configuration Language) is a dedicated language for infrastructure provisioning, while YAML is a generic data format. HCL supports logic like loops and conditionals natively, whereas YAML requires an external tool like Ansible to interpret it. YAML is simpler but less powerful on its own.

In Terraform HCL, you write resource "network_interface" "example" { name = "eth0" }. In YAML, you would just write name: eth0 and rely on Ansible to create the resource.

Step-by-Step Breakdown

1

Define the Root Mapping

Start your YAML file with a top-level key that represents the main category of configuration, such as vlans or interfaces. This key becomes the parent of all related settings. For example, write vlans: on its own line to begin defining VLANs.

2

Add Sequence Items with Dash

If you have multiple items of the same type, such as multiple VLANs, list them under the parent key using a dash and a space. Each dash represents one item in a list. For example, - id: 10 means the first VLAN with ID 10.

3

Nest Key-Value Pairs Under Each Item

For each list item, indent by 2 spaces and add key-value pairs that describe that item. For a VLAN, you might add id and name. The indentation shows that these keys belong to that specific item. Make sure all keys at the same level share the same indentation.

4

Add Additional Sections as Needed

You can define multiple root mappings in the same file, separated by a blank line for readability. For example, after defining vlans, you can add a new section for interfaces. Each section operates independently under its own parent key.

5

Validate Indentation and Syntax

Before using the YAML file, run it through a YAML linter or a simple check tool to ensure there are no tabs, extra spaces, or missing colons. A valid YAML file parses without errors. Many code editors have built-in YAML validation that highlights problems in real time.

6

Reference Variables in Automation Tool

Once the YAML file is ready, use it as a variable source in your automation tool. In Ansible, you would load this file using include_vars or a vars_files directive, then reference the keys in your tasks. For example, {{ vlans }} would give you the list of VLANs defined in the file.

Practical Mini-Lesson

YAML for Network Config is a skill that every modern network engineer needs to master. At its core, YAML is about representing structured data in a way that both humans and machines can understand easily. The most important rule to remember is that indentation counts. In YAML, two spaces of indentation are standard, but the key is consistency. If you indent the first level by two spaces, every other line at that same level must use exactly two spaces. Mixing indentation levels is the most common source of errors.

When you start writing YAML, begin with a simple file. Define one section, such as interfaces. Under interfaces, list each interface as a list item using a dash. Then under each interface, indent and add properties like name, description, and ip_address. Keep the file tidy by adding a blank line between major sections. Always use a colon followed by a space between key and value. Never use a tab.

In practice, network professionals often combine YAML with Ansible. The YAML file becomes a variables file that holds all the site-specific data, such as IP addresses, VLAN IDs, and interface names. The Ansible playbook, also written in YAML, contains the tasks that apply those settings. This separation of data and logic is powerful because it allows you to reuse the same playbook for different sites by simply swapping the YAML variables file.

What can go wrong? Besides indentation issues, the most common problem is using special characters in unquoted strings. If you write description: Link to HQ - Primary, the dash could be misinterpreted as a list indicator. Always quote strings that contain punctuation. Another issue is forgetting that YAML is case-sensitive. The key IP_address is different from ip_address. Choose a naming convention and stick to it.

Finally, YAML connects to broader IT concepts like Infrastructure as Code (IaC) and NetDevOps. By storing network configurations as code in YAML, you gain the ability to version control, review, test, and deploy changes with the same rigor as software development. This reduces outages, improves compliance, and makes the network team more agile. Learning YAML is a stepping stone to mastering network automation, which is a core requirement for CCNP and other advanced certifications.

Memory Tip

YAML uses spaces for structure to keep data clean. Remember the three tools: a colon for key-value, a dash for lists, and two space indents to nest. No tabs, no excuses.

Covered in These Exams

Related Glossary Terms

Frequently Asked Questions

Do I need to install any software to use YAML for network configuration?

No, YAML files are plain text files that you can create with any text editor. However, to apply the configuration to network devices, you need an automation tool like Ansible, which reads the YAML file and executes the configuration commands.

What is the difference between YAML and JSON for network automation?

Both are data formats, but YAML is more human-readable because it uses indentation instead of brackets and commas. JSON is more compact and often used in APIs. For network configuration files that people need to edit and review, YAML is generally preferred.

Can I use YAML directly on a Cisco router?

No, Cisco routers do not natively parse YAML files. YAML is used with external automation tools like Ansible or Python scripts, which then apply the configuration to the router via SSH, NETCONF, or RESTCONF.

How do I handle indentation errors in YAML?

Most errors come from using tabs or inconsistent spaces. Use a YAML linter (online tool or editor plugin) to check your file. Ensure every indentation level uses the same number of spaces, typically 2 per level.

Is YAML case-sensitive?

Yes, YAML key names are case-sensitive. interface, Interface, and INTERFACE are three different keys. Choose a consistent naming convention and stick to it throughout your file.

Can I include comments in a YAML file?

Yes, YAML supports comments using the hash symbol at the start of a line. For example: This is a comment. Comments are ignored by the parser and help document your configuration.

What is a YAML anchor and alias?

An anchor is a label you assign to a block of data using the ampersand symbol, and an alias is a reference to that anchor using the asterisk symbol. This helps you reuse configuration blocks without duplicating text, reducing repetition in large files.

Do I need to put quotes around all strings in YAML?

No, only quote strings that contain special characters like colons, dashes, exclamation marks, or square brackets. Plain text without special characters can be left unquoted. But when in doubt, using double quotes is safe.

Summary

YAML for Network Config is a human-readable data format that allows network engineers to define device configurations in a structured, indentation-based text file. It is not a programming language but a way to store settings that automation tools can read and apply. YAML uses three main structures: key-value pairs for properties, sequences with dashes for lists, and nested indentation for hierarchy. The most important technical rule is to use spaces for indentation, never tabs, and to be consistent.

In real IT work, YAML is the backbone of network automation with tools like Ansible. It enables teams to manage hundreds of devices from a single file, enforce standard configurations, and use version control for all network changes. For the CCNP ENCOR exam, YAML appears in the Automation and Programmability domain, where you will be tested on syntax, interpretation, and application. You may be asked to identify valid YAML, translate between formats, or choose the right tool for an automation task. Avoiding common mistakes like mixing tabs and spaces or forgetting colons is critical for exam success. Understanding YAML deeply prepares you for modern network engineering roles that demand automation skills.