← Inapoi la Hub
---

YAML

Format lizibil pentru configurari, CI/CD, Docker si Kubernetes

Ce este YAML?

YAML (YAML Ain't Markup Language) este un format de serializare a datelor, optimizat pentru:

YAML vs JSON

YAML:
nume: Maria varsta: 15 esteElev: true
JSON echivalent:
{ "nume": "Maria", "varsta": 15, "esteElev": true }
💡 YAML este mai curat! Fara acolade, fara ghilimele pentru chei, fara virgule.

Sintaxa de Baza

# Acesta este un comentariu string: text simplu string_ghilimele: "text cu ghilimele" numar: 42 decimal: 3.14 boolean: true null_value: null
⚠️ Atentie la indentare! YAML foloseste spatii (nu tab-uri) pentru structura. De obicei 2 spatii.

Liste (Arrays)

# Lista simpla clase: - 5A - 6B - 7A # Lista inline note: [10, 9, 8, 10]

Obiecte Imbricate

elev: nume: Ion Popescu clasa: 7A note: romana: 9 matematica: 10 informatica: 10

Text Multi-linie

# Pastreaza newlines (|) descriere: | Aceasta este prima linie. Aceasta este a doua linie. Fiecare linie ramane separata. # Concateneaza liniile (>) paragraf: > Acest text lung va fi concatenat intr-o singura linie.

Exemplu: GitHub Actions

name: CI Pipeline on: push: branches: [main] pull_request: branches: [main] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Run tests run: npm test

Exemplu: Docker Compose

version: "3.8" services: web: image: nginx:latest ports: - "80:80" volumes: - ./html:/usr/share/nginx/html database: image: postgres:14 environment: POSTGRES_DB: myapp POSTGRES_USER: admin

Reguli Importante

RegulaDetalii
IndentareFoloseste 2 spatii, NU tab-uri
CheiNu au nevoie de ghilimele (de obicei)
ComentariiIncep cu #
Booleantrue/false sau yes/no
ListeIncep cu - (dash + spatiu)

Unde se foloseste YAML?

ContextFisier
GitHub Actions.github/workflows/*.yml
Docker Composedocker-compose.yml
Kubernetesdeployment.yaml
Ansibleplaybook.yml
Jekyll/HugoFront matter in Markdown