📂

Understanding YQ for YAML Parsing

May 22, 2025

Lecture Notes: Parsing YAML Files with YQ

Introduction to YQ Templating

  • Purpose: To learn YQ templating and how to read YAML files.
  • Context: YAML files are prevalent in DevOps for configuration.
  • Goal: To simplify development/modifications using Python or other languages.

Recap of Previous Sessions

  • Covered Topics:
    • Reading and writing YAML files with Python.
    • Inserting data into MySQL databases using Python.

Today's Focus

  • Installing YQ:
    • Quick installation on Ubuntu and Windows.
  • Examples:
    • Reading YAML files.
    • Creating variables from YAML files.

YAML File Structures

  • Key Types:
    • Key-Value Pairs: Basic association (e.g., pi: 3.14).
    • Arrays/Lists: Collection of similar objects (e.g., tables array).
    • Dictionaries: Maps or collections of key-value pairs (e.g., Xmas 50 map).

Practical Examples with YQ

  • Installation Steps:
    • Ubuntu: Install using brew or directly using wget.
    • Windows: Download exe, add to environment path variable.
  • Usage:
    • Use YQ commands to read different data types in YAML.
    • Extract values and store them for further use (e.g., in Azure pipelines).

Working with Arrays and Dictionaries

  • Array Handling:
    • Retrieve array elements and values through correct indexing.
  • Dictionary Access:
    • Navigate nested dictionaries to fetch specific data.

Additional Resources and Documentation

  • GitHub Repository: Contains YQ templating examples.
  • Command Syntax: Detailed explanation of commands used to parse YAML.

Conclusion

  • Understanding YAML Parsing:
    • Important for handling complex configurations in DevOps.
  • Further Learning:
    • Explore YQ GitHub for more examples and development insights.
  • Engagement:
    • Encouragement to subscribe and comment for more support.
  • Summary: Overview of YQ usage through examples and commands.

  • If there are any questions or challenges while working with YAML and YQ, viewers are encouraged to comment and seek further clarification.