Loading...
Loading...
Creates, modifies and debugs Infrahub transforms that convert data into JSON, text, CSV, or device configs using Python or Jinja2 templates, with YAML-driven tests. TRIGGER when: building config generation, data export, format conversion, Jinja2 templates, artifact pipelines, writing or running tests for a transform, modifying or extending an existing transform or template, debugging why a transform renders the wrong output or an artifact fails to generate. DO NOT TRIGGER when: designing schemas, writing validation checks, creating generators, querying live data.
npx skill4agent add opsmill/infrahub-skills infrahub-managing-transformscat .infrahub.yml 2>/dev/null || echo "No .infrahub.yml found"find . -name "*.py" -path "*/transforms/*" -o -name "*.j2" -path "*/templates/*" 2>/dev/null | head -20| Priority | Category | Prefix | Description |
|---|---|---|---|
| CRITICAL | Types | | Python vs Jinja2 choice |
| CRITICAL | Python | | InfrahubTransform class |
| CRITICAL | Jinja2 | | Template syntax, filters |
| HIGH | Hybrid | | Python + Jinja2 combined |
| HIGH | Artifacts | | Output files, targets |
| HIGH | API Ref | | Class attrs, methods |
| MEDIUM | Patterns | | Utilities, CSV, shared |
| HIGH | Testing | | Resources Testing Framework, transform/render commands |
| If the transform... | The schema (or .infrahub.yml) must... | See |
|---|---|---|
Will feed an | The target node must | ../infrahub-managing-schemas/rules/extension-artifact-target.md |
| Reads attributes from a node | Define those attributes with their full | ../infrahub-managing-schemas/rules/attribute-defaults-and-types.md |
| Picks a template per device by platform/role | The schema must expose that platform/role as a real attribute or relationship — string-matching on | ../infrahub-managing-schemas/rules/display-human-friendly-id.md |
Is referenced from | The transform's registered | rules/artifacts-definitions.md |
| Uses Jinja2 (not Python) | Register under | rules/api-reference.md |
| Is a Python transform | Carry a | rules/artifacts-watch-dependencies.md |
| Reads a data file at runtime, or includes a template by variable name | Name those paths in | rules/artifacts-watch-dependencies.md |
| Has its artifacts regenerated by a caller (catalog page, CI job, orchestrator) | That caller must poll | rules/artifacts-async-regen-polling.md |
jinja2_transforms.infrahub.ymlpython_transformsInfrahubTransform| Signal | Cheaper layer | See rule |
|---|---|---|
Transform body is | Jinja2 template file | yagni-python-transform-that-could-be-jinja2 |
| Transform copies query data verbatim without computation | The GraphQL query alone — no transform needed | Ladder step 1 (drop the requirement); judgment call, no rule |
Conditionals are | Jinja2 | yagni-python-transform-that-could-be-jinja2 |
client.filters(NetworkLink, ...)kind="NetworkLink"create()| Type | Output | Entry Point |
|---|---|---|
| Python | Whatever the artifact's | |
| Jinja2 | Text | |
from infrahub_sdk.transforms import InfrahubTransform
class MyTransform(InfrahubTransform):
query = "my_query"
# Returns a dict, so the artifact definition has to declare
# content_type: application/json (or application/yaml). Under any
# other content type this dict is stored as str(dict), with no
# error. See rules/artifacts-definitions.md.
async def transform(self, data: dict) -> dict:
device = data["DcimDevice"]["edges"][0]["node"]
return {"hostname": device["name"]["value"]}.gqlInfrahubTransformtransform().j2python_transformsjinja2_transformswatch.filesfiles: []watchinfrahubctl transforminfrahubctl rendercontent_type.infrahub.ymldocs.infrahub.app