CYBER-0 ansible-testing update

This commit is contained in:
Ole
2026-08-31 13:35:40 +02:00
parent ca9312379a
commit 042ddc63d5
6 changed files with 60 additions and 162 deletions
+19 -21
View File
@@ -57,10 +57,8 @@ playbooks/
└── test_hitl.yml # Human-in-the-Loop with ansible.builtin.pause
reports/
├── render.go # Go renderer (text/template + external .gohtml)
├── render_report.py # Python renderer (terminal + markdown output)
├── report.gohtml # Go template for terminal box-drawing report
├── go.mod # Go module definition
├── report.gohtml # Go template rendered by gomplate (terminal box-drawing report)
└── sample-output.json # Example output for offline renderer tests
inventory.ini # Ansible inventory — all platform groups defined
run.sh # End-to-end wrapper: ansible → find JSON → render
@@ -85,7 +83,7 @@ run.sh # End-to-end wrapper: ansible → find JSON
▼
run.sh / render manually:
python3 reports/render_report.py reports/<hostname>-<date>.json
go run reports/render.go reports/<hostname>-<date>.json reports/report.gohtml
gomplate --context .=reports/<hostname>-<date>.json --file reports/report.gohtml
```
### Target Integrations
@@ -109,7 +107,7 @@ run.sh # End-to-end wrapper: ansible → find JSON
- Ansible ≥ 2.9 with the collections listed above (pre-installed in the Docker image)
- Python ≥ 3.6 (for the Python report renderer)
- Go ≥ 1.21 (optional, for the Go renderer)
- [gomplate](https://docs.gomplate.ca/installing/) (optional, single static binary, for the `.gohtml` template renderer)
- For Windows / VMware / Cisco targets: the Python libraries listed above
### Step 1: Configure Inventory
@@ -160,8 +158,8 @@ python3 reports/render_report.py reports/localhost-2026-08-14.json
# Markdown (for GitHub / GitLab wikis, PR comments):
python3 reports/render_report.py reports/localhost-2026-08-14.json --format md
# Go template renderer:
cd reports && go run render.go ../reports/localhost-2026-08-14.json report.gohtml
# gomplate template renderer:
gomplate --context .=reports/localhost-2026-08-14.json --file reports/report.gohtml
```
---
@@ -580,29 +578,31 @@ python3 reports/render_report.py reports/hostname-2026-08-14.json --format md >
Terminal output groups results by FR category with a failure-detail section.
Markdown output produces GFM tables plus per-failure sections with remediation.
### Go Renderer (`reports/render.go`)
### gomplate Renderer (`reports/report.gohtml`)
Requires Go >= 1.21. Uses `text/template` with an external `.gohtml` file:
Requires [gomplate](https://docs.gomplate.ca/installing/) (a single static
binary — no Go toolchain, no compilation). Renders a `.gohtml` file against
the JSON report loaded as the template's root context:
```bash
cd reports
go run render.go ../reports/hostname-2026-08-14.json report.gohtml
gomplate --context .=../reports/hostname-2026-08-14.json --file report.gohtml
```
The template file is standalone — customise it without recompiling. Registered
template functions:
The template file is standalone — customise it without recompiling anything.
Fields are accessed with plain dot notation (e.g. `.meta.target`), and the
template only relies on gomplate's built-in functions:
| Function | Purpose |
|---|---|
| `passIcon` | Maps `passed` value to ✅ PASS / ❌ FAIL / ❓ MANUAL |
| `severityIcon` | Maps severity to 🔴/🟠/🟡/🟢 |
| `title` | Capitalises first letter of each word |
| `divf` | Float division for compliance rate percentage |
| `add`, `sub` | Integer arithmetic |
| `passIcon` (in-template) | Maps `passed` value to ✅ PASS / ❌ FAIL / ❓ MANUAL |
| `severityIcon` (in-template) | Maps severity to 🔴/🟠/🟡/🟢 |
| `strings.Title` | Capitalises first letter of each word |
| `math.Div`, `math.Mul` | Compliance rate percentage |
Custom templates:
```bash
go run reports/render.go reports/*.json my-custom.gohtml
gomplate --context .=reports/<hostname>-<date>.json --file my-custom.gohtml
```
---
@@ -702,9 +702,7 @@ QEMU VM boots in ~6 seconds
| `playbooks/templates/test_service_check.yml` | Copy-and-fill template: `service_facts` |
| `playbooks/templates/test_hitl.yml` | Copy-and-fill template: `pause` + `delegate_to: localhost` |
| `reports/render_report.py` | Python renderer: terminal box-drawing and Markdown output |
| `reports/render.go` | Go renderer: `text/template` on external `.gohtml` |
| `reports/report.gohtml` | Go template producing the terminal box-drawing report |
| `reports/go.mod` | Go module (requires `golang.org/x/text`) |
| `reports/report.gohtml` | Go template producing the terminal box-drawing report, rendered by `gomplate` |
| `reports/sample-output.json` | Hand-crafted example report for offline renderer testing |
| `inventory.ini` | Ansible inventory with all platform groups and connection vars |
| `run.sh` | End-to-end wrapper: run ansible → find latest JSON → render |