#!/usr/bin/env python3
"""Validate playbook YAML files have required keys."""
import yaml
import sys
import glob

required_keys = {'name', 'description'}

for f in glob.glob('playbooks/*.yaml'):
    with open(f) as fh:
        try:
            data = yaml.safe_load(fh)
            if not isinstance(data, dict):
                print(f'ERROR: {f} is not a YAML mapping')
                sys.exit(1)
            missing = required_keys - set(data.keys())
            if missing:
                print(f'WARNING: {f} missing keys: {missing}')
            print(f'OK: {f}')
        except yaml.YAMLError as e:
            print(f'ERROR: {f}: {e}')
            sys.exit(1)
