Problem:
Looking through the logs it seems like every single POST to /api/hosts/facts results in the error:
(ActiveRecord::RecordInvalid): Validation failed: Name Operating system version already exists
Expected outcome:
Fact submission should not produce an error.
Foreman and Proxy versions:
3.12.0-develop
Foreman and Proxy plugin versions:
foreman_bootdisk: 21.2.3
foreman_puppet: 7.0.0
foreman_setup: 8.0.1
Distribution and version:
Ubuntu 22.04.4 LTS
Other relevant data:
I have seen previous mentions of this error from 2019, but that seemed to relate to Katello which we do not use.
An example from the logs:
2024-09-16T14:21:04 [I|app|7480b7fb] Started POST "/api/hosts/facts" for 172.31.84.205 at 2024-09-16 14:21:04 +0000
2024-09-16T14:21:04 [I|app|7480b7fb] Processing by Api::V2::HostsController#facts as JSON
2024-09-16T14:21:04 [I|app|7480b7fb] Parameters: {"facts"=>"[FILTERED]", "name"=>"******", "certname"=>"******", "apiv"=>"v2", "host"=>{"certname"=>"******", "name"=>"******"}}
2024-09-16T14:21:04 [W|app|7480b7fb] Some subtrees exceeded 100 limit of facts, dropped 646 keys
2024-09-16T14:21:07 [I|app|7480b7fb] Import facts for '******' completed. Added: 0, Updated: 75, Deleted 0 facts
2024-09-16T14:21:07 [W|app|7480b7fb] Action failed
2024-09-16T14:21:07 [I|app|7480b7fb] Backtrace for 'Action failed' error (ActiveRecord::RecordInvalid): Validation failed: Name Operating system version already exists
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/validations.rb:80:in `raise_validation_error'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/validations.rb:53:in `save!'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:302:in `block in save!'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:302:in `save!'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/suppressor.rb:48:in `save!'
7480b7fb | /usr/share/foreman/app/services/puppet_fact_parser.rb:40:in `operatingsystem'
7480b7fb | /usr/share/foreman/app/models/host/base.rb:169:in `block in set_non_empty_values'
7480b7fb | /usr/share/foreman/app/models/host/base.rb:168:in `each'
7480b7fb | /usr/share/foreman/app/models/host/base.rb:168:in `set_non_empty_values'
7480b7fb | /usr/share/foreman/app/models/host/base.rb:162:in `populate_fields_from_facts'
7480b7fb | /usr/share/foreman/app/models/host/managed.rb:472:in `populate_fields_from_facts'
7480b7fb | /usr/share/foreman/app/services/host_fact_importer.rb:56:in `block (2 levels) in parse_facts'
7480b7fb | /usr/share/foreman/app/services/foreman/telemetry_helper.rb:28:in `telemetry_duration_histogram'
7480b7fb | /usr/share/foreman/app/services/host_fact_importer.rb:55:in `block in parse_facts'
7480b7fb | /usr/share/foreman/app/services/host_fact_importer.rb:96:in `block in skipping_orchestration'
7480b7fb | /usr/share/foreman/app/models/concerns/orchestration.rb:124:in `without_orchestration'
7480b7fb | /usr/share/foreman/app/services/host_fact_importer.rb:95:in `skipping_orchestration'
7480b7fb | /usr/share/foreman/app/services/host_fact_importer.rb:51:in `parse_facts'
7480b7fb | /usr/share/foreman/app/services/host_fact_importer.rb:34:in `import_facts'
7480b7fb | /usr/share/foreman/app/controllers/api/v2/hosts_controller.rb:303:in `facts'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/abstract_controller/base.rb:228:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal/rendering.rb:30:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
7480b7fb | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in `set_timezone'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
7480b7fb | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
7480b7fb | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/audited-5.6.0/lib/audited/sweeper.rb:16:in `around'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/audited-5.6.0/lib/audited/sweeper.rb:16:in `around'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:137:in `run_callbacks'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/abstract_controller/callbacks.rb:41:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal/rescue.rb:22:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/notifications.rb:203:in `block in instrument'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/notifications.rb:203:in `instrument'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal/instrumentation.rb:33:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activerecord-6.1.7.8/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/abstract_controller/base.rb:165:in `process'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionview-6.1.7.8/lib/action_view/rendering.rb:39:in `process'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal.rb:190:in `dispatch'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_controller/metal.rb:254:in `dispatch'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/routing/route_set.rb:33:in `serve'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/routing/mapper.rb:49:in `serve'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/journey/router.rb:50:in `block in serve'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/journey/router.rb:32:in `each'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/journey/router.rb:32:in `serve'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/routing/route_set.rb:842:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/apipie-dsl-2.6.2/lib/apipie_dsl/static_dispatcher.rb:67:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/apipie-rails-1.4.0/lib/apipie/static_dispatcher.rb:74:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/static.rb:24:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/static.rb:24:in `call'
7480b7fb | /usr/share/foreman/lib/foreman/middleware/libvirt_connection_cleaner.rb:9:in `call'
7480b7fb | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/apipie-rails-1.4.0/lib/apipie/middleware/checksum_in_headers.rb:27:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/tempfile_reaper.rb:15:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/etag.rb:27:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/conditional_get.rb:40:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/head.rb:12:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/http/permissions_policy.rb:22:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/http/content_security_policy.rb:19:in `call'
7480b7fb | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/session/abstract/id.rb:266:in `context'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/session/abstract/id.rb:260:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/cookies.rb:697:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/callbacks.rb:98:in `run_callbacks'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/railties-6.1.7.8/lib/rails/rack/logger.rb:37:in `call_app'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/railties-6.1.7.8/lib/rails/rack/logger.rb:28:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/sprockets-rails-3.5.1/lib/sprockets/rails/quiet_assets.rb:17:in `call'
7480b7fb | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/request_id.rb:26:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/method_override.rb:24:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/runtime.rb:22:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/activesupport-6.1.7.8/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/executor.rb:14:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/sendfile.rb:110:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/ssl.rb:77:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/actionpack-6.1.7.8/lib/action_dispatch/middleware/host_authorization.rb:142:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/secure_headers-6.5.0/lib/secure_headers/middleware.rb:11:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/railties-6.1.7.8/lib/rails/engine.rb:539:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/railties-6.1.7.8/lib/rails/railtie.rb:207:in `public_send'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/railties-6.1.7.8/lib/rails/railtie.rb:207:in `method_missing'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/urlmap.rb:74:in `block in call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/urlmap.rb:58:in `each'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/rack-2.2.9/lib/rack/urlmap.rb:58:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/configuration.rb:272:in `call'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/request.rb:100:in `block in handle_request'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/thread_pool.rb:378:in `with_force_shutdown'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/request.rb:99:in `handle_request'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/server.rb:464:in `process_client'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/server.rb:245:in `block in run'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/puma-6.4.2/lib/puma/thread_pool.rb:155:in `block in spawn_thread'
7480b7fb | /usr/share/foreman/vendor/ruby/3.0.0/gems/logging-2.4.0/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
2024-09-16T14:21:07 [I|app|7480b7fb] Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (Duration: 0.3ms | Allocations: 74)
2024-09-16T14:21:07 [I|app|7480b7fb] Rendered layout api/v2/layouts/error_layout.json.erb (Duration: 0.4ms | Allocations: 141)
2024-09-16T14:21:07 [I|app|7480b7fb] Completed 500 Internal Server Error in 2750ms (Views: 1.5ms | ActiveRecord: 278.9ms | Allocations: 79503)