YAML (YAML Ain't Markup Language) is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted.
In the DevOps ecosystem, YAML is the industry standard for Infrastructure as Code (IaC). Its clean, indentation-based structure makes it the primary language for defining configurations in tools like Ansible and Docker. It allows developers to separate application logic from environment settings.
| Feature | Technical Role | Strategic Value |
|---|---|---|
| Readability | Human-Centric Syntax | Minimizes syntax errors compared to JSON or XML; easier for teams to audit. |
| Serialization | Data Mapping | Easily converts complex data structures into a format Python or PHP can parse. |
| Portability | Environment Agnostic | Configs stay separate from logic, allowing the same code to run in different environments. |
This demonstration shows how a Python script references external YAML configuration files to set game parameters like range and difficulty mode.
range:
min: 1
max: 1000
guesses: 10
mode: single
import random
import yaml
import getpass
# Load the external configuration
with open("py-nn1-gamedata.yaml","r") as f:
config = yaml.safe_load(f)
# Map YAML data to local variables
range_min = config['range']['min']
range_max = config['range']['max']
guesses_allowed = config['guesses']
mode = config['mode']
solved = False
if mode == "single":
correct_number = random.randint(range_min, range_max)
elif mode == "multi":
# 2 player mode, player2 provides the number
correct_number = int(getpass.getpass("player2, enter the number to guess!")) # hide the input on the screen
else: # check for invalid config
print("invalid config")
exit()
# Game Loop
for i in range(guesses_allowed):
guess = int(input("enter your guess:"))
if guess == correct_number:
print(f"Correct, you used {i + 1} tries.")
solved = True
break
elif guess < correct_number:
print(f"too low")
else:
print(f"too high")
if not solved:
print("you lost, the number was", correct_number)
This ledger tracks the verified data-handling operations completed within this environment.
| Domain | Verified Action / Command | Functional Result |
|---|---|---|
| Python | pip install pyyaml |
Installed the library required for Python to interpret YAML files. |
| Serialization | YAML Data Mapping | Successfully parsed nested objects (range:min) into active code variables. |
| Logic Audit | Game Logic: Lab 2.1 | Verified conditional branching based on "mode" parameter from YAML. |
Also see: Python demo →