1 Commits

Author SHA1 Message Date
34f936e21c Capture Server Name column and prioritize for inventory keys
All checks were successful
Build and Release / Build Windows Exe (push) Successful in 10s
2026-02-06 16:11:48 -05:00
2 changed files with 12 additions and 5 deletions

View File

@@ -77,8 +77,8 @@ def read_servers(filename: str) -> Dict[str, Server]:
print("Warning: No 'Servers' sheet found.")
return {}
# keywords: reference, platform, ip address, management ip, production ip
header_keywords = ['reference', 'platform', 'ip address', 'production ip']
# keywords: reference, platform, ip address, management ip, production ip, server name
header_keywords = ['reference', 'platform', 'ip address', 'production ip', 'server name']
header_row_idx, col_map = find_header_row(target_sheet, header_keywords)
@@ -96,6 +96,7 @@ def read_servers(filename: str) -> Dict[str, Server]:
# Extract data
ref_idx = col_map.get('reference')
name_idx = col_map.get('server name') # User confirmed header
plat_idx = col_map.get('platform')
ip_idx = col_map.get('ip address') # Generic/Management IP
prod_ip_idx = col_map.get('production ip') # Specific Production IP
@@ -110,6 +111,12 @@ def read_servers(filename: str) -> Dict[str, Server]:
if not ref or ref.lower() == 'example':
continue
# Hostname Logic:
# 1. Use 'Server Name' column if available (e.g. ITSMDEV-5009898)
# 2. Fallback to cleaned Reference (Stripping SRV###)
server_name_raw = get_val(name_idx)
final_hostname = server_name_raw if server_name_raw else clean_reference(ref)
plat = get_val(plat_idx) or 'unknown'
# Parse Management IP
@@ -130,7 +137,7 @@ def read_servers(filename: str) -> Dict[str, Server]:
s = Server(
reference=ref,
hostname=clean_reference(ref),
hostname=final_hostname,
platform=plat,
ip_address=ip_addr,
production_ip=prod_ip_addr

View File

@@ -61,8 +61,8 @@ def generate_inventory(servers: Dict[str, Server], flows: List[Flow]) -> Dict[st
match_count += 1
# Prepare host entry if new
# We use the Reference/Hostname as the key in inventory 'hosts'
host_key = server.reference or server.hostname or server.ip_address
# We use the Hostname (from Server Name col) -> Reference (cleaned) -> IP match
host_key = server.hostname or server.reference or server.ip_address
if host_key not in inventory_hosts:
host_vars = server.get_ansible_vars()