mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 06:30:19 -07:00
Make all lookup plugins work with lists
Lookup plugins should accept a string or a list, and always return a list, even if it is just one item.
This commit is contained in:
parent
6350dedd7a
commit
b73016b881
9 changed files with 101 additions and 68 deletions
|
@ -24,9 +24,14 @@ class LookupModule(object):
|
|||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
p = subprocess.Popen(terms, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode == 0:
|
||||
return [stdout.rstrip()]
|
||||
else:
|
||||
raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (terms, p.returncode))
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
ret = []
|
||||
for term in terms:
|
||||
p = subprocess.Popen(term, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode == 0:
|
||||
ret.append(stdout.rstrip())
|
||||
else:
|
||||
raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (term, p.returncode))
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue