From 67c83823f2f3f5380e65ee7cc04cb646cf577000 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 14 Dec 2017 12:53:00 -0500 Subject: [PATCH] Add q/query aliases to lookup (#33466) * Add L alias to lookup, defaults to real list * renamed to q/query as per core meeting * also force wantlist=true --- lib/ansible/template/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 1aa3a674fb..79756dd242 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -603,6 +603,11 @@ class Templar: def _fail_lookup(self, name, *args, **kwargs): raise AnsibleError("The lookup `%s` was found, however lookups were disabled from templating" % name) + def _query_lookup(self, name, *args, **kwargs): + ''' wrapper for lookup, force wantlist true''' + kwargs['wantlist'] = True + return self._lookup(name, *args, **kwargs) + def _lookup(self, name, *args, **kwargs): instance = self._lookup_loader.get(name.lower(), loader=self._loader, templar=self) @@ -685,9 +690,10 @@ class Templar: return data if disable_lookups: - t.globals['lookup'] = self._fail_lookup + t.globals['query'] = t.globals['q'] = t.globals['lookup'] = self._fail_lookup else: t.globals['lookup'] = self._lookup + t.globals['query'] = t.globals['q'] = self._query_lookup t.globals['finalize'] = self._finalize