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:
Daniel Hokka Zakrisson
2012-12-05 12:26:23 +01:00
parent 6350dedd7a
commit b73016b881
9 changed files with 101 additions and 68 deletions

View File

@@ -24,7 +24,12 @@ class LookupModule(object):
self.basedir = basedir
def run(self, terms, **kwargs):
path = utils.path_dwim(self.basedir, terms)
if not os.path.exists(path):
raise errors.AnsibleError("%s does not exist" % path)
return [open(path).read().rstrip()]
if isinstance(terms, basestring):
terms = [ terms ]
ret = []
for term in terms:
path = utils.path_dwim(self.basedir, term)
if not os.path.exists(path):
raise errors.AnsibleError("%s does not exist" % path)
ret.append(open(path).read().rstrip())
return ret