From c2ac1507ea7b34ed7ce7ea957e3c8c8e6377625a Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 20 Jan 2016 18:31:40 -0500 Subject: [PATCH] corrected host/group match in inventory_hostnames now the lookup works when using ! and & operators fixes #13997 --- lib/ansible/plugins/lookup/inventory_hostnames.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/lookup/inventory_hostnames.py b/lib/ansible/plugins/lookup/inventory_hostnames.py index a86d2270bba..651055b6f74 100644 --- a/lib/ansible/plugins/lookup/inventory_hostnames.py +++ b/lib/ansible/plugins/lookup/inventory_hostnames.py @@ -26,10 +26,15 @@ class LookupModule(LookupBase): def get_hosts(self, variables, pattern): hosts = [] - if pattern in variables['groups']: - hosts = variables['groups'][pattern] - elif pattern in variables['groups']['all']: - hosts = [pattern] + if pattern[0] in ('!','&'): + obj = pattern[1:] + else: + obj = pattern + + if obj in variables['groups']: + hosts = variables['groups'][obj] + elif obj in variables['groups']['all']: + hosts = [obj] return hosts def run(self, terms, variables=None, **kwargs):