Repository: ansible/ansible

Issue:
lookup first_found problem
ansible v2.0.0.2
My ansible role:

```
- name: create nameserver zones configs
  template: >
    src={{ lookup('first_found', nameserver_zone_templates) }}
    dest=/srv/{{ nameserver_container_name }}/db.{{ item.domain }}
  with_items: nameserver_zones
```

An exception occurred during task execution. The full traceback is:

```
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'
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/lookup/first_found.py b/lib/ansible/plugins/lookup/first_found.py
--- a/lib/ansible/plugins/lookup/first_found.py
+++ b/lib/ansible/plugins/lookup/first_found.py
@@ -171,7 +171,7 @@ def run(self, terms, variables, **kwargs):
                 else:
                     total_search.append(term)
         else:
-            total_search = terms
+            total_search = self._flatten(terms)
 
         roledir = variables.get('roledir')
         for fn in total_search:


Test patch: