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

Cannot use after_build hook #30

Closed miroswan closed 8 years ago

miroswan commented 8 years ago

This is what happens when I restart foreman after I added my script to /usr/share/foreman/config/hooks/managed/after_build:

uninitialized constant Managed (NameError)
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/config/initializers/deprecations.rb:3:in `const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/inflector/methods.rb:230:in `block in constantize'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/inflector/methods.rb:229:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/inflector/methods.rb:229:in `constantize'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks/engine.rb:6:in `block (2 levels) in <class:Engine>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks/engine.rb:6:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks/engine.rb:6:in `block in <class:Engine>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:462:in `_run__2952295411430003890__prepare__2925492264482690565__callbacks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:405:in `__run_callback'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:81:in `run_callbacks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:30:in `instance_exec'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:30:in `run'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:55:in `block in run_initializers'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:54:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:54:in `run_initializers'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/application.rb:136:in `initialize!'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/railtie/configurable.rb:30:in `method_missing'
  /usr/share/foreman/config/environment.rb:5:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
miroswan commented 8 years ago

Renaming the path to /usr/share/foreman/config/hooks/Host::Managed/after_build fixed it.

miroswan commented 8 years ago

I see in the docs now that the README.md that the path was specified as /usr/share/foreman/config/hooks/host/managed/after_build

Perhaps it makes sense to explain that the Object with :: can be delimited w/ File::SEPARATOR for the given operating system.