From b91d4d884d14101bc526ced4457bd02c1bd78ef6 Mon Sep 17 00:00:00 2001 From: jamessewell Date: Sat, 19 Nov 2016 06:27:17 +1100 Subject: [PATCH] =?UTF-8?q?Moved=20the=20=5Finventory.clear=5Fgroup=5Fdict?= =?UTF-8?q?=5Fcache()=20from=20creating=20a=20group=20w=E2=80=A6=20(#17766?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Moved the _inventory.clear_group_dict_cache() from creating a group which doesn't exist, to adding members to the group. * Update __init__.py Update to use changed: block to catch all changes for cache clear as suggested --- lib/ansible/plugins/strategy/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 38917c8b58..7ff1491d75 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -624,9 +624,6 @@ class StrategyBase: group_name = result_item.get('add_group') new_group = self._inventory.get_group(group_name) if not new_group: - # clear cache of group dict, which is used in magic host variables - self._inventory.clear_group_dict_cache() - # create the new group and add it to inventory new_group = Group(name=group_name) self._inventory.add_group(new_group) @@ -640,6 +637,10 @@ class StrategyBase: if group_name not in host.get_groups(): new_group.add_host(real_host) changed = True + + if changed: + # clear cache of group dict, which is used in magic host variables + self._inventory.clear_group_dict_cache() return changed