Internal/ruby event that could be used for hook on subnet creation?

Hello all!

Is there a way for me to associate some internal ruby event to a hook to run something for me on subnet creation?

I’m looking for something similar to host/discovered/[after_commit|after_create|after_destroy] so I can automate subnet creation/deletion of said subnet in DHCP config and restart ISC dhcpd after that.


Possibly just answered my own question:

# foreman-rake hooks:events[subnet]

1 Like

Hmm, even though Foreman does recognize a simple script I put under ~foreman/config/hooks/subnet/{after_commit,after_create,after_destroy}/, I don’t see that script executed:

2018-09-06 14:44:06 [app] [D] Found hook to Subnet#after_destroy, filename
2018-09-06 14:44:06 [app] [D] Found hook to Subnet#after_create, filename
2018-09-06 14:44:06 [app] [D] Found hook to Subnet#after_commit, filename
2018-09-06 14:44:06 [app] [I] Finished discovering 1 hooks for Subnet#after_destroy
2018-09-06 14:44:06 [app] [I] Finished discovering 1 hooks for Subnet#after_create
2018-09-06 14:44:06 [app] [I] Finished discovering 1 hooks for Subnet#after_commit
2018-09-06 14:44:09 [app] [D] Extending Subnet with foreman_hooks Rails hooking support
2018-09-06 14:44:09 [app] [D] Created hook method after_destroy on Subnet
2018-09-06 14:44:09 [app] [D] Created hook method after_create on Subnet
2018-09-06 14:44:09 [app] [D] Created hook method after_commit on Subnet

On a subnet deletion/update/create, I only see this in a log:

2018-09-06 14:47:10 6e900e71 [app] [D] Observed after_commit hook on

Instead of expected output like this (other hooks on the same Foreman instance):

2018-09-06 14:52:47 1069c3e6 [sql] [D] Observed update hook on
2018-09-06 14:52:47 1069c3e6 [sql] [D] Queuing 3 hooks for Host::Managed#update
2018-09-06 14:52:47 1069c3e6 [sql] [D] Queuing hook for Host::Managed#update at priority 00
2018-09-06 14:52:47 1069c3e6 [sql] [D] Running hook: /usr/share/foreman/config/hooks/host/managed/update/ update
2018-09-06 14:52:48 1069c3e6 [sql] [D] Task Hook: completed

Am I out of luck here and can’t actually use Ruby events for subnets?

This is 1.15. Forgot to mention.

Shooting in the dark: Is the file executable? Permissions and ownership?

This should work.

Yes, everything with the script is perfectly fine. In fact, that’s just a symlink to the same script that host/managed hooks use and the latter have no issues with it as you can see in my example above.

I agree, this seems like something that should just work, but it does not and I’m puzzled here…

Can you drop the symlink and do a copy? SELinux might be preventing that. Absolute symlinks are also problem sometimes (not in this context but in chroots).

I did try that, but there’s no difference in behavior - I still see that hook is observed, but not executed :frowning:

Anything else I could try?

Can you put bunch of puts into the code and identify where it stops?

Sure, I can try that. I’m just wondering if anybody else have tried and got that working? Should be easy to setup and try it out.