theforeman / foreman_hooks

Run custom hook scripts on Foreman events
http://m0dlx.com/blog/Extending_Foreman_quickly_with_hook_scripts.html
GNU General Public License v3.0
56 stars 50 forks source link

Hooks fail to render JSON when running under foreman-tasks #28

Closed jameslikeslinux closed 8 years ago

jameslikeslinux commented 8 years ago

In Katello, the job of destroying hosts is farmed off to foreman-tasks so that associated Katello entities like content_hosts can be dealt with at the same time. foreman-tasks runs outside of the main Foreman process, but takes care to load Foreman's application.rb and all of Foreman's plugins. The result is that hooks are run in foreman-tasks jobs, but they fail to find Foreman's views path:

2015-12-03 00:28:20 [D] Running hook: /usr/share/foreman/config/hooks/host/managed/destroy/50_remove_dhcp_conf.sh destroy ci-build-1235.umd.edu
2015-12-03 00:28:20 [W] Unable to render ci-build-1235.umd.edu (Host::Managed) using RABL: Cannot find rabl template 'api/v2/hosts/show' within registered (["app/views"]) view paths!
2015-12-03 00:28:20 [D] /opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl/partials.rb:47:in `block in fetch_source'
/opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl.rb:58:in `source_cache'
/opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl/partials.rb:34:in `fetch_source'
/opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl/renderer.rb:62:in `process_source'
/opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl/renderer.rb:36:in `initialize'
/opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl.rb:77:in `new'
/opt/rh/ruby193/root/usr/share/gems/gems/rabl-0.9.0/lib/rabl.rb:77:in `render'
/opt/rh/ruby193/root/usr/share/gems/gems/foreman_hooks-0.3.7/lib/foreman_hooks/util.rb:18:in `render_hook_json'
/opt/rh/ruby193/root/usr/share/gems/gems/foreman_hooks-0.3.7/lib/foreman_hooks/util.rb:29:in `block in exec_hook'
...