From 279e5e45227f8d0354d24ea954584b6839ce2814 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 7 May 2012 18:09:57 -0400 Subject: [PATCH 1/2] fix the get_hosts() error in get_groups returning a dict not a list of group objects --- lib/ansible/inventory.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ansible/inventory.py b/lib/ansible/inventory.py index 21e11a1b47..6fb96d7931 100644 --- a/lib/ansible/inventory.py +++ b/lib/ansible/inventory.py @@ -73,14 +73,14 @@ class Inventory(object): hosts = {} patterns = pattern.replace(";",":").split(":") - for group in self.get_groups(): - for host in group.get_hosts(): - for pat in patterns: - if group.name == pat or pat == 'all' or self._match(host.name, pat): - if not self._restriction: - hosts[host.name] = host - if self._restriction and host.name in self._restriction: - hosts[host.name] = host + for (groupname, group) in self.get_groups().items(): + for host in group.get_hosts(): + for pat in patterns: + if group.name == pat or pat == 'all' or self._match(host.name, pat): + if not self._restriction: + hosts[host.name] = host + if self._restriction and host.name in self._restriction: + hosts[host.name] = host return sorted(hosts.values(), key=lambda x: x.name) def get_groups(self): From cd28d82639a394d7473bec6e39c83a5bf082e02a Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 7 May 2012 18:10:52 -0400 Subject: [PATCH 2/2] fix indentation --- lib/ansible/inventory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory.py b/lib/ansible/inventory.py index 6fb96d7931..b707b1596f 100644 --- a/lib/ansible/inventory.py +++ b/lib/ansible/inventory.py @@ -88,8 +88,8 @@ class Inventory(object): def get_host(self, hostname): for group in self.groups: - for host in group.get_hosts(): - if hostname == host.name: + for host in group.get_hosts(): + if hostname == host.name: return host return None