first_found lookup; minor fixes (#82836)

Always process options no matter the combination
return a full normalized path (symlinks still not followed, should be specific option in future)
pull/82895/head
Brian Coca 2 months ago committed by GitHub
parent b4d67adfda
commit ad0ec47fe9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
bugfixes:
- first_found lookup now always takes into account k=v options
- first_found lookup now always returns a full (absolute) and normalized path

@ -147,6 +147,7 @@ from jinja2.exceptions import UndefinedError
from ansible.errors import AnsibleLookupError, AnsibleUndefinedVariable
from ansible.module_utils.six import string_types
from ansible.plugins.lookup import LookupBase
from ansible.utils.path import unfrackpath
def _split_on(terms, spliters=','):
@ -206,8 +207,9 @@ class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
self.set_options(var_options=variables, direct=kwargs)
if not terms:
self.set_options(var_options=variables, direct=kwargs)
terms = self.get_option('files')
total_search, skip = self._process_terms(terms, variables, kwargs)
@ -234,7 +236,7 @@ class LookupModule(LookupBase):
# exit if we find one!
if path is not None:
return [path]
return [unfrackpath(path, follow=False)]
# if we get here, no file was found
if skip:

@ -147,3 +147,8 @@
- ishouldnotbefound.yml
paths:
- "{{role_path}}/vars"
- name: Make sure skip works in 'mixed' argument passing
assert:
that:
- q('first_found', ['/nonexistant'], skip=True) == []

Loading…
Cancel
Save