Merge pull request #1733 from dhozac/lookup-list
Make all lookup plugins accept lists as argumentspull/4420/head
commit
d34e320e12
|
@ -41,8 +41,11 @@ class LookupModule(object):
|
||||||
raise errors.AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed")
|
raise errors.AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed")
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
|
if isinstance(terms, basestring):
|
||||||
domain = terms.split()[0]
|
terms = [ terms ]
|
||||||
|
ret = []
|
||||||
|
for term in terms:
|
||||||
|
domain = term.split()[0]
|
||||||
string = []
|
string = []
|
||||||
try:
|
try:
|
||||||
answers = dns.resolver.query(domain, 'TXT')
|
answers = dns.resolver.query(domain, 'TXT')
|
||||||
|
@ -57,4 +60,5 @@ class LookupModule(object):
|
||||||
except dns.exception.DNSException as e:
|
except dns.exception.DNSException as e:
|
||||||
raise errors.AnsibleError("dns.resolver unhandled exception", e)
|
raise errors.AnsibleError("dns.resolver unhandled exception", e)
|
||||||
|
|
||||||
return ''.join(string)
|
ret.append(''.join(string))
|
||||||
|
return ret
|
||||||
|
|
|
@ -24,6 +24,10 @@ class LookupModule(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
|
if isinstance(terms, basestring):
|
||||||
var = terms.split()[0]
|
terms = [ terms ]
|
||||||
return os.getenv(var, '')
|
ret = []
|
||||||
|
for term in terms:
|
||||||
|
var = term.split()[0]
|
||||||
|
ret.append(os.getenv(var, ''))
|
||||||
|
return ret
|
||||||
|
|
|
@ -24,7 +24,12 @@ class LookupModule(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
path = utils.path_dwim(self.basedir, terms)
|
if isinstance(terms, basestring):
|
||||||
|
terms = [ terms ]
|
||||||
|
ret = []
|
||||||
|
for term in terms:
|
||||||
|
path = utils.path_dwim(self.basedir, term)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise errors.AnsibleError("%s does not exist" % path)
|
raise errors.AnsibleError("%s does not exist" % path)
|
||||||
return [open(path).read().rstrip()]
|
ret.append(open(path).read().rstrip())
|
||||||
|
return ret
|
||||||
|
|
|
@ -25,10 +25,13 @@ class LookupModule(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
dwimterms = utils.path_dwim(self.basedir, terms)
|
if isinstance(terms, basestring):
|
||||||
|
terms = [ terms ]
|
||||||
|
ret = []
|
||||||
|
for term in terms:
|
||||||
|
dwimterms = utils.path_dwim(self.basedir, term)
|
||||||
# This skips whatever prefix the dwim added, leaving just the filename for the item
|
# This skips whatever prefix the dwim added, leaving just the filename for the item
|
||||||
dwim_prefix_len = len(dwimterms) - len(terms)
|
dwim_prefix_len = len(dwimterms) - len(term)
|
||||||
return [ f[dwim_prefix_len:] for f in glob.glob(dwimterms) if os.path.isfile(f) ]
|
ret.extend([ f[dwim_prefix_len:]
|
||||||
|
for f in glob.glob(dwimterms) if os.path.isfile(f) ])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ class LookupModule(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
return terms
|
if isinstance(terms, basestring):
|
||||||
|
terms = [ terms ]
|
||||||
|
return [term for term in terms]
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,14 @@ class LookupModule(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
p = subprocess.Popen(terms, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
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()
|
(stdout, stderr) = p.communicate()
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
return stdout.splitlines()
|
ret.extend(stdout.splitlines())
|
||||||
else:
|
else:
|
||||||
raise errors.AnsibleError("lookup_plugin.lines(%s) returned %d" % (terms, p.returncode))
|
raise errors.AnsibleError("lookup_plugin.lines(%s) returned %d" % (term, p.returncode))
|
||||||
|
return ret
|
||||||
|
|
|
@ -24,9 +24,14 @@ class LookupModule(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
p = subprocess.Popen(terms, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
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()
|
(stdout, stderr) = p.communicate()
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
return [stdout.rstrip()]
|
ret.append(stdout.rstrip())
|
||||||
else:
|
else:
|
||||||
raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (terms, p.returncode))
|
raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (term, p.returncode))
|
||||||
|
return ret
|
||||||
|
|
|
@ -40,8 +40,11 @@ class LookupModule(object):
|
||||||
raise errors.AnsibleError("Can't LOOKUP(redis_kv): module redis is not installed")
|
raise errors.AnsibleError("Can't LOOKUP(redis_kv): module redis is not installed")
|
||||||
|
|
||||||
def run(self, terms, **kwargs):
|
def run(self, terms, **kwargs):
|
||||||
|
if isinstance(terms, basestring):
|
||||||
(url,key) = terms.split(',')
|
terms = [ terms ]
|
||||||
|
ret = []
|
||||||
|
for term in terms:
|
||||||
|
(url,key) = term.split(',')
|
||||||
if url == "":
|
if url == "":
|
||||||
url = 'redis://localhost:6379'
|
url = 'redis://localhost:6379'
|
||||||
|
|
||||||
|
@ -62,6 +65,7 @@ class LookupModule(object):
|
||||||
res = conn.get(key)
|
res = conn.get(key)
|
||||||
if res is None:
|
if res is None:
|
||||||
res = ""
|
res = ""
|
||||||
return res
|
ret.append(res)
|
||||||
except:
|
except:
|
||||||
return "" # connection failed or key not found
|
ret.append("") # connection failed or key not found
|
||||||
|
return ret
|
||||||
|
|
|
@ -23,5 +23,9 @@ class LookupModule(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms, inject=None, **kwargs):
|
def run(self, terms, inject=None, **kwargs):
|
||||||
return utils.template_from_file(self.basedir, terms, inject)
|
if isinstance(terms, basestring):
|
||||||
|
terms = [ terms ]
|
||||||
|
ret = []
|
||||||
|
for term in terms:
|
||||||
|
ret.append(utils.template_from_file(self.basedir, term, inject))
|
||||||
|
return ret
|
||||||
|
|
Loading…
Reference in New Issue