mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make more lookup plugins tolerant of new variable system, with a little better 'do what I mean' logic to resolving
what happens if you get a string back as a template result.
This commit is contained in:
parent
c0f8af5202
commit
86d47bce5f
11 changed files with 51 additions and 33 deletions
|
@ -40,9 +40,13 @@ class LookupModule(object):
|
|||
if HAVE_DNS == False:
|
||||
raise errors.AnsibleError("Can't LOOKUP(dnstxt): module dns.resolver is not installed")
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
|
||||
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
domain = term.split()[0]
|
||||
|
|
|
@ -23,9 +23,10 @@ class LookupModule(object):
|
|||
def __init__(self, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
var = term.split()[0]
|
||||
|
|
|
@ -66,10 +66,6 @@
|
|||
|
||||
# this will include the tasks in the file generic where it is found first (staging or production)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from ansible import utils, errors
|
||||
import os
|
||||
|
||||
|
@ -78,8 +74,12 @@ class LookupModule(object):
|
|||
def __init__(self, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
result = None
|
||||
|
||||
for term in terms:
|
||||
if isinstance(term, dict):
|
||||
files = term.get('files', [])
|
||||
|
|
|
@ -23,9 +23,10 @@ class LookupModule(object):
|
|||
def __init__(self, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
p = subprocess.Popen(term, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
|
|
|
@ -30,9 +30,10 @@ class LookupModule(object):
|
|||
def __init__(self, length=None, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
ret = []
|
||||
|
||||
for term in terms:
|
||||
|
|
|
@ -23,9 +23,13 @@ class LookupModule(object):
|
|||
def __init__(self, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
terms = [ terms ]
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
p = subprocess.Popen(term, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import random
|
||||
from ansible import utils
|
||||
|
||||
# useful for introducing chaos ... or just somewhat reasonably fair selection
|
||||
# amongst available mirrors
|
||||
|
@ -32,8 +33,9 @@ class LookupModule(object):
|
|||
def __init__(self, basedir=None, **kwargs):
|
||||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
return [ random.choice(terms) ]
|
||||
|
||||
|
|
|
@ -39,9 +39,10 @@ class LookupModule(object):
|
|||
if HAVE_REDIS == False:
|
||||
raise errors.AnsibleError("Can't LOOKUP(redis_kv): module redis is not installed")
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
(url,key) = term.split(',')
|
||||
|
|
|
@ -73,9 +73,9 @@ class LookupModule(object):
|
|||
calculating the number of entries in a sequence when a stride is specified.
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, basedir, **kwargs):
|
||||
"""absorb any keyword args"""
|
||||
pass
|
||||
self.basedir = basedir
|
||||
|
||||
def reset(self):
|
||||
"""set sensible defaults"""
|
||||
|
@ -170,11 +170,10 @@ class LookupModule(object):
|
|||
"problem formatting %r with %r" % self.format
|
||||
)
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
results = []
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [terms]
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
for term in terms:
|
||||
try:
|
||||
|
|
|
@ -23,8 +23,9 @@ class LookupModule(object):
|
|||
self.basedir = basedir
|
||||
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
ret.append(template.template_from_file(self.basedir, term, inject))
|
||||
|
|
|
@ -725,7 +725,11 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
|
|||
|
||||
if not '{' in terms and not '[' in terms and not terms.strip().startswith("/"):
|
||||
try:
|
||||
terms = template.template(basedir, "{{ %s }}" % terms, inject)
|
||||
new_terms = template.template(basedir, "{{ %s }}" % terms, inject)
|
||||
if isinstance(new_terms, basestring) and new_terms.find("{{") != -1:
|
||||
pass
|
||||
else:
|
||||
terms = new_terms
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue