Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable callbacks for localhost-like entries #1527

Open
lcrownover opened this issue Nov 22, 2022 · 7 comments · May be fixed by #1529
Open

Option to disable callbacks for localhost-like entries #1527

lcrownover opened this issue Nov 22, 2022 · 7 comments · May be fixed by #1529

Comments

@lcrownover
Copy link

SUMMARY

Callback plugin works great when targets are nodes from an inventory (using foreman inventory). When running playbooks that use hosts: localhost (configuring foreman itself, or any playbook to be run locally), you end up with a localhost host object in Foreman that must be deleted. Every subsequent run adds another localhost host.

I'd like a way make localhost runs not report facts to foreman. Either built-in, or an ignore_host = <regex>-like option in the callback settings.

Thanks for all the work on this system!

ISSUE TYPE
  • Feature Idea
@evgeni
Copy link
Member

evgeni commented Nov 22, 2022

You can disable the callback using an environment variable:
https://github.com/theforeman/foreman-ansible-modules/blob/develop/plugins/callback/foreman.py#L104

Would that suffice?

@lcrownover
Copy link
Author

lcrownover commented Nov 22, 2022

That would technically accomplish the task, but ergonomically it's a pain.

On top of our team having to add FOREMAN_CALLBACK_DISABLE=1 to the beginning of each relevant ansible-playbook call, it would require them to remember or look inside each playbook before running to know if they need to disable the callback or not.

edit: I'm happy to take a stab at implementing this, doesn't look too complicated on first glance. Just wanted to report first to make sure my PR would even be considered.

@evgeni
Copy link
Member

evgeni commented Nov 28, 2022

So I must admit I don't like the idea that the filtering should happen in the callback, but I also do see how the existing solutions are not really optimal for you either.

Just to re-iterate, you can't set the create_new_host_when_facts_are_uploaded and create_new_host_when_report_is_uploaded settings in Foreman to false to completely disable the creation of new hosts, as you need that feature somewhere else? (That would be the most canonical solution from the Foreman side, IMHO).

From a bit of searching, I couldn't find a way to tell Ansible to filter things (read: not to execute the callback for that specific host at all) and also no other callback that handles "remote reporting" (like to a logging system or chat or whatever) does support filtering either :(

Should Foreman itself gain a "here is a list/regex/whatever that you should not create hosts for"? I'll ask @ares later when I see him.

@lcrownover
Copy link
Author

I wasn't aware of those two Foreman options, and at first glance they might work.

We manually create hosts with playbooks for bare-metal provisioning or subscription manager for existing hosts (I'm assuming this doesn't make use of dynamic host creation via facts/reports).

I do agree with you though, this sounds like something that Ansible should implement globally for callback plugins. I can totally see how I'd want the same feature on a logging callback.

I'll mull this over a few days and discuss with the team if we can think of any situations where we need the callback to create hosts. Thanks for the help.

@lcrownover
Copy link
Author

Coming back to this, the admin options are working fine, but I do receive this rather ugly warning:

[WARNING]: Sending data to Foreman at https://satellite.example.org failed for localhost: 500 Server Error: Internal Server Error for url:
https://satellite.example.org/api/v2/hosts/facts

I don't think that Ansible provides a global "ignore warnings" setting, and I can't think of a nice way to hide this error if it's working as intended. I wonder if maybe an ignore_warnings = <bool> might be useful on the callback plugin?

What do you think?

@evgeni
Copy link
Member

evgeni commented Nov 30, 2022

Ah, yes, the host doesn't exist and you try to submit facts for it, that makes sense.

To make sure, can you post the full traceback from /var/log/foreman/production.log?

@lcrownover
Copy link
Author

Absolutely:

2022-11-30T11:13:49 [I|app|57bca5fc] Started POST "/api/v2/hosts/facts" for 10.174.128.83 at 2022-11-30 11:13:49 -0800
2022-11-30T11:13:49 [I|app|57bca5fc] Processing by Api::V2::HostsController#facts as JSON
2022-11-30T11:13:49 [I|app|57bca5fc]   Parameters: {"name"=>"localhost", "facts"=>"[FILTERED]", "apiv"=>"v2", "host"=>{"name"=>"localhost"}}
2022-11-30T11:13:49 [W|app|57bca5fc] Action failed
2022-11-30T11:13:49 [I|app|57bca5fc] Backtrace for 'Action failed' error (RuntimeError): resource have no errors
 57bca5fc | /usr/share/foreman/app/controllers/api/base_controller.rb:156:in `process_resource_error'
 57bca5fc | /usr/share/foreman/app/controllers/api/base_controller.rb:176:in `process_response'
 57bca5fc | /usr/share/foreman/app/controllers/api/v2/hosts_controller.rb:311:in `facts'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/abstract_controller/base.rb:195:in `process_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal/rendering.rb:30:in `process_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:112:in `block in run_callbacks'
 57bca5fc | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in `set_timezone'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 57bca5fc | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 57bca5fc | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 57bca5fc | /usr/share/gems/gems/audited-4.9.0/lib/audited/sweeper.rb:14:in `around'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 57bca5fc | /usr/share/gems/gems/audited-4.9.0/lib/audited/sweeper.rb:14:in `around'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:139:in `run_callbacks'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/abstract_controller/callbacks.rb:41:in `process_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal/rescue.rb:22:in `process_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications.rb:180:in `block in instrument'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications.rb:180:in `instrument'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
 57bca5fc | /usr/share/gems/gems/activerecord-6.0.4.7/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/abstract_controller/base.rb:136:in `process'
 57bca5fc | /usr/share/gems/gems/actionview-6.0.4.7/lib/action_view/rendering.rb:39:in `process'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal.rb:190:in `dispatch'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_controller/metal.rb:254:in `dispatch'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/routing/route_set.rb:33:in `serve'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/routing/mapper.rb:48:in `serve'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/journey/router.rb:49:in `block in serve'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/journey/router.rb:32:in `each'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/journey/router.rb:32:in `serve'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/routing/route_set.rb:834:in `call'
 57bca5fc | /usr/share/gems/gems/katello-4.3.0.50/lib/katello/middleware/organization_created_enforcer.rb:18:in `call'
 57bca5fc | /usr/share/gems/gems/katello-4.3.0.50/lib/katello/middleware/event_daemon.rb:10:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/apipie-dsl-2.4.0/lib/apipie_dsl/static_dispatcher.rb:67:in `call'
 57bca5fc | /usr/share/gems/gems/apipie-rails-0.5.17/lib/apipie/static_dispatcher.rb:66:in `call'
 57bca5fc | /usr/share/gems/gems/apipie-rails-0.5.17/lib/apipie/extractor/recorder.rb:137:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/foreman/lib/foreman/middleware/libvirt_connection_cleaner.rb:9:in `call'
 57bca5fc | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in `call'
 57bca5fc | /usr/share/gems/gems/apipie-rails-0.5.17/lib/apipie/middleware/checksum_in_headers.rb:27:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/tempfile_reaper.rb:15:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/etag.rb:27:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/conditional_get.rb:40:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/head.rb:12:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
 57bca5fc | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:266:in `context'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:260:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/cookies.rb:654:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/callbacks.rb:101:in `run_callbacks'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
 57bca5fc | /usr/share/gems/gems/railties-6.0.4.7/lib/rails/rack/logger.rb:37:in `call_app'
 57bca5fc | /usr/share/gems/gems/railties-6.0.4.7/lib/rails/rack/logger.rb:28:in `call'
 57bca5fc | /usr/share/gems/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
 57bca5fc | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/request_id.rb:27:in `call'
 57bca5fc | /usr/share/gems/gems/katello-4.3.0.50/lib/katello/prevent_json_parsing.rb:12:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/method_override.rb:24:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/runtime.rb:22:in `call'
 57bca5fc | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/executor.rb:14:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/static.rb:126:in `call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/sendfile.rb:110:in `call'
 57bca5fc | /usr/share/gems/gems/actionpack-6.0.4.7/lib/action_dispatch/middleware/host_authorization.rb:97:in `call'
 57bca5fc | /usr/share/gems/gems/secure_headers-6.3.0/lib/secure_headers/middleware.rb:11:in `call'
 57bca5fc | /usr/share/gems/gems/railties-6.0.4.7/lib/rails/engine.rb:527:in `call'
 57bca5fc | /usr/share/gems/gems/railties-6.0.4.7/lib/rails/railtie.rb:190:in `public_send'
 57bca5fc | /usr/share/gems/gems/railties-6.0.4.7/lib/rails/railtie.rb:190:in `method_missing'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/urlmap.rb:74:in `block in call'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/urlmap.rb:58:in `each'
 57bca5fc | /usr/share/gems/gems/rack-2.2.3.1/lib/rack/urlmap.rb:58:in `call'
 57bca5fc | /usr/share/gems/gems/puma-5.6.2/lib/puma/configuration.rb:252:in `call'
 57bca5fc | /usr/share/gems/gems/puma-5.6.2/lib/puma/request.rb:77:in `block in handle_request'
 57bca5fc | /usr/share/gems/gems/puma-5.6.2/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
 57bca5fc | /usr/share/gems/gems/puma-5.6.2/lib/puma/request.rb:76:in `handle_request'
 57bca5fc | /usr/share/gems/gems/puma-5.6.2/lib/puma/server.rb:441:in `process_client'
 57bca5fc | /usr/share/gems/gems/puma-5.6.2/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
 57bca5fc | /usr/share/gems/gems/logging-2.3.0/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
2022-11-30T11:13:49 [I|app|57bca5fc]   Rendering api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout
2022-11-30T11:13:49 [I|app|57bca5fc]   Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (Duration: 5.6ms | Allocations: 335)
2022-11-30T11:13:49 [I|app|57bca5fc] Completed 500 Internal Server Error in 45ms (Views: 21.8ms | ActiveRecord: 2.8ms | Allocations: 10442)
2022-11-30T11:13:49 [I|app|424b4d93] Started POST "/api/v2/config_reports" for 10.174.128.83 at 2022-11-30 11:13:49 -0800
2022-11-30T11:13:49 [I|app|424b4d93] Processing by Api::V2::ConfigReportsController#create as JSON
2022-11-30T11:13:49 [I|app|424b4d93]   Parameters: {"config_report"=>"[FILTERED]", "apiv"=>"v2"}
2022-11-30T11:13:49 [I|app|424b4d93] skipping report for localhost as its an unknown host and create_new_host_when_report_is_uploaded setting is disabled
2022-11-30T11:13:49 [I|app|424b4d93]   Rendering api/v2/config_reports/create.json.rabl
2022-11-30T11:13:49 [I|app|424b4d93]   Rendered api/v2/config_reports/create.json.rabl (Duration: 17.4ms | Allocations: 6698)
2022-11-30T11:13:49 [I|app|424b4d93] Completed 201 Created in 67ms (Views: 20.3ms | ActiveRecord: 5.0ms | Allocations: 13172)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants