'Loads a lookup plugin to handle the with_* portion of a task (if specified),
and returns the items result.'

def _get_loop_items(self):

    play_context_vars = dict()
    self._play_context.update_vars(play_context_vars)
    old_vars = dict()
    for k in play_context_vars:
        if (k in self._job_vars):
            old_vars[k] = self._job_vars[k]
        self._job_vars[k] = play_context_vars[k]
    self._job_vars['ansible_search_path'] = self._task.get_search_path()
    templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=self._job_vars)
    items = None
    if self._task.loop:
        if (self._task.loop in self._shared_loader_obj.lookup_loader):
            fail = True
            if (self._task.loop == 'first_found'):
                fail = False
            loop_terms = listify_lookup_plugin_terms(terms=self._task.loop_args, templar=templar, loader=self._loader, fail_on_undefined=fail, convert_bare=False)
            if (not fail):
                loop_terms = [t for t in loop_terms if (not templar._contains_vars(t))]
            mylookup = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar)
            for subdir in ['template', 'var', 'file']:
                if (subdir in self._task.action):
                    break
            setattr(mylookup, '_subdir', (subdir + 's'))
            items = mylookup.run(terms=loop_terms, variables=self._job_vars, wantlist=True)
        else:
            raise AnsibleError(("Unexpected    failure    in    finding    the    lookup    named    '%s'    in    the    available    lookup    plugins" % self._task.loop))
    for k in play_context_vars:
        if (k in old_vars):
            self._job_vars[k] = old_vars[k]
        else:
            del self._job_vars[k]
    if items:
        for (idx, item) in enumerate(items):
            if ((item is not None) and (not isinstance(item, UnsafeProxy))):
                items[idx] = UnsafeProxy(item)
    if (self._loader.get_basedir() not in self._job_vars['ansible_search_path']):
        self._job_vars['ansible_search_path'].append(self._loader.get_basedir())
    return items
