Build status for host without content can not be set to "build" - "Refresh Content Host Statuses" fails

Problem:
After upgrading our production environment recently to Foreman 3.2/Katello 4.4, our automatic provisioning workflow for Windows servers started breaking.
The hosts are cloned from templates and all works fine, except setting the build status to “built”. We are using a user-data template to run commands after provisioning, and one of those commands is '<%= powershell %> -Command "invoke-webrequest -Uri <%= foreman_url("built") %>"', which calls the appropriate API endpoint. Foreman fails on that request though with the following error (see below for full stack trace)

Refresh Content Host Statuses for host.example.com task failed with the following error: undefined method `security' for nil:NilClass

Our windows servers do not have content hosts associated, and they also do not have any fields filled in that suggest they should (from what I can see in the GUI). Neither LCE, not Content source or anything else content related are filled out.
The same workflow worked flawlessly both back on Foreman 2.5 and in our test environment. I am not sure why foreman suddenly tries to refresh a content host for these systems that is non-existent.
Expected outcome:
Host getting maked as “built” properly.
Foreman and Proxy versions:
3.2.1
Foreman and Proxy plugin versions:

  • foreman-tasks 6.0.1
  • foreman_expire_hosts 7.0.4
  • foreman_hooks 0.3.17
  • foreman_puppet 3.0.7
  • foreman_remote_execution 6.0.0
  • foreman_scc_manager 1.8.20
  • foreman_snapshot_management 2.0.1
  • foreman_templates 9.1.0
  • katello 4.4.1
  • puppetdb_foreman 5.0.0

Distribution and version:
RHEL 7.9
Other relevant data:
Full stacktrace from production.log

2022-09-19T15:46:54 [I|app|64fe6b85] Started GET "/unattended/built?token=bc2cdb92-d1a6-487b-80a5-57a84f9d1ebd" for 10.160.239.35 at 2022-09-19 15:46:54 +0200
2022-09-19T15:46:54 [I|app|64fe6b85] Processing by UnattendedController#built as TEXT
2022-09-19T15:46:54 [I|app|64fe6b85]   Parameters: {"token"=>"bc2cdb92-d1a6-487b-80a5-57a84f9d1ebd"}
2022-09-19T15:46:54 [I|app|64fe6b85] unattended: host.example.comis built!
2022-09-19T15:46:57 [W|app|64fe6b85] Refresh Content Host Statuses for host.example.com task failed with the following error: undefined method `security' for nil:NilClass
 64fe6b85 | Did you mean?  secure_token
2022-09-19T15:46:57 [I|app|64fe6b85] Backtrace for 'Refresh Content Host Statuses for host.example.com task failed with the following error: undefined method `security' for nil:NilClass
 64fe6b85 | Did you mean?  secure_token' error (NoMethodError): undefined method `security' for nil:NilClass
 64fe6b85 | Did you mean?  secure_token
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4.1/app/models/katello/errata_status.rb:61:in `to_status'
 64fe6b85 | /usr/share/foreman/app/models/host_status/status.rb:83:in `update_status'
 64fe6b85 | /usr/share/foreman/app/models/host_status/status.rb:58:in `refresh'
 64fe6b85 | /usr/share/foreman/app/models/host_status/status.rb:52:in `refresh!'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4.1/app/models/katello/concerns/host_managed_extensions.rb:122:in `block in refresh_content_host_status'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/relation/delegation.rb:87:in `each'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/relation/delegation.rb:87:in `each'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4.1/app/models/katello/concerns/host_managed_extensions.rb:121:in `refresh_content_host_status'
 64fe6b85 | /usr/share/foreman/app/models/concerns/orchestration.rb:227:in `execute'
 64fe6b85 | /usr/share/foreman/app/models/concerns/orchestration.rb:152:in `block in process'
 64fe6b85 | /usr/share/foreman/app/models/concerns/orchestration.rb:144:in `each'
 64fe6b85 | /usr/share/foreman/app/models/concerns/orchestration.rb:144:in `process'
 64fe6b85 | /usr/share/foreman/app/models/concerns/orchestration.rb:44:in `around_save_orchestration'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:139:in `run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:825:in `_run_save_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/callbacks.rb:327:in `create_or_update'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/timestamp.rb:128:in `create_or_update'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/persistence.rb:470:in `save'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/validations.rb:47:in `save'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:314:in `block in save'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:375:in `block in with_transaction_returning_status'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `block in transaction'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transaction'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `transaction'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:212:in `transaction'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:366:in `with_transaction_returning_status'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:314:in `save'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/suppressor.rb:44:in `save'
 64fe6b85 | /usr/share/foreman/app/models/concerns/foreman/sti.rb:26:in `save'
 64fe6b85 | /usr/share/foreman/app/models/host/managed.rb:402:in `built'
 64fe6b85 | /usr/share/foreman/app/models/concerns/hostext/ui_notifications.rb:9:in `built'
 64fe6b85 | /usr/share/foreman/app/controllers/unattended_controller.rb:29:in `built'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/abstract_controller/base.rb:195:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal/rendering.rb:30:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:112:in `block in run_callbacks'
 64fe6b85 | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in `set_timezone'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 64fe6b85 | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 64fe6b85 | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.9.0/lib/audited/sweeper.rb:14:in `around'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.9.0/lib/audited/sweeper.rb:14:in `around'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:139:in `run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/abstract_controller/callbacks.rb:41:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal/rescue.rb:22:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/notifications.rb:180:in `block in instrument'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/notifications.rb:180:in `instrument'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/abstract_controller/base.rb:136:in `process'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionview-6.0.3.7/lib/action_view/rendering.rb:39:in `process'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal.rb:190:in `dispatch'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_controller/metal.rb:254:in `dispatch'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/routing/route_set.rb:33:in `serve'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/journey/router.rb:49:in `block in serve'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/journey/router.rb:32:in `each'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/journey/router.rb:32:in `serve'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/routing/route_set.rb:834:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4.1/lib/katello/middleware/organization_created_enforcer.rb:18:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4.1/lib/katello/middleware/event_daemon.rb:10:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-dsl-2.4.0/lib/apipie_dsl/static_dispatcher.rb:67:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.17/lib/apipie/static_dispatcher.rb:66:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.17/lib/apipie/extractor/recorder.rb:137:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /usr/share/foreman/lib/foreman/middleware/libvirt_connection_cleaner.rb:9:in `call'
 64fe6b85 | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.17/lib/apipie/middleware/checksum_in_headers.rb:27:in `call'
 64fe6b85 | /usr/share/foreman/lib/foreman/middleware/catch_json_parse_errors.rb:9:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
 64fe6b85 | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/cookies.rb:648:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/callbacks.rb:101:in `run_callbacks'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/rack/logger.rb:37:in `call_app'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/rack/logger.rb:28:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
 64fe6b85 | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/request_id.rb:27:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4.1/lib/katello/prevent_json_parsing.rb:12:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/executor.rb:14:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/actionpack-6.0.3.7/lib/action_dispatch/middleware/host_authorization.rb:76:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/secure_headers-6.3.0/lib/secure_headers/middleware.rb:11:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/engine.rb:527:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:190:in `public_send'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:190:in `method_missing'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/urlmap.rb:74:in `block in call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/urlmap.rb:58:in `each'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/urlmap.rb:58:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/puma-5.5.2/lib/puma/configuration.rb:249:in `call'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/puma-5.5.2/lib/puma/request.rb:77:in `block in handle_request'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/puma-5.5.2/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/puma-5.5.2/lib/puma/request.rb:76:in `handle_request'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/puma-5.5.2/lib/puma/server.rb:447:in `process_client'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/puma-5.5.2/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
 64fe6b85 | /opt/theforeman/tfm/root/usr/share/gems/gems/logging-2.3.0/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
2022-09-19T15:46:57 [W|app|64fe6b85] Rolling back due to a problem: [#<Orchestration::Task:0x0000000014eb0280 @name="Refresh Content Host Statuses for host.example.com", @id="refresh_content_host_status_7459", @status="failed", @priority=300, @action=[#<Host::Managed id: 7459, name: "host.example.com", last_compile: nil, last_report: nil, updated_at: "2022-09-19 13:42:47", created_at: "2022-09-19 13:42:47", root_pass: nil, architecture_id: 1, operatingsystem_id: 25, ptable_id: nil, medium_id: nil, build: false, comment: nil, disk: nil, installed_at: "2022-09-19 13:46:54", model_id: nil, hostgroup_id: 281, owner_id: 5, owner_type: "User", enabled: true, puppet_ca_proxy_id: nil, managed: true, use_image: nil, image_file: nil, uuid: "50012d0b-c089-aaa1-2b1e-91e7c70c0a92", compute_resource_id: 5, puppet_proxy_id: nil, certname: nil, image_id: 2, organization_id: 8, location_id: 2, type: "Host::Managed", otp: nil, realm_id: nil, compute_profile_id: 8, provision_method: "image", grub_pass: nil, global_status: 0, lookup_value_matcher: [FILTERED], pxe_loader: nil, initiated_at: nil, build_errors: nil, expired_on: nil>, :refresh_content_host_status], @created=1663595217.8452818, @timestamp=2022-09-19 13:46:57.881528257 UTC>]
2022-09-19T15:46:57 [W|app|64fe6b85] Failed to set Build on host.example.com: ["Refresh Content Host Statuses for host.example.com task failed with the following error: undefined method `security' for nil:NilClass\nDid you mean?  secure_token"]
2022-09-19T15:46:57 [I|app|64fe6b85] Completed 409 Conflict in 3349ms (ActiveRecord: 409.4ms | Allocations: 1602006)
1 Like

It would be really great if someone could try to help here. We are getting this error with about every Windows server installation.

This looks like a bug to me. It’s trying to refresh all the content statuses without first checking to see if the host has content.

I’ve filed Bug #35683: Content host status refreshed even for hosts without content - Katello - Foreman

1 Like

I have applied the patch from Fixes #35683 - check for content facet before refreshing content host statuses by jeremylenz · Pull Request #10353 · Katello/katello · GitHub to our Foreman instaces, the error has not re-occured since then.
Thanks for the help :slight_smile:

1 Like