Refs #969 - Foreman-side changes for serving templates from the proxy

Needs the proxy-side PR to function.

This is a rebase of @GregSutcliffe's original https://github.com/theforeman/foreman/pull/751.
This rescue seems a bit dangerous, log the stack backtrace in both this and the one below, and in this case raise a foreman exception. Also print the error message in both cases please.