# Buggy code
def run(self, terms, variables, **kwargs):
    result = None
    anydict = False
    skip = False

    for term in terms:
        if isinstance(term, dict):
            anydict = True

    total_search = []
    if anydict:
        for term in terms:
            if isinstance(term, dict):
                files = term.get("files", [])
                paths = term.get("paths", [])
                skip = boolean(term.get("skip", False))

                filelist = files
                if isinstance(files, basestring):
                    files = files.replace(",", " ")
                    files = files.replace(";", " ")
                    filelist = files.split(" ")

                pathlist = paths
                if paths:
                    if isinstance(paths, basestring):
                        paths = paths.replace(",", " ")
                        paths = paths.replace(":", " ")
                        paths = paths.replace(";", " ")
                        pathlist = paths.split(" ")

                if not pathlist:
                    total_search = filelist
                else:
                    for path in pathlist:
                        for fn in filelist:
                            f = os.path.join(path, fn)
                            total_search.append(f)
            else:
                total_search.append(term)
    else:
        total_search = terms

    roledir = variables.get("roledir")
    for fn in total_search:
        try:
            fn = self._templar.template(fn)
        except (AnsibleUndefinedVariable, UndefinedError) as e:
            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]
    else:
        if skip:
            return []
        else:
            raise AnsibleLookupError(
                "No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found"
            )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/executor/process/worker.py", line 114, in run
self._shared_loader_obj,
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 91, in run
item_results = self._run_loop(items)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 241, in _run_loop
res = self._execute(variables=task_vars)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 356, in _execute
self._task.post_validate(templar=templar)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/playbook/task.py", line 238, in post_validate
super(Task, self).post_validate(templar)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/playbook/base.py", line 307, in post_validate
value = templar.template(getattr(self, name))
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/template/__init__.py", line 350, in template
d[k] = self.template(variable[k], preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/template/__init__.py", line 322, in template
result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/template/__init__.py", line 474, in _do_template
res = j2_concat(rf)
File "<template>", line 9, in root
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/vendor/lib/python2.7/site-packages/jinja2/runtime.py", line 196, in call
return __obj(*args, **kwargs)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/template/__init__.py", line 401, in _lookup
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
File "/usr/local/Cellar/ansible/2.0.0.2/libexec/lib/python2.7/site-packages/ansible/plugins/lookup/first_found.py", line 183, in run
if os.path.isabs(fn) and os.path.exists(fn):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 54, in isabs
return s.startswith('/')
AttributeError: 'list' object has no attribute 'startswith'

# Fixed code
def run(self, terms, variables, **kwargs):
    result = None
    anydict = False
    skip = False

    for term in terms:
        if isinstance(term, dict):
            anydict = True

    total_search = []
    if anydict:
        for term in terms:
            if isinstance(term, dict):
                files = term.get("files", [])
                paths = term.get("paths", [])
                skip = boolean(term.get("skip", False))

                filelist = files
                if isinstance(files, basestring):
                    files = files.replace(",", " ")
                    files = files.replace(";", " ")
                    filelist = files.split(" ")

                pathlist = paths
                if paths:
                    if isinstance(paths, basestring):
                        paths = paths.replace(",", " ")
                        paths = paths.replace(":", " ")
                        paths = paths.replace(";", " ")
                        pathlist = paths.split(" ")

                if not pathlist:
                    total_search = filelist
                else:
                    for path in pathlist:
                        for fn in filelist:
                            f = os.path.join(path, fn)
                            total_search.append(f)
            else:
                total_search.append(term)
    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:
            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]
    else:
        if skip:
            return []
        else:
            raise AnsibleLookupError(
                "No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found"
            )