Skip to content

Commit 5d6389d

Browse files
committed
Add ability to template device name
1 parent 0e4a6b8 commit 5d6389d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 5 additions & 1 deletion
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)