template.py: Handle purposely raised exceptions in lookup()

If a lookup plugin is run by the lookup() template method it should pass
along any AnsibleError (or child exception classes) rather than just eat
them.  These exceptions are purposely raised by the plugin.
Merge pull request #7608 from jjneely/lookup-function

template.py: Handle purposely raised exceptions in lookup()