diff --git a/lib/ansible/runner/lookup_plugins/dnstxt.py b/lib/ansible/runner/lookup_plugins/dnstxt.py index 819f9b90a6..072d33f3c6 100644 --- a/lib/ansible/runner/lookup_plugins/dnstxt.py +++ b/lib/ansible/runner/lookup_plugins/dnstxt.py @@ -41,20 +41,24 @@ class LookupModule(object): raise errors.AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed") def run(self, terms, **kwargs): + if isinstance(terms, basestring): + terms = [ terms ] + ret = [] + for term in terms: + domain = term.split()[0] + string = [] + try: + answers = dns.resolver.query(domain, 'TXT') + for rdata in answers: + s = rdata.to_text() + string.append(s[1:-1]) # Strip outside quotes on TXT rdata - domain = terms.split()[0] - string = [] - try: - answers = dns.resolver.query(domain, 'TXT') - for rdata in answers: - s = rdata.to_text() - string.append(s[1:-1]) # Strip outside quotes on TXT rdata + except dns.resolver.NXDOMAIN: + string = 'NXDOMAIN' + except dns.resolver.Timeout: + string = '' + except dns.exception.DNSException as e: + raise errors.AnsibleError("dns.resolver unhandled exception", e) - except dns.resolver.NXDOMAIN: - string = 'NXDOMAIN' - except dns.resolver.Timeout: - string = '' - except dns.exception.DNSException as e: - raise errors.AnsibleError("dns.resolver unhandled exception", e) - - return ''.join(string) + ret.append(''.join(string)) + return ret diff --git a/lib/ansible/runner/lookup_plugins/env.py b/lib/ansible/runner/lookup_plugins/env.py index 5599261d1d..4e21cac788 100644 --- a/lib/ansible/runner/lookup_plugins/env.py +++ b/lib/ansible/runner/lookup_plugins/env.py @@ -24,6 +24,10 @@ class LookupModule(object): self.basedir = basedir def run(self, terms, **kwargs): - - var = terms.split()[0] - return os.getenv(var, '') + if isinstance(terms, basestring): + terms = [ terms ] + ret = [] + for term in terms: + var = term.split()[0] + ret.append(os.getenv(var, '')) + return ret diff --git a/lib/ansible/runner/lookup_plugins/file.py b/lib/ansible/runner/lookup_plugins/file.py index 50635fced3..92fa9a7c93 100644 --- a/lib/ansible/runner/lookup_plugins/file.py +++ b/lib/ansible/runner/lookup_plugins/file.py @@ -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 diff --git a/lib/ansible/runner/lookup_plugins/fileglob.py b/lib/ansible/runner/lookup_plugins/fileglob.py index 6711ccc84d..a42ffcb274 100644 --- a/lib/ansible/runner/lookup_plugins/fileglob.py +++ b/lib/ansible/runner/lookup_plugins/fileglob.py @@ -25,10 +25,13 @@ class LookupModule(object): self.basedir = basedir def run(self, terms, **kwargs): - dwimterms = utils.path_dwim(self.basedir, terms) - # This skips whatever prefix the dwim added, leaving just the filename for the item - dwim_prefix_len = len(dwimterms) - len(terms) - return [ f[dwim_prefix_len:] for f in glob.glob(dwimterms) if os.path.isfile(f) ] - - - + 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 + dwim_prefix_len = len(dwimterms) - len(term) + ret.extend([ f[dwim_prefix_len:] + for f in glob.glob(dwimterms) if os.path.isfile(f) ]) + return ret diff --git a/lib/ansible/runner/lookup_plugins/items.py b/lib/ansible/runner/lookup_plugins/items.py index efc4169602..f11c1fab1d 100644 --- a/lib/ansible/runner/lookup_plugins/items.py +++ b/lib/ansible/runner/lookup_plugins/items.py @@ -21,7 +21,6 @@ class LookupModule(object): pass def run(self, terms, **kwargs): - return terms - - - + if isinstance(terms, basestring): + terms = [ terms ] + return [term for term in terms] diff --git a/lib/ansible/runner/lookup_plugins/lines.py b/lib/ansible/runner/lookup_plugins/lines.py index 37c34c993d..0a086e7823 100644 --- a/lib/ansible/runner/lookup_plugins/lines.py +++ b/lib/ansible/runner/lookup_plugins/lines.py @@ -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.splitlines() - else: - raise errors.AnsibleError("lookup_plugin.lines(%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.extend(stdout.splitlines()) + else: + raise errors.AnsibleError("lookup_plugin.lines(%s) returned %d" % (term, p.returncode)) + return ret diff --git a/lib/ansible/runner/lookup_plugins/pipe.py b/lib/ansible/runner/lookup_plugins/pipe.py index 5308c0ac5e..37ea97b520 100644 --- a/lib/ansible/runner/lookup_plugins/pipe.py +++ b/lib/ansible/runner/lookup_plugins/pipe.py @@ -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 diff --git a/lib/ansible/runner/lookup_plugins/redis_kv.py b/lib/ansible/runner/lookup_plugins/redis_kv.py index a59454eef3..768d6b75d3 100644 --- a/lib/ansible/runner/lookup_plugins/redis_kv.py +++ b/lib/ansible/runner/lookup_plugins/redis_kv.py @@ -40,28 +40,32 @@ class LookupModule(object): raise errors.AnsibleError("Can't LOOKUP(redis_kv): module redis is not installed") def run(self, terms, **kwargs): + if isinstance(terms, basestring): + terms = [ terms ] + ret = [] + for term in terms: + (url,key) = term.split(',') + if url == "": + url = 'redis://localhost:6379' - (url,key) = terms.split(',') - if url == "": - url = 'redis://localhost:6379' + # urlsplit on Python 2.6.1 is broken. Hmm. Probably also the reason + # Redis' from_url() doesn't work here. - # urlsplit on Python 2.6.1 is broken. Hmm. Probably also the reason - # Redis' from_url() doesn't work here. + p = '(?P[^:]+)://?(?P[^:/ ]+).?(?P[0-9]*).*' - p = '(?P[^:]+)://?(?P[^:/ ]+).?(?P[0-9]*).*' + try: + m = re.search(p, url) + host = m.group('host') + port = int(m.group('port')) + except AttributeError: + raise errors.AnsibleError("Bad URI in redis lookup") - try: - m = re.search(p, url) - host = m.group('host') - port = int(m.group('port')) - except AttributeError: - raise errors.AnsibleError("Bad URI in redis lookup") - - try: - conn = redis.Redis(host=host, port=port) - res = conn.get(key) - if res is None: - res = "" - return res - except: - return "" # connection failed or key not found + try: + conn = redis.Redis(host=host, port=port) + res = conn.get(key) + if res is None: + res = "" + ret.append(res) + except: + ret.append("") # connection failed or key not found + return ret diff --git a/lib/ansible/runner/lookup_plugins/template.py b/lib/ansible/runner/lookup_plugins/template.py index 4c8c4b1e86..987de9ef1d 100644 --- a/lib/ansible/runner/lookup_plugins/template.py +++ b/lib/ansible/runner/lookup_plugins/template.py @@ -23,5 +23,9 @@ class LookupModule(object): self.basedir = basedir 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