correct, cleanup & simplify dwim stack (#25956)

* correct, cleanup & simplify dwim stack

latlh chIS logh HeS qar wej chel laD
better errors
update find_file to new exception

* addressed latest comments

* test should not use realpath as it follows symlink

this fails when on OS X as /var is now a symlink to /private/var
but first_found was not supposed to follow symlinks
This commit is contained in:
Brian Coca 2017-07-03 15:27:53 -04:00 committed by GitHub
commit 8f758204cf
7 changed files with 81 additions and 52 deletions

View file

@ -22,6 +22,7 @@ __metaclass__ = type
from abc import ABCMeta, abstractmethod
from ansible.module_utils.six import with_metaclass
from ansible.errors import AnsibleFileNotFound
try:
from __main__ import display
@ -112,8 +113,11 @@ class LookupBase(with_metaclass(ABCMeta, object)):
else:
paths = self.get_basedir(myvars)
result = self._loader.path_dwim_relative_stack(paths, subdir, needle)
if result is None and not ignore_missing:
self._display.warning("Unable to find '%s' in expected paths." % needle)
result = None
try:
result = self._loader.path_dwim_relative_stack(paths, subdir, needle)
except AnsibleFileNotFound:
if not ignore_missing:
self._display.warning("Unable to find '%s' in expected paths." % needle)
return result