diff --git a/lib/ansible/inventory/data.py b/lib/ansible/inventory/data.py index c87d9385642..84966ab2bd8 100644 --- a/lib/ansible/inventory/data.py +++ b/lib/ansible/inventory/data.py @@ -41,7 +41,6 @@ class InventoryData(object): def __init__(self): - # the inventory object holds a list of groups self.groups = {} self.hosts = {} diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 08f57701ea3..5606b2655ee 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -104,7 +104,9 @@ def split_host_pattern(pattern): """ if isinstance(pattern, list): - return list(itertools.chain(*map(split_host_pattern, pattern))) + results = (split_host_pattern(p) for p in pattern) + # flatten the results + return list(itertools.chain.from_iterable(results)) elif not isinstance(pattern, string_types): pattern = to_text(pattern, errors='surrogate_or_strict') @@ -580,7 +582,7 @@ class InventoryManager(object): def list_hosts(self, pattern="all"): """ return a list of hostnames for a pattern """ # FIXME: cache? - result = [h for h in self.get_hosts(pattern)] + result = self.get_hosts(pattern) # allow implicit localhost if pattern matches and no other results if len(result) == 0 and pattern in C.LOCALHOST: @@ -590,7 +592,7 @@ class InventoryManager(object): def list_groups(self): # FIXME: cache? - return sorted(self._inventory.groups.keys(), key=lambda x: x) + return sorted(self._inventory.groups.keys()) def restrict_to_hosts(self, restriction): """