'find one file in first path in stack taking roles into account and adding play basedir as fallback
:arg paths: A list of text strings which are the paths to look for the filename in.
:arg dirname: A text string representing a directory.  The directory
is prepended to the source to form the path to search for.
:arg source: A text string which is the filename to search for
:rtype: A text string
:returns: An absolute path to the filename ``source`` if found
:raises: An AnsibleFileNotFound Exception if the file is found to exist in the search paths'

def path_dwim_relative_stack(self, paths, dirname, source, is_role=False):

    b_dirname = to_bytes(dirname)
    b_source = to_bytes(source)
    result = None
    search = []
    if (source is None):
        display.warning('Invalid    request    to    find    a    file    that    matches    a    "null"    value')
    elif (source and (source.startswith('~') or source.startswith(os.path.sep))):
        test_path = unfrackpath(b_source, follow=False)
        if os.path.exists(to_bytes(test_path, errors='surrogate_or_strict')):
            result = test_path
    else:
        display.debug((u'evaluation_path:\n DCTB %s' % '\n DCTB '.join(paths)))
        for path in paths:
            upath = unfrackpath(path, follow=False)
            b_upath = to_bytes(upath, errors='surrogate_or_strict')
            b_mydir = os.path.dirname(b_upath)
            if (is_role or self._is_role(path)):
                if b_mydir.endswith('tasks'):
                    search.append(os.path.join(os.path.dirname(b_mydir), b_dirname, b_source))
                    search.append(os.path.join(b_mydir, b_source))
                else:
                    if (b_source.split('/')[0] != b_dirname):
                        search.append(os.path.join(b_upath, b_dirname, b_source))
                    search.append(os.path.join(b_upath, b_source))
            elif (b_dirname not in b_source.split('/')):
                if (b_source.split('/')[0] != dirname):
                    search.append(os.path.join(b_upath, b_dirname, b_source))
                search.append(os.path.join(b_upath, b_source))
        if (b_source.split('/')[0] != dirname):
            search.append(os.path.join(to_bytes(self.get_basedir()), b_dirname, b_source))
        search.append(os.path.join(to_bytes(self.get_basedir()), b_source))
        display.debug((u'search_path:\n DCTB %s' % to_text('\n DCTB '.join(search))))
        for b_candidate in search:
            display.vvvvv((u'looking    for    "%s"    at    "%s"' % (source, to_text(b_candidate))))
            if os.path.exists(b_candidate):
                result = to_text(b_candidate)
                break
    if (result is None):
        raise AnsibleFileNotFound(file_name=source, paths=[to_text(p) for p in search])
    return result
