squirrelworks

Infrastructure: YAML & Data Serialization

Acorn

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.

Why YAML for DevOps?
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.

2. Implementation: Python & YAML Interaction

This demonstration shows how a Python script references external YAML configuration files to set game parameters like range and difficulty mode.

Configuration: py-nn1-gamedata.yaml
range:
  min: 1
  max: 1000

guesses: 10

mode: single
Logic: Python Parser
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)
Thank you @NeuralNine
Execution Ledger: Verified YAML Operations

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.


Accessibility
 --overview

Agile
 --DevOps overview
 --Principles

API
 --REST best practices
 --REST demo
 --REST vs RPC
 --Wikipedia API

Blockchain
 --overview

Cloud
 --AWS overview

CSS/HTML
 --Bootstrap carousel
 --Grid demo
 --markdown demo

Electricity
 --fundamentals

Encoding
 --Overview

Ergonomics
 --Desk configuration
 --Device fleet
 --Input device array
 --keystroke mechanics
 --Phones & RSI

ERP
 --Anthology overview
 --Ellucian Banner
 --Higher Ed ERP Simulation Lab
 --PeopleSoft Campus Solutions
 --PESC standards
 --Slate data model

Git
 --syntax overview
 --troubleshooting libcrypto

Hardware
 --Device fleet
 --Homelab diagram

Java
 --Fundamentals

Javascript
 --Advanced Interaction: jQuery & UI Frameworks
 --input prompt demo
 --misc demo
 --Time and Date functions
 --Vue demo

Linux
 --grep demo
 --HCI and Proxmox
 --Proxmox install
 --xammp ftp server

Mail flow
 --DKIM, SPF, DMARC
 --MAPI

Microsoft
 --AZ-800: Administering Windows Server Hybrid Core Infrastructure
 --BAT scripting
 --Group Policy
 --IIS
 --robocopy
 --Server 2022 setup - Virtualbox

Misc
 --Applications
 --regex
 --Resources
 --Sustainable Computing
 --Terminology
 --Tribute to Computer Scientists

Networks
 --BGP Peering & Security Hardening Lab
 --CCNA Lammle Study Guide
 --Cisco 1921/K9 router
 --routing protocols
 --throughput calculations

PHP/SQL
 --Cookies
 --database interaction
 --demo, OSI Layers quiz
 --Foreign key constraint demo
 --fundamentals
 --MySQL and PHPmyAdmin setup
 --pagination
 --security
 --session variables
 --SQL fundamentals
 --structures
 --Tables display

Python
 --fundamentals

Security
 --Overview- GRC (Governance, Risk, and Compliance)
 --Security Blog
 --SSH fundamentals

Serialization
 --JSON demo
 --YAML demo