switch available_hosts to `frozenset` from `list` in ansible-inventory (#81870)

* major speedup large inventories, since it's consulted iteratively
pull/81882/head
Matt Davis 8 months ago committed by GitHub
parent debf2be913
commit c1343cc304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-inventory - index available_hosts for major performance boost when dumping large inventories

@ -325,7 +325,7 @@ class InventoryCLI(CLI):
return results
hosts = self.inventory.get_hosts(top.name)
results = format_group(top, [h.name for h in hosts])
results = format_group(top, frozenset(h.name for h in hosts))
# populate meta
results['_meta'] = {'hostvars': {}}
@ -381,7 +381,7 @@ class InventoryCLI(CLI):
return results
available_hosts = [h.name for h in self.inventory.get_hosts(top.name)]
available_hosts = frozenset(h.name for h in self.inventory.get_hosts(top.name))
return format_group(top, available_hosts)
def toml_inventory(self, top):
@ -425,7 +425,7 @@ class InventoryCLI(CLI):
return results
available_hosts = [h.name for h in self.inventory.get_hosts(top.name)]
available_hosts = frozenset(h.name for h in self.inventory.get_hosts(top.name))
results = format_group(top, available_hosts)
return results

Loading…
Cancel
Save