diff --git a/changelogs/fragments/inv_available_hosts_to_frozenset.yml b/changelogs/fragments/inv_available_hosts_to_frozenset.yml new file mode 100644 index 00000000000..094fe6ddd54 --- /dev/null +++ b/changelogs/fragments/inv_available_hosts_to_frozenset.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-inventory - index available_hosts for major performance boost when dumping large inventories \ No newline at end of file diff --git a/lib/ansible/cli/inventory.py b/lib/ansible/cli/inventory.py index 448214cee43..3550079bf8e 100755 --- a/lib/ansible/cli/inventory.py +++ b/lib/ansible/cli/inventory.py @@ -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