diff --git a/lib/ansible/plugins/lookup/__init__.py b/lib/ansible/plugins/lookup/__init__.py index e8f5b9a6ed..490ea959a4 100644 --- a/lib/ansible/plugins/lookup/__init__.py +++ b/lib/ansible/plugins/lookup/__init__.py @@ -31,10 +31,12 @@ except ImportError: __all__ = ['LookupBase'] + class LookupBase(with_metaclass(ABCMeta, object)): def __init__(self, loader=None, templar=None, **kwargs): self._loader = loader self._templar = templar + # Backwards compat: self._display isn't really needed, just import the global display and use that. self._display = display def get_basedir(self, variables): diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py index 26b10fce01..abc77c601d 100644 --- a/lib/ansible/plugins/lookup/file.py +++ b/lib/ansible/plugins/lookup/file.py @@ -20,6 +20,14 @@ __metaclass__ = type from ansible.errors import AnsibleError, AnsibleParserError from ansible.plugins.lookup import LookupBase +try: + from __main__ import display + display = display +except ImportError: + from ansible.utils.display import Display + display = Display() + + class LookupModule(LookupBase): def run(self, terms, variables=None, **kwargs): @@ -29,7 +37,7 @@ class LookupModule(LookupBase): basedir = self.get_basedir(variables) for term in terms: - self._display.debug("File lookup term: %s" % term) + display.debug("File lookup term: %s" % term) # Special handling of the file lookup, used primarily when the # lookup is done from a role. If the file isn't found in the @@ -38,7 +46,7 @@ class LookupModule(LookupBase): # itself (which will be relative to the current working dir) lookupfile = self._loader.path_dwim_relative(basedir, 'files', term) - self._display.vvvv("File lookup using %s as file" % lookupfile) + display.vvvv("File lookup using %s as file" % lookupfile) try: if lookupfile: contents, show_data = self._loader._get_file_contents(lookupfile) diff --git a/lib/ansible/plugins/lookup/template.py b/lib/ansible/plugins/lookup/template.py index 5fc10d7f52..439b805979 100644 --- a/lib/ansible/plugins/lookup/template.py +++ b/lib/ansible/plugins/lookup/template.py @@ -23,6 +23,14 @@ from ansible import constants as C from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase +try: + from __main__ import display + display = display +except ImportError: + from ansible.utils.display import Display + display = Display() + + class LookupModule(LookupBase): def run(self, terms, variables, **kwargs): @@ -32,10 +40,10 @@ class LookupModule(LookupBase): ret = [] for term in terms: - self._display.debug("File lookup term: %s" % term) + display.debug("File lookup term: %s" % term) lookupfile = self._loader.path_dwim_relative(basedir, 'templates', term) - self._display.vvvv("File lookup using %s as file" % lookupfile) + display.vvvv("File lookup using %s as file" % lookupfile) if lookupfile and os.path.exists(lookupfile): with open(lookupfile, 'r') as f: template_data = f.read() diff --git a/lib/ansible/plugins/lookup/url.py b/lib/ansible/plugins/lookup/url.py index 51ab0303dc..d40bb54c39 100644 --- a/lib/ansible/plugins/lookup/url.py +++ b/lib/ansible/plugins/lookup/url.py @@ -24,16 +24,23 @@ from ansible.plugins.lookup import LookupBase from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError from ansible.utils.unicode import to_unicode -class LookupModule(LookupBase): +try: + from __main__ import display + display = display +except ImportError: + from ansible.utils.display import Display + display = Display() +class LookupModule(LookupBase): + def run(self, terms, variables=None, **kwargs): validate_certs = kwargs.get('validate_certs', True) ret = [] for term in terms: - self._display.vvvv("url lookup connecting to %s" % term) + display.vvvv("url lookup connecting to %s" % term) try: response = open_url(term, validate_certs=validate_certs) except urllib2.HTTPError as e: