Skip to content

Add ability to template device name #1347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/1346-template-any-field-host.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Add the ability to use any field to generate the host name in inventory
6 changes: 5 additions & 1 deletion plugins/inventory/nb_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,8 +1775,12 @@ def extract_name(self, host):
# Use virtual chassis name if set by the user.
if self.virtual_chassis_name and self._get_host_virtual_chassis_master(host):
return host["virtual_chassis"]["name"] or str(uuid.uuid4())
elif self.hostname_field:
elif self.hostname_field and self.hostname_field in host["custom_fields"]:
return host["custom_fields"][self.hostname_field]
elif self.hostname_field and (
self.hostname_field in host or "." in self.hostname_field
):
return self._compose(self.hostname_field, host) or str(uuid.uuid4())
else:
return host["name"] or str(uuid.uuid4())

Expand Down
Loading