YAML stores the same data as JSON, with less to type.
You write a key, a colon, a space and the value:
Figure 1 - The Same Data in JSON and in YAML
There are no braces, and most strings need no quotes.
In the lab, add the key
modelwith the value C9300 toswitch.yaml.
Runshow.pyto get the flag.Answer the question below
Enter the flag you obtained.
In YAML, the spaces at the start of a line replace the braces and the brackets.
A list item starts with a dash, and two spaces put a key inside the key above it:
Figure 2 - A List and Nested Keys in YAML
You can use more than two spaces, but never a tab.
In the lab, the file
inventory.yamlis a list with one switch.
Add the switch SW2 with the address 10.0.0.3 and the VLANs 10 and 30, then runshow.pyto get the flag.Answer the question below
Enter the flag you obtained.
Python parses YAML like JSON, with the module
yaml.
Its functionyaml.safe_load()gives the same dictionary asjson.load():
Figure 3 - Two Files, the Same Dictionary
In a script, you open the file with
open(), then you give it toyaml.safe_load():import yaml with open("switch.yaml") as file: switch = yaml.safe_load(file) print(switch["name"]) # Output: SW1The module
yamldoes not come with Python. It is in the package PyYAML, already installed in the lab.In the lab, load
inventory.yamlinaudit.py.
Print the number of VLANs of each switch in this format to get the flag:SW1: ?Answer the question below
Enter the flag you obtained.