Problem:
Trying to work around issues regarding cloud-init (more on that in another thread), we have created hooks to generate directories and files on our Foreman server. A webhook is supposed to trigger a shellhook when a host enters build mode. The shellhook would then do its thing on the local filesystem (we adapted /etc/sudoers to allow this).
We were able to verify that the above works if we let the shellhook be triggered by another event. For easy testing, we used the event “Host Updated”. Every time we update a host, the shellhook executes. If we change the event to “Build Entered” and build that host, however, the exact same shellhook does nothing and the Webinterface shows a “500 Internal Server Error” message.
production log for “Host Updated” event
2022-10-10T13:04:57 [I|app|3c9b5b7b] Performing ForemanWebhooks::DeliverWebhookJob (Job ID: 72e1b9b3-ffd2-4e02-bdd8-cdc5cb401cca) from Dynflow(default) enqueued at 2022-10-10T11:
04:31Z with arguments: {:event_name=>"host_updated.event.foreman", :payload=>"", :headers=>"{\n \"X-Shellhook-Arg-1\": \"MANAGEDHOST\"\n}", :url=>"https:/
/FOREMANSERVER:8443/shellhook/host_built_cloud-init.sh", :webhook_id=>8}
2022-10-10T13:04:57 [I|app|3c9b5b7b] Performing 'host built cloud-init' webhook request for event 'host_updated.event.foreman'
2022-10-10T13:04:57 [I|app|3c9b5b7b] POST response was 200
2022-10-10T13:04:57 [I|app|3c9b5b7b] Performed ForemanWebhooks::DeliverWebhookJob (Job ID: 72e1b9b3-ffd2-4e02-bdd8-cdc5cb401cca) from Dynflow(default) in 20.77ms
2022-10-10T13:04:57 [I|app|e4a730f1] Started GET "/apidoc/apipie_checksum" for IPADDRESS at 2022-10-10 13:04:57 +0200
2022-10-10T13:04:57 [I|app|e4a730f1] Processing by Apipie::ApipiesController#apipie_checksum as JSON
2022-10-10T13:04:57 [I|app|e4a730f1] Parameters: {"apipy"=>{}}
2022-10-10T13:04:57 [I|app|e4a730f1] Rendering /usr/share/gems/gems/apipie-rails-0.5.17/app/views/apipie/apipies/apipie_checksum.json.erb
2022-10-10T13:04:57 [I|app|e4a730f1] Rendered /usr/share/gems/gems/apipie-rails-0.5.17/app/views/apipie/apipies/apipie_checksum.json.erb (Duration: 3.9ms | Allocations: 5255)
2022-10-10T13:04:57 [I|app|e4a730f1] Completed 200 OK in 5ms (Views: 4.7ms | ActiveRecord: 0.0ms | Allocations: 5717)
production.log for “Build Entered” event
2022-10-10T11:47:12 [I|app|c19674fc] ForemanWebhooks::EventSubscriber: build_entered.event.foreman event received
2022-10-10T11:47:12 [W|app|c19674fc] undefined method `name' for nil:NilClass
2022-10-10T11:47:12 [I|app|c19674fc] Backtrace for 'undefined method `name' for nil:NilClass' error (NoMethodError): undefined method `name' for nil:NilClass
[...] trace output [...]
2022-10-10T11:47:12 [I|app|c19674fc] Rendering common/500.html.erb
2022-10-10T11:47:12 [I|app|c19674fc] Rendered common/500.html.erb (Duration: 4.9ms | Allocations: 5673)
2022-10-10T11:47:12 [I|app|c19674fc] Completed 500 Internal Server Error in 503ms (Views: 5.6ms | ActiveRecord: 75.7ms | Allocations: 113654)
We noticed that the webhook argument “@object.name” resolves to the FQDN of the managed host for the “Host Updated” event, but logs as “undefined method” for the “Build Entered” event. Is that a bug or are we doing something wrong?
Expected outcome:
A webhook triggered by the “Build Entered” event executes in the same way as webhooks on other events do.
Foreman and Proxy versions:
foreman-3.3.0-1.el8.noarch
foreman-proxy-3.3.0-1.el8.noarch
Foreman and Proxy plugin versions:
rubygem-foreman_webhooks-3.0.3-1.fm3_3.el8.noarch
Distribution and version:
Red Hat Enterprise Linux 8.6 (Ootpa)
Other relevant data: