Skip to content

Feature/tenant data - #1537

Open
J0kerul wants to merge 5 commits into
netbox-community:develfrom
J0kerul:feature/tenant-data
Open

J0kerul wants to merge 5 commits into
netbox-community:develfrom
J0kerul:feature/tenant-data

Conversation

@J0kerul

@J0kerul J0kerul commented Mar 26, 2026

Copy link
Copy Markdown

Related Issue

New Behavior

When tenant_data: true is set in the inventory configuration, the full tenant data structure from the NetBox API is included in host vars (id, name, slug, description, group, custom_fields, tags, etc.).

When tenant_data: false (default), only the tenant slug string is included — preserving current behavior.

Contrast to Current Behavior

Currently, tenant host vars always contain only the slug string (e.g. "acme-corp"), regardless of configuration. There is no way to get the full tenant object in host vars.

The site_data option already provides this toggle for sites. This PR adds the equivalent for tenants.

Discussion: Benefits and Drawbacks

  • Benefit: Users managing multi-tenant environments can access full tenant details (group, description, custom fields) directly in playbooks without additional API lookups.
  • Benefit: Follows the established pattern of site_data, so the implementation is consistent and predictable.
  • Backwards-compatible: Yes. Default is false, so existing behavior is unchanged.
  • Drawback: None significant. Slightly larger host vars when enabled.

Changes to the Documentation

Plugin DOCUMENTATION string updated with the new tenant_data option definition.

Proposed Release Note Entry

nb_inventory - Add tenant_data option to include full tenant data structures in host vars, mirroring site_data behavior.

Double Check

  • I have read the comments and followed the CONTRIBUTING.md.
  • I have explained my PR according to the information in the comments or in a linked issue.
  • My PR targets the devel branch.

J0kerul added 5 commits March 26, 2026 11:23
Adds a new tenant_data boolean option (default: false) that controls
whether the full tenant data structure from the NetBox API is included
in host vars, or just the slug string.

This mirrors the existing site_data option behavior:
- When false: host var 'tenant' contains only the slug
- When true: host var 'tenant' contains the full API response

Changes:
- Added tenant_data option to DOCUMENTATION
- Extended refresh_tenants_lookup() with tenants_lookup_slug
- Added _add_tenant_groups() method for group creation
- Excluded tenant from generic grouping loop in add_host_to_groups()
- Added tenant group assignment in main()
Adds a new tenant_data boolean option (default: false) that includes
full tenant data structures from the NetBox API in host vars,
mirroring the existing site_data option.

Changes:
- Added tenant_data option to DOCUMENTATION
- Extended refresh_tenants_lookup() with tenants_lookup_slug
- Added _add_tenant_groups() method for group creation
- Excluded tenant from generic grouping loop in add_host_to_groups()
- Added tenant group assignment in main()
- Added option reading in parse()

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant