/infrahub:infrahub-managing-generators [generator-name] [description...]from infrahub
Creates, modifies, and debugs Infrahub Generators — design-driven automation that builds infrastructure objects from templates and topology definitions. Covers generator architecture, idempotent create-or-update workflows, and debugging wrong or missing objects.
Ships in infrahub. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Expert guidance for creating Infrahub Generators. Generators query data from Infrahub via GraphQL and create new nodes and relationships based on the result -- enabling design-driven automation where a "design" object automatically creates downstream infrastructure.
Before writing a generator, look at the project with read-only tools:
.infrahub.yml if it exists..py files under a
generators/ directory..gql files
under a generators/ directory.These steps contact the Infrahub server, so they come after the read-only look at the project:
infrahubctl command, detect the
project's Python environment as
../infrahub-common/rules/connectivity-python-environment.md
describes..gql
file, dry-run the query against the live schema on a
branch as
../infrahub-common/rules/deployment-gql-dry-run.md
describes..py or .gql file under generators/, even when the
request does not mention generators| Priority | Category | Prefix | Description |
|---|---|---|---|
| CRITICAL | Architecture | architecture- | Components, groups |
| CRITICAL | Python Class | python- | Generator, generate() |
| HIGH | Tracking | tracking- | Upsert, idempotent |
| HIGH | API Ref | api- | Constructor, props |
| HIGH | Registration | registration- | .infrahub.yml config |
| MEDIUM | Patterns | patterns- | Cleaning, batch, store |
| LOW | Testing | testing- | infrahubctl commands |
Generators create real objects, so the schema must permit the shape they emit. Catch these gaps before the first run — re-running a buggy generator can delete data via the tracking cleanup.
| If the generator... | The schema must... | See |
|---|---|---|
| Creates objects of kind X | Have node X defined with the attributes the generator sets — a field the kind does not have is dropped before the request is sent, with no error; missing required ones abort the create | ../infrahub-managing-schemas/rules/attribute-defaults-and-types.md |
| Links the created object to a parent | Have a Component/Parent relationship pair with matching identifiers and optional: false on the Parent side | ../infrahub-managing-schemas/rules/relationship-component-parent.md |
| Reads a "design" node to drive output | Define that node's human_friendly_id so the generator's tracking key stays stable across runs | ../infrahub-managing-schemas/rules/display-human-friendly-id.md |
| Is triggered by membership in a group | Target the group the design objects are already in, of any kind; create a CoreStandardGroup only when none exists. CoreGeneratorGroup is the generator's own output group | rules/registration-config.md |
| Should be idempotent on re-run | Every save() uses allow_upsert=True; the run's tracking context deletes objects from prior runs that aren't recreated | rules/tracking-idempotent.md |
| Imports anything from the repository (a shared package, generated protocols, its own query model) | Carry a watch: block in .infrahub.yml naming every one of those paths — imports are never followed, so an undeclared helper means the Generator silently stops re-running when that helper changes | rules/registration-watch-dependencies.md |
| Adding several peers to a cardinality-many relationship | .extend() for a list, or a per-peer .add() loop — never .add() with a list | rules/python-multi-peer-add.md |
| Adding peers to a relationship several runs can write at once | node.add_relationships(relation_to_update=..., related_nodes=[ids]) | rules/python-concurrent-relationship-writes.md |
| Deleting objects a generator previously created | Detach the relationships pointing at them before deleting the peers, and save the holder in between — a save(allow_upsert=True) after the delete re-sends the ids from the in-memory manager | rules/python-delete-ordering.md |
| Modifying a generator so it produces a different set of objects than last run | Audit every save() reachable from generate(), helpers included | rules/tracking-idempotent.md |
A generator should compute objects from a design. If
what you're about to write is "make these N specific
objects from a hardcoded list," that list is data —
move it to objects/ and either let the object
loader handle it directly or pass it into a smaller
generator. Walk this ladder before reaching for
InfrahubGenerator:
| Signal | Cheaper layer | See rule |
|---|---|---|
| Generator hardcodes object lists, role catalogs, or status sets | YAML data files under objects/ (loaded by the object loader) | yagni-generator-hardcoding-data |
| Generator recreates a built-in IPAM/VLAN primitive (custom IP address, prefix, VLAN nodes) | inherit_from: [BuiltinIPAddress / BuiltinIPPrefix / IpamVLAN] in the schema, then the generator computes references rather than reimplementing the primitive | yagni-custom-domain-primitives-instead-of-builtin |
Generator's output shape duplicates objects already in opsmill/schema-library | inherit_from a library generic; the generator computes the instance but not the shape | yagni-duplicate-shape-not-extracted-to-generic |
Generator allocates a subnet/IP/VLAN/port with ipaddress math, random, or a hand-written "find the first free one" loop | A built-in resource pool — allocate_next_ip_prefix / allocate_next_ip_address, CoreIPPrefixPool / CoreNumberPool — which tracks utilization and stays idempotent across re-runs | yagni-imperative-allocation-vs-resource-pool |
generate() stamps a fixed set of children with constant values and no computation (no branching, derived naming, or allocation) | An Object Template (generate_template: true) users clone — the structure lives in data, not Python | yagni-generator-that-should-be-template |
Bootstrap, seed, and demo generators (under
bootstrap/, seed/, demo/) are exempt — they
exist specifically to hardcode initial state. Use
Python when the generator is genuinely computing
objects from a design definition; see
rules/python-generate.md
for the legitimate cases.
Once you are writing Python, type your SDK calls with generated protocol
classes rather than string kinds — client.create(NetworkDevice, ...), not
kind="NetworkDevice" — so a schema change breaks attribute reads on the
returned object at type-check time. Field names passed to create() are not
type-checked. See
protocols-adopt-typed-kinds.
Every generator has three components:
.gql file) -- fetches the design dataInfrahubGenerator,
implements generate()from infrahub_sdk.generator import InfrahubGenerator
class MyGenerator(InfrahubGenerator):
async def generate(self, data: dict) -> None:
obj = await self.client.create(
kind="DcimDevice",
data={"name": "spine-01"},
)
await obj.save(allow_upsert=True)
Follow these steps when creating a generator:
.gql file
that fetches the design data. Read
../infrahub-common/graphql-queries.md
for query patterns. If the repository keeps a
schema.graphql, that file is generated — re-export
it instead of editing it when a field is missing.
Read
../infrahub-common/rules/protocols-generated.md.InfrahubGenerator, implement generate(). Read
rules/python-generate.md
for the class pattern and
rules/api-reference.md
for available methods.allow_upsert=True so
re-running creates or updates without duplicates.
See rules/tracking-idempotent.md.from_graphql adoption opportunity — if
generate() iterates response edges and calls
self.client.get() to re-fetch typed peers, consider
refactoring to InfrahubNode.from_graphql() to collapse
O(N + 1) round trips to O(1). Read
rules/patterns-hydration.md
for the decision tree, detection heuristic, and refactor
recipe.generate() needs
the routes between two nodes, use the SDK's
traverse_paths rather than a hand-written per-hop
walk, and constrain it by relationship identifier plus
a depth bound. Kind filtering restricts which nodes
may appear, not which edges are followed, so a shared
reference object still bridges unrelated subgraphs and
the walk returns structurally valid nonsense. Read
rules/patterns-path-traversal.md
for the parameter semantics and the truncation signal.generator_definitions with the target group. See
rules/registration-config.md.
Then declare the Generator's dependencies with
watch.files: read its imports and runtime file reads,
and name every first-party path they resolve to —
sibling query models included. Always carry the key;
files: [] when the Generator genuinely has no
dependency beyond its own file. Read
rules/registration-watch-dependencies.md,
which also covers reviewing an existing watch block
for entries that are missing, stale, or wrong.infrahubctl generator to validate.
See rules/testing-commands.md..infrahub.yml
registration (with the query:-required shape that
differs from check_definitions)docs.infrahub.app
on a genuine gap (e.g. deleting nodes)examples.md (opens in a new tab)reference.md (opens in a new tab)rules/_sections.md (opens in a new tab)rules/_template.md (opens in a new tab)rules/api-reference.md (opens in a new tab)rules/architecture-components.md (opens in a new tab)rules/patterns-common.md (opens in a new tab)rules/patterns-hydration.md (opens in a new tab)rules/patterns-natural-key-preflight.md (opens in a new tab)rules/patterns-path-traversal.md (opens in a new tab)rules/python-concurrent-relationship-writes.md (opens in a new tab)rules/python-delete-ordering.md (opens in a new tab)rules/python-generate.md (opens in a new tab)rules/python-multi-peer-add.md (opens in a new tab)rules/python-relationship-references.md (opens in a new tab)rules/registration-config.md (opens in a new tab)rules/registration-watch-dependencies.md (opens in a new tab)rules/testing-commands.md (opens in a new tab)rules/testing-integration.md (opens in a new tab)rules/tracking-idempotent.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
infrahub@opsmill is listed by opsmill/claude-marketplace — review the source before installing
npx claudepluginhub opsmill/claude-marketplace --plugin infrahub18 skills in this plugin
/infrahub-analyzing-dataAnalyzes and correlates live Infrahub data via the MCP server — answers operational questions, detects drift, and investigates impact. TRIGGER when: querying infrastructure data, checking compliance, investigating change impact, producing ad-hoc reports. DO NOT TRIGGER when: writing automated checks, building transforms, designing schemas, populating data files, planning an Infrahub version upgrade (use infrahub-planning-upgrades). ALWAYS pass the user's question verbatim as args — this skill runs in a forked context and cannot see the parent conversation. Invoking without args will fail./infrahub-analyzing-diagnosticsAnalyze an already-collected infrahub-collect diagnostic bundle — traceback and failure triage across service logs, incident correlation, and known-issue matching against opsmill/infrahub GitHub issues. TRIGGER when: the user says they collected a diagnostic bundle, gives you a bundle path, or pastes bundle contents — and asks what's wrong, wants the logs or tracebacks analyzed, asks "what does this bundle say", wants errors triaged/correlated, or asks whether a crash is a known issue. DO NOT TRIGGER when: no bundle exists yet — collect one first (use infrahub-collecting-diagnostics), filing the issue itself (use infrahub-reporting-issues), or querying live data (use infrahub-analyzing-data)./infrahub-auditing-repoAudits an Infrahub repository against best practices and rules, producing a structured compliance report. TRIGGER when: reviewing repo for compliance, onboarding to existing project, pre-deployment validation, catching issues. DO NOT TRIGGER when: creating schemas, writing checks/generators, querying live data, populating objects, planning an Infrahub version upgrade (use infrahub-planning-upgrades). ALWAYS pass the user's request verbatim as args, with any scope, path, or focus they named. This skill runs in a forked context and cannot see the parent conversation./infrahub-collecting-diagnosticsCollect a redacted local diagnostic bundle (logs, config, version, state) for an OpsMill expert hand-off. TRIGGER when: Infrahub is broken/failing/erroring, the user asks for help debugging, wants to collect logs/diagnostics, prepares a hand-off for OpsMill support, or reports a crash/timeout/connection issue (upgrade failure, stuck branch, container CrashLoopBackOff, 500s, OOM). DO NOT TRIGGER when: debugging a check, transform, generator, menu, or schema in the repository (use the infrahub-managing-* skills), a bundle has already been collected and the user wants it analyzed (use infrahub-analyzing-diagnostics), filing a public GitHub issue (use infrahub-reporting-issues), running operational queries (use infrahub-analyzing-data), or planning an upgrade that has not run yet (use infrahub-planning-upgrades)./infrahub-commonShared references and cross-cutting rules for all Infrahub skills — GraphQL syntax, .infrahub.yml format, and common patterns. DO NOT TRIGGER directly — loaded automatically by other Infrahub skills when they need shared references./infrahub-converting-netbox-device-typesConverts NetBox device-type and module-type definitions (the netbox-community devicetype-library format, also published via the NetBox Data Exchange / NDX) into Infrahub object templates as Infrahub object YAML, using a bundled Python converter driven by a schema mapping profile. TRIGGER when: importing NetBox device types or module types, exporting device types from a running NetBox instance, building object templates from vendor device models, converting line cards / PSUs / transceivers from NetBox module types into Template* objects, re-running a conversion after changing the mapping profile, debugging a wrong or failed conversion. DO NOT TRIGGER when: importing CSV/TSV data (use infrahub-importing-data), authoring schemas from scratch (use infrahub-managing-schemas), writing ordinary object data files (use infrahub-managing-objects), or setting up continuous two-way replication with a live NetBox (that is infrahub-sync, a separate product; a one-off export of device types is in scope here).Other plugins' skills for the same job