Capture Server Name column and prioritize for inventory keys
All checks were successful
Build and Release / Build Windows Exe (push) Successful in 10s
All checks were successful
Build and Release / Build Windows Exe (push) Successful in 10s
This commit is contained in:
@@ -77,8 +77,8 @@ def read_servers(filename: str) -> Dict[str, Server]:
|
|||||||
print("Warning: No 'Servers' sheet found.")
|
print("Warning: No 'Servers' sheet found.")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# keywords: reference, platform, ip address, management ip, production ip
|
# keywords: reference, platform, ip address, management ip, production ip, server name
|
||||||
header_keywords = ['reference', 'platform', 'ip address', 'production ip']
|
header_keywords = ['reference', 'platform', 'ip address', 'production ip', 'server name']
|
||||||
|
|
||||||
header_row_idx, col_map = find_header_row(target_sheet, header_keywords)
|
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
|
# Extract data
|
||||||
ref_idx = col_map.get('reference')
|
ref_idx = col_map.get('reference')
|
||||||
|
name_idx = col_map.get('server name') # User confirmed header
|
||||||
plat_idx = col_map.get('platform')
|
plat_idx = col_map.get('platform')
|
||||||
ip_idx = col_map.get('ip address') # Generic/Management IP
|
ip_idx = col_map.get('ip address') # Generic/Management IP
|
||||||
prod_ip_idx = col_map.get('production ip') # Specific Production 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':
|
if not ref or ref.lower() == 'example':
|
||||||
continue
|
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'
|
plat = get_val(plat_idx) or 'unknown'
|
||||||
|
|
||||||
# Parse Management IP
|
# Parse Management IP
|
||||||
@@ -130,7 +137,7 @@ def read_servers(filename: str) -> Dict[str, Server]:
|
|||||||
|
|
||||||
s = Server(
|
s = Server(
|
||||||
reference=ref,
|
reference=ref,
|
||||||
hostname=clean_reference(ref),
|
hostname=final_hostname,
|
||||||
platform=plat,
|
platform=plat,
|
||||||
ip_address=ip_addr,
|
ip_address=ip_addr,
|
||||||
production_ip=prod_ip_addr
|
production_ip=prod_ip_addr
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ def generate_inventory(servers: Dict[str, Server], flows: List[Flow]) -> Dict[st
|
|||||||
match_count += 1
|
match_count += 1
|
||||||
|
|
||||||
# Prepare host entry if new
|
# Prepare host entry if new
|
||||||
# We use the Reference/Hostname as the key in inventory 'hosts'
|
# We use the Hostname (from Server Name col) -> Reference (cleaned) -> IP match
|
||||||
host_key = server.reference or server.hostname or server.ip_address
|
host_key = server.hostname or server.reference or server.ip_address
|
||||||
|
|
||||||
if host_key not in inventory_hosts:
|
if host_key not in inventory_hosts:
|
||||||
host_vars = server.get_ansible_vars()
|
host_vars = server.get_ansible_vars()
|
||||||
|
|||||||
Reference in New Issue
Block a user