Skip to content

Commit d43c5ab

Browse files
committed
Add ability to template device name
1 parent b712398 commit d43c5ab

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- Add the ability to use any field to generate the host name in inventory

plugins/inventory/nb_inventory.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,12 @@ def extract_name(self, host):
17751775
# Use virtual chassis name if set by the user.
17761776
if self.virtual_chassis_name and self._get_host_virtual_chassis_master(host):
17771777
return host["virtual_chassis"]["name"] or str(uuid.uuid4())
1778-
elif self.hostname_field:
1778+
elif self.hostname_field and self.hostname_field in host["custom_fields"]:
17791779
return host["custom_fields"][self.hostname_field]
1780+
elif self.hostname_field and (
1781+
self.hostname_field in host or "." in self.hostname_field
1782+
):
1783+
return self._compose(self.hostname_field, host) or str(uuid.uuid4())
17801784
else:
17811785
return host["name"] or str(uuid.uuid4())
17821786

0 commit comments

Comments
 (0)