mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
fixed lookup search path (#16630)
* fixed lookup search path added ansible_search_path var that contains the proper list and in order removed roledir var which was only used by first_found, rest used role_path added needle function for lookups that mirrors the action plugin one, now both types of plugins use same pathing. * added missing os import * renamed as per feedback * fixed missing rename in first_found * also fixed first_found * fixed import to match new error class * fixed getattr ref
This commit is contained in:
parent
221520cbad
commit
3c39bb5633
11 changed files with 87 additions and 84 deletions
|
@ -118,12 +118,11 @@ __metaclass__ = type
|
|||
# - ../files/baz
|
||||
# ignore_errors: true
|
||||
|
||||
|
||||
import os
|
||||
|
||||
from jinja2.exceptions import UndefinedError
|
||||
|
||||
from ansible.errors import AnsibleLookupError, AnsibleUndefinedVariable
|
||||
from ansible.errors import AnsibleFileNotFound, AnsibleLookupError, AnsibleUndefinedVariable
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.boolean import boolean
|
||||
|
||||
|
@ -131,7 +130,6 @@ class LookupModule(LookupBase):
|
|||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
result = None
|
||||
anydict = False
|
||||
skip = False
|
||||
|
||||
|
@ -173,28 +171,20 @@ class LookupModule(LookupBase):
|
|||
else:
|
||||
total_search = self._flatten(terms)
|
||||
|
||||
roledir = variables.get('roledir')
|
||||
for fn in total_search:
|
||||
try:
|
||||
fn = self._templar.template(fn)
|
||||
except (AnsibleUndefinedVariable, UndefinedError) as e:
|
||||
except (AnsibleUndefinedVariable, UndefinedError):
|
||||
continue
|
||||
|
||||
if os.path.isabs(fn) and os.path.exists(fn):
|
||||
return [fn]
|
||||
else:
|
||||
if roledir is not None:
|
||||
# check the templates and vars directories too,if they exist
|
||||
for subdir in ('templates', 'vars', 'files'):
|
||||
path = self._loader.path_dwim_relative(roledir, subdir, fn)
|
||||
if os.path.exists(path):
|
||||
return [path]
|
||||
|
||||
# if none of the above were found, just check the
|
||||
# current filename against the current dir
|
||||
path = self._loader.path_dwim(fn)
|
||||
if os.path.exists(path):
|
||||
return [path]
|
||||
# get subdir if set by task executor, default to files otherwise
|
||||
subdir = getattr(self, '_subdir', 'files')
|
||||
path = None
|
||||
try:
|
||||
path = self.find_file_in_search_path(variables, subdir, fn)
|
||||
return [path]
|
||||
except AnsibleFileNotFound:
|
||||
continue
|
||||
else:
|
||||
if skip:
|
||||
return []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue