From cf289191e58ad9ef4e547bbd55405394fe02f779 Mon Sep 17 00:00:00 2001 From: Alex Lee Date: Thu, 17 Sep 2015 15:58:10 -0700 Subject: [PATCH] return None if group does not exist in inventory groups --- lib/ansible/inventory/__init__.py | 5 ++++- lib/ansible/plugins/strategy/__init__.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 99e6729b899..42c8e67a4c0 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -457,7 +457,10 @@ class Inventory(object): return matching_host def get_group(self, groupname): - return self.groups[groupname] + if groupname in self.groups: + return self.groups[groupname] + else: + return None def get_group_variables(self, groupname, update_cached=False, vault_password=None): if groupname not in self._vars_per_group or update_cached: diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index d6bd92203cb..df2e500d940 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -356,10 +356,10 @@ class StrategyBase: new_group.add_host(new_host) # add this host to the group cache - if self._inventory._groups_list is not None: - if group_name in self._inventory._groups_list: - if new_host.name not in self._inventory._groups_list[group_name]: - self._inventory._groups_list[group_name].append(new_host.name) + if self._inventory.groups is not None: + if group_name in self._inventory.groups: + if new_host not in self._inventory.get_group(group_name).hosts: + self._inventory.get_group(group_name).hosts.append(new_host.name) # clear pattern caching completely since it's unpredictable what # patterns may have referenced the group