mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 11:10:21 -07:00
Merge pull request #10298 from bcoca/lookup_wantlist
Allow requesting a list to lookup plugins instead of , delimited string
This commit is contained in:
commit
acbd096cf3
2 changed files with 7 additions and 3 deletions
|
@ -10,6 +10,8 @@ in Ansible, and are typically used to load variables or templates with informati
|
||||||
|
|
||||||
.. note:: Lookups occur on the local computer, not on the remote computer.
|
.. note:: Lookups occur on the local computer, not on the remote computer.
|
||||||
|
|
||||||
|
.. note:: Since 1.9 you can pass wantlist=True to lookups to use in jinja2 template "for" loops.
|
||||||
|
|
||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
.. _getting_file_contents:
|
.. _getting_file_contents:
|
||||||
|
|
|
@ -89,6 +89,8 @@ def lookup(name, *args, **kwargs):
|
||||||
instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None))
|
instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None))
|
||||||
tvars = kwargs.get('vars', None)
|
tvars = kwargs.get('vars', None)
|
||||||
|
|
||||||
|
wantlist = kwargs.pop('wantlist', False)
|
||||||
|
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
try:
|
try:
|
||||||
ran = instance.run(*args, inject=tvars, **kwargs)
|
ran = instance.run(*args, inject=tvars, **kwargs)
|
||||||
|
@ -98,7 +100,7 @@ def lookup(name, *args, **kwargs):
|
||||||
raise errors.AnsibleUndefinedVariable("One or more undefined variables: %s" % str(e))
|
raise errors.AnsibleUndefinedVariable("One or more undefined variables: %s" % str(e))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise errors.AnsibleError('Unexpected error in during lookup: %s' % e)
|
raise errors.AnsibleError('Unexpected error in during lookup: %s' % e)
|
||||||
if ran:
|
if ran and not wantlist:
|
||||||
ran = ",".join(ran)
|
ran = ",".join(ran)
|
||||||
return ran
|
return ran
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue