Generate Playbook Documentation Script

This script automates documentation for all Ansible playbooks in the repository. It enforces the presence of a # Purpose: comment, generates per‑playbook documentation under docs/playbooks/, builds folder‑level summaries inside the playbooks/ tree, and maintains a global index of all playbooks.
It is executed by the Generate Ansible Playbook Docs GitHub Action workflow.


🐍 Python Script: generate_playbook_docs.py

The script performs the following steps:


1. Purpose Extraction


2. Role Detection


3. Per‑Playbook Documentation Generation

docs/playbooks/<playbook>.md

4. Global Playbook Index

docs/playbooks/README.md

5. Folder‑Level Indexes


6. Single Playbook Mode

If the script is run with a specific playbook path:

python scripts/generate_playbook_docs.py playbooks/infra/prepare-node.yml

📂 Example Outputs

Per‑Playbook Documentation (docs/playbooks/deploy-ansible.md)

# 📖 Playbook: deploy-ansible.yml

## 🛠 Purpose
Sets up the Ansible control node and prepares managed nodes with required roles.

## 🔗 Roles Applied
- [`global`](../roles/global.md)
- [`ansible_node`](../roles/ansible_node.md)

## 🚀 Usage

bash ansible-playbook playbooks/deploy-ansible.yml


Folder Index (playbooks/ansible/README.md)

markdown
# 📚 Playbooks in `ansible`

| Playbook | Purpose |
|----------|---------|
| [`deploy_ansible.yml`](../../docs/playbooks/deploy_ansible.md) | Prepares VMs and baremetal hosts for Ansible management |


Global Index (docs/playbooks/README.md)

markdown
# 📚 Playbook Index

## 📂 Playbooks in root `playbooks/`

| Playbook | Purpose |
|----------|---------|
| [`deploy-ansible.yml`](deploy-ansible.md) | Sets up the Ansible control node and prepares managed nodes |

## 📂 Playbooks in subfolders

| Playbook Path | Purpose |
|----------------|---------|
| [`infra/prepare-node.yml`](prepare-node.md) | Prepares VMs and baremetal hosts for Ansible management |
| [`security/firewall.yml`](firewall.md) | Configures firewall rules for managed nodes |

✅ Contributor Expectations