listify lookup plugin terms when they're specified as "{{ lookup(terms) }}"
Before this, they were not listified there but they were listified when specified like this: with_lookup: terms
This commit is contained in:
parent
e32d887609
commit
d35b956900
23 changed files with 16 additions and 50 deletions
|
@ -153,7 +153,6 @@ class TaskExecutor:
|
|||
items = None
|
||||
if self._task.loop:
|
||||
if self._task.loop in self._shared_loader_obj.lookup_loader:
|
||||
loop_terms = listify_lookup_plugin_terms(terms=self._task.loop_args, templar=templar, loader=self._loader, fail_on_undefined=True)
|
||||
items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=vars_copy)
|
||||
else:
|
||||
raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop)
|
||||
|
|
|
@ -29,7 +29,13 @@ class LookupModule(LookupBase):
|
|||
[1, 2, 3], [a, b] -> [1, a], [1, b], [2, a], [2, b], [3, a], [3, b]
|
||||
"""
|
||||
|
||||
def __lookup_variables(self, terms):
|
||||
def _lookup_variables(self, terms):
|
||||
"""
|
||||
Turn this:
|
||||
terms == ["1,2,3", "a,b"]
|
||||
into this:
|
||||
terms == [[1,2,3], [a, b]]
|
||||
"""
|
||||
results = []
|
||||
for x in terms:
|
||||
intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader)
|
||||
|
@ -38,7 +44,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
terms = self.__lookup_variables(terms)
|
||||
terms = self._lookup_variables(terms)
|
||||
|
||||
my_list = terms[:]
|
||||
if len(my_list) == 0:
|
||||
|
|
|
@ -35,9 +35,6 @@ class LookupModule(LookupBase):
|
|||
if not CREDSTASH_INSTALLED:
|
||||
raise AnsibleError('The credstash lookup plugin requires credstash to be installed.')
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [terms]
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
try:
|
||||
|
|
|
@ -42,9 +42,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
basedir = self.get_basedir(variables)
|
||||
|
||||
ret = []
|
||||
|
|
|
@ -44,9 +44,6 @@ class LookupModule(LookupBase):
|
|||
if HAVE_DNS == False:
|
||||
raise AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed")
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
domain = term.split()[0]
|
||||
|
|
|
@ -25,9 +25,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
var = term.split()[0]
|
||||
|
|
|
@ -66,9 +66,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
validate_certs = kwargs.get('validate_certs', True)
|
||||
|
||||
etcd = Etcd(validate_certs=validate_certs)
|
||||
|
|
|
@ -27,9 +27,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
if not isinstance(terms, list):
|
||||
terms = [ terms ]
|
||||
|
||||
ret = []
|
||||
|
||||
basedir = self.get_basedir(variables)
|
||||
|
|
|
@ -63,6 +63,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
### FIXME: Is this needed now that listify is run on all lookup plugin terms?
|
||||
if not isinstance(terms, list):
|
||||
raise AnsibleError("with_flattened expects a list")
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
### FIXME: Is this needed now that listify is run on all lookup plugin terms?
|
||||
if not isinstance(terms, list):
|
||||
raise AnsibleError("with_indexed_items expects a list")
|
||||
|
||||
|
|
|
@ -53,9 +53,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
basedir = self.get_basedir(variables)
|
||||
self.basedir = basedir
|
||||
self.cp = ConfigParser.ConfigParser()
|
||||
|
|
|
@ -25,6 +25,7 @@ from ansible.plugins.lookup import LookupBase
|
|||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
### FIXME: Is this needed now that listify is run on all lookup plugin terms?
|
||||
if not isinstance(terms, list):
|
||||
raise AnsibleError("with_inventory_hostnames expects a list")
|
||||
|
||||
|
|
|
@ -23,8 +23,5 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, **kwargs):
|
||||
|
||||
if not isinstance(terms, list):
|
||||
terms = [ terms ]
|
||||
|
||||
return self._flatten(terms)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ from ansible.utils.listify import listify_lookup_plugin_terms
|
|||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def __lookup_variables(self, terms, variables):
|
||||
def _lookup_variables(self, terms, variables):
|
||||
foo = variables.copy()
|
||||
foo.pop('vars')
|
||||
results = []
|
||||
|
@ -39,7 +39,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
terms = self.__lookup_variables(terms, variables)
|
||||
terms = self._lookup_variables(terms, variables)
|
||||
|
||||
my_list = terms[:]
|
||||
my_list.reverse()
|
||||
|
|
|
@ -59,9 +59,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
ret = []
|
||||
|
||||
if not isinstance(terms, list):
|
||||
terms = [ terms ]
|
||||
|
||||
for term in terms:
|
||||
# you can't have escaped spaces in yor pathname
|
||||
params = term.split()
|
||||
|
|
|
@ -26,9 +26,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
'''
|
||||
|
|
|
@ -43,9 +43,6 @@ class LookupModule(LookupBase):
|
|||
if not HAVE_REDIS:
|
||||
raise AnsibleError("Can't LOOKUP(redis_kv): module redis is not installed")
|
||||
|
||||
if not isinstance(terms, list):
|
||||
terms = [ terms ]
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
(url,key) = term.split(',')
|
||||
|
|
|
@ -184,9 +184,6 @@ class LookupModule(LookupBase):
|
|||
def run(self, terms, variables, **kwargs):
|
||||
results = []
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
for term in terms:
|
||||
try:
|
||||
self.reset() # clear out things for this iteration
|
||||
|
|
|
@ -34,7 +34,6 @@ class LookupModule(LookupBase):
|
|||
"subelements lookup expects a list of two or three items, "
|
||||
+ msg)
|
||||
|
||||
terms = listify_lookup_plugin_terms(terms, templar=self._templar, loader=self._loader)
|
||||
terms[0] = listify_lookup_plugin_terms(terms[0], templar=self._templar, loader=self._loader)
|
||||
|
||||
# check lookup terms - check number of terms
|
||||
|
|
|
@ -27,9 +27,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
if not isinstance(terms, list):
|
||||
terms = [ terms ]
|
||||
|
||||
basedir = self.get_basedir(variables)
|
||||
|
||||
ret = []
|
||||
|
|
|
@ -31,7 +31,7 @@ class LookupModule(LookupBase):
|
|||
[1, 2], [3] -> [1, 3], [2, None]
|
||||
"""
|
||||
|
||||
def __lookup_variables(self, terms):
|
||||
def _lookup_variables(self, terms):
|
||||
results = []
|
||||
for x in terms:
|
||||
intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader)
|
||||
|
@ -40,7 +40,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
terms = self.__lookup_variables(terms)
|
||||
terms = self._lookup_variables(terms)
|
||||
|
||||
my_list = terms[:]
|
||||
if len(my_list) == 0:
|
||||
|
|
|
@ -29,9 +29,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
validate_certs = kwargs.get('validate_certs', True)
|
||||
|
||||
ret = []
|
||||
|
|
|
@ -251,6 +251,7 @@ class Templar:
|
|||
instance = self._lookup_loader.get(name.lower(), loader=self._loader, templar=self)
|
||||
|
||||
if instance is not None:
|
||||
loop_terms = listify_lookup_plugin_terms(terms=8args, templar=self, loader=self._loader, fail_on_undefined=True)
|
||||
# safely catch run failures per #5059
|
||||
try:
|
||||
ran = instance.run(*args, variables=self._available_variables, **kwargs)
|
||||
|
|
Loading…
Reference in a new issue