Pcornel
Automation · Python Automation

YAML

Cheat sheet · https://pcornel.dk/topic.php?topic=5268

Back to the Topic

Answer

Python reads YAML with PyYAML (yaml.safe_load), never yaml.load on untrusted input, turning playbooks, inventories and configs into dictionaries and lists.

Remember

  • Use yaml.safe_load.
  • Never use yaml.load on untrusted input.
  • YAML type guessing can surprise you.

First checks

  • python3 -c 'import yaml;yaml.safe_load(open("f.yaml"))' — safe parse
  • yamllint f.yaml — lint
  • Never yaml.load without SafeLoader — security

Verify in this order

YAML text → safe_load → objects → validation

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5268

Confirmation

Confirm action

Continue?