← All challenges
mediumautomation~40 min

Generate switch VLAN config from a template

Hand-configuring VLANs and access ports across switches doesn't scale. Write a template that renders the VLAN database and access-port config from a variables file.

Scenario

You manage switches with the same VLAN layout repeated everywhere. Rather than type it out per switch, render the config from a template driven by a variables file: a list of VLANs and a list of access ports with the VLAN each one belongs to.

Your job

In template.j2, generate the switch config so it:

  • declares every VLAN in vlans (vlan <id>)
  • for each port in ports, sets switchport mode access and switchport access vlan <vlan>

Use loops ({% for ... %}) over vlans and ports. Don't hardcode the values.

Variables (what the template is rendered with)

  • vlans: [10, 20, 30]
  • ports: Ethernet1→10, Ethernet2→10, Ethernet3→20, Ethernet4→30

What "done" looks like

The rendered config declares all three VLANs and puts each port in access mode in its VLAN.

Teaches: config templating for switching. Express the layout once and render it from data, so adding a VLAN or a port is a one-line change to the variables.

What gets checked

Your solution is verified against each of these:

  • The config is generated from a template, not hardcoded
  • Every VLAN in the variables is declared
  • Every access port is set to access mode in its VLAN

Solve it in your browser

No setup, no install. Write your solution in the editor and hit Check. The in-house engine renders and grades it instantly, then issues your proof the moment every check passes.

Solve in browser →

Prefer your own lab?

  1. Build the fix locally. New to the tooling? See setting up your lab.
  2. Push your topology file, device configs, and any playbooks to a public repo (GitHub or GitLab).
  3. Submit the repo link. We review it by hand, confirm it works, and issue your proof page.
Submit your solution →