Join inventory with ownership records
Enrich an inventory using an exact host join without dropping unowned systems.
Put the right person beside the right system
An ownership report helps turn an observation into a follow-up task. Use an exact normalized host key to join a server export to an ownership export. A prefix search can confuse srv-01 with srv-010, sending a finding to the wrong team.
Build a dictionary from the ownership records once. Reject duplicate normalized hosts before processing the inventory, including duplicates whose spelling differs only in case or surrounding whitespace. Quietly keeping the last owner would make the result depend on file order.
Preserve missing ownership
Keep every inventory row, even when no owner matches. Use None for an unknown or whitespace-only owner. Unknown is a request for review, not permission to omit a system from capacity or maintenance reporting.
Copy each inventory dictionary and add the owner field rather than changing the original records. This leaves other calculations free to reuse the input. Normalize the returned host, but preserve the other inventory fields and the original order.
The supplied records describe fictional systems and teams. This is a data join, not an account lookup or an invitation to contact anyone automatically. In a real workflow an owner report should also identify the export date so readers know how current the contact information is.
owners = {"srv-01": "Platform team"}
print(owners.get(" SRV-01 ".strip().casefold()))
print(owners.get("srv-010"))
Put it into practice.
Define join_owners(servers, owners). Ownership rows contain host and owner strings. Index hosts with strip().casefold(); duplicate normalized hosts raise ValueError. Return new server dictionaries in input order with normalized host and owner (stripped text, or None for missing/blank ownership). Preserve all other fields and both original inputs. Match complete host keys.
See an explained solution
def join_owners(servers, owners):
index = {}
for record in owners:
host = record["host"].strip().casefold()
if host in index:
raise ValueError("Duplicate ownership host")
index[host] = record["owner"].strip() or None
return [{**server, "host": server["host"].strip().casefold(), "owner": index.get(server["host"].strip().casefold())} for server in servers]
if __name__ == "__main__":
print(join_owners([{"host":"srv-01"}, {"host":"srv-02"}], [{"host":"srv-01", "owner":"Platform"}]))
An exact indexed join is efficient and keeps unknown systems visible. Duplicate detection protects the report from an accidental last-record-wins policy.