mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Hard-coded self-path references rot the moment the file moves: a header
comment ``# utils/foo/bar.py`` at the top of a module, a docstring
mentioning ``utils/foo/bar.py``, or a docs entry linking
``utils/foo/bar.py`` from inside ``utils/foo/bar.py`` itself all silently
desync from reality after the next ``git mv``.
The new lint walks every project file, computes its POSIX-style relative
path from PROJECT_ROOT, and reports any line whose text contains that
path as a substring. Files at the repo root (no ``/`` in their relative
path) and setuptools-generated ``*.egg-info/`` artefacts are exempt.
Per-line opt-out via ``# nocheck: self-path-reference`` on the offending
line, registered in the suppression catalog.
Existing offenders cleaned up:
- 72 redundant ``# <self-path>`` header lines removed across roles,
cli, plugins, scripts, tests, and utils.
- 4 prometheus templates that told consumers to "update
<self-template-path>" rewritten to drop the redundant self-reference.
- 8 docstring/comment self-references in cli, plugins, tests, utils,
and the dashboard oidc.js.j2 header rewritten to describe the layout
without naming the file's own path.
- 17 legitimate usage examples (shell scripts, test data lists, one
template self-include doc-block) marked with ``nocheck:
self-path-reference``.
- ``container.sh`` heredoc usage strings switched to ``${0}`` so the
marker stays out of the user-visible help output.
- ``healthcheck/http.yml.j2`` doc-block rewritten to prose because
``{# ... #}`` Jinja comments cannot host an inner ``{# nocheck #}``
(the inner ``#}`` closes the outer comment).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Templating Utilities 🧩
Strict Jinja renderers used by lookup plugins, library modules, and the YAML cache layer.
Scope 📋
Modules in utils/templating/ MUST limit themselves to rendering {{ ... }} and {% ... %} constructs found in YAML values, lookups, and templated config strings.
Both renderers fail loudly when Jinja markers cannot be resolved so generated configs never silently leak unrendered placeholders.
Modules 📦
| Module | Engine | When to use |
|---|---|---|
| ansible.py | Ansible's internal Templar (with TrustedAsTemplate tagging for Ansible 2.19+) |
When the caller already has Ansible's variable stack and wants tag-aware rendering with shortcuts for lookup('env', ...), simple var.path lookups, and literal coercion. |
| jinja.py | Standalone jinja2.Environment |
When the caller runs in a context where Templar can silently leave markers untouched (some lookup plugin entry points). Renders multiple passes so nested vars (A.x = "{{ B.y }}", B.y = "{{ C.z }}") collapse fully. |
Example Imports ✍️
from utils.templating.ansible import render_ansible_strict
from utils.templating.jinja import render_strict