Foreman Hooks Issue

I believe I am experiencing an issue related to Foreman hooks.

Quick run down of what I am trying to do. I want to execute an action when
new hosts are created, either via the UI or through fact or report upload.
Once that occurs I would modify the newly created host (setting location,
puppet proxy and puppet CA proxy, etc). In order to do this I have to
execute in the after_commit stage, as anything prior the host isn't
available via the API. The problem is that after_commit is called for most
actions on a host, not just on creation.

With a suggestion I received here, the after_create or create hook was
utilized to create a file (in /tmp) that is used to trigger the action in
the after_commit. Therefore the after_commit simply checks for the
existence of the file, if found it means this is a newly created host and
performs the necessary tasks, and then deletes the file. If the file isn't
found, exit skipping the rest of the script.

does file exist, if it doesn't return (fail safe so that we don't run

this hook again after initial provisioning)

if File.file?("/tmp/foreman-hooks/#{HOSTNAME}") then

determine whether host was created vai UI or through other means (ie:

fact upload)

d = YAML::load_file("/tmp/foreman-hooks/#{HOSTNAME}")

state = d['state']

if state.eql? "after_create" then

# when called in after_create (at least from fact upload) there is no 

outer host key

event_details = hook_object

else

event_details = get_key hook_object, 'host'

end

else

exit 0

end

As seen above, fairly simple.

However if I drop this into the after_commit directory and enable it
(restart HTTP), the performance of Foreman suffers. Not immediately but
after a while the UI takes forever to respond, and API calls take minutes
to return (thus breaking ENC). The second I remove the script and restart,
everything goes back to normal.

Is there some sort of threading issue with Foreman hooks that I could be
running into?

Thanks

> Is there some sort of threading issue with Foreman hooks that I could be
> running into?

Can't tell until I see the whole script, use pastebin please.

ยทยทยท -- Later, Lukas #lzap Zapletal