Associate single vm with hammer/api doesn't work

Problem:
I want to associate a single vm without GUI but it doesn’t work:

LANG=C hammer compute-resource associate-vms --id 4 --vm-id 500a83fc-33c0-83fe-4616-805246457669

Could not associate the virtual machines:
wrong number of arguments (given 1, expected 0)
(Used VMWare VM ID)
LANG=C hammer --debug compute-resource associate-vms --id 4 --vm-id 4222
[ERROR 2026-09-22T16:21:07 Exception] Resource compute_resource not found by id '4'
Could not associate the virtual machines:
Resource compute_resource not found by id '4'
[ERROR 2026-09-22T16:21:07 Exception]

[ ... ]
RestClient::NotFound (404 Not Found):
/usr/share/gems/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:249:in exception_with_response'     /usr/share/gems/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:129:in return!'
/usr/share/gems/gems/apipie-bindings-0.7.1/lib/apipie_bindings/api.rb:353:in block in rest_client_call_block'     /usr/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:834:in process_result'
/usr/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:743:in block in transmit'     /usr/share/ruby/net/http.rb:960:in start'
/usr/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:727:in transmit'     /usr/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:163:in execute'
/usr/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in execute'     /usr/share/gems/gems/rest-client-2.1.0/lib/restclient/resource.rb:79:in put'
/usr/share/gems/gems/apipie-bindings-0.7.1/lib/apipie_bindings/api.rb:327:in call_client'     /usr/share/gems/gems/apipie-bindings-0.7.1/lib/apipie_bindings/api.rb:240:in http_call'
/usr/share/gems/gems/apipie-bindings-0.7.1/lib/apipie_bindings/api.rb:190:in call_action'     /usr/share/gems/gems/apipie-bindings-0.7.1/lib/apipie_bindings/api.rb:185:in call'
/usr/share/gems/gems/apipie-bindings-0.7.1/lib/apipie_bindings/resource.rb:21:in call'     /usr/share/gems/gems/hammer_cli-3.19.0/lib/hammer_cli/apipie/command.rb:53:in send_request'
/usr/share/gems/gems/hammer_cli_foreman-3.19.0/lib/hammer_cli_foreman/commands.rb:180:in send_request'     /usr/share/gems/gems/hammer_cli-3.19.0/lib/hammer_cli/apipie/command.rb:34:in execute'
/usr/share/gems/gems/clamp-1.4.0/lib/clamp/command.rb:66:in run'     /usr/share/gems/gems/hammer_cli-3.19.0/lib/hammer_cli/abstract.rb:103:in run'
/usr/share/gems/gems/clamp-1.4.0/lib/clamp/subcommand/execution.rb:18:in execute'     /usr/share/gems/gems/clamp-1.4.0/lib/clamp/command.rb:66:in run'
/usr/share/gems/gems/hammer_cli-3.19.0/lib/hammer_cli/abstract.rb:103:in run'     /usr/share/gems/gems/clamp-1.4.0/lib/clamp/subcommand/execution.rb:18:in execute'
/usr/share/gems/gems/clamp-1.4.0/lib/clamp/command.rb:66:in run'     /usr/share/gems/gems/hammer_cli-3.19.0/lib/hammer_cli/abstract.rb:103:in run'
/usr/share/gems/gems/clamp-1.4.0/lib/clamp/command.rb:140:in run'     /usr/share/gems/gems/hammer_cli-3.19.0/bin/hammer:142:in <top (required)>'
/bin/hammer:25:in load'     /bin/hammer:25:in '
curl -k 'https://$(hostname -f)/api/compute_resources/11/associate/106' -X PUT -H "Content-Type: application/json" -u user

Enter host password for user 'user':
{
"error": {"message":"wrong number of arguments (given 1, expected 0)"}
}

grep 17222a29 production.log

2026-09-22T16:24:04 [I|app|17222a29] Started PUT "/api/compute_resources/11/associate/106" for  at 2026-09-22 16:24:04 +0200
2026-09-22T16:24:04 [I|app|17222a29] Processing by Api::V2::ComputeResourcesController#associate as JSON
2026-09-22T16:24:04 [I|app|17222a29]   Parameters: {"apiv"=>"v2", "id"=>"11", "vm_id"=>"106", "compute_resource"=>{}}
2026-09-22T16:24:05 [I|app|17222a29] ForemanWebhooks::EventSubscriber: user_updated.event.foreman event received
2026-09-22T16:24:06 [I|app|17222a29] ForemanWebhooks::EventSubscriber: user_updated.event.foreman event received
2026-09-22T16:24:06 [I|app|17222a29] Authorized user user(User)
2026-09-22T16:24:08 [W|app|17222a29] Action failed
2026-09-22T16:24:08 [I|app|17222a29] Backtrace for 'Action failed' error (ArgumentError): wrong number of arguments (given 1, expected 0)
17222a29 | /usr/share/gems/gems/foreman_fog_proxmox-0.24.0/app/services/concerns/foreman_fog_proxmox/compute_resource_host_associator.rb:27:in associate_hosts'  17222a29 | /usr/share/foreman/app/controllers/api/v2/compute_resources_controller.rb:206:in associate'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal/basic_implicit_render.rb:6:in send_action'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/abstract_controller/base.rb:215:in process_action'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal/rendering.rb:165:in process_action'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/abstract_controller/callbacks.rb:234:in block in process_action'
17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:118:in block in run_callbacks'  17222a29 | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:13:in rescue in set_timezone'
17222a29 | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:11:in set_timezone'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:127:in block in run_callbacks'
17222a29 | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in clear_thread'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:127:in block in run_callbacks'
17222a29 | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in set_topbar_sweeper_controller'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:127:in block in run_callbacks'
17222a29 | /usr/share/gems/gems/audited-5.8.0/lib/audited/sweeper.rb:16:in around'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:127:in block in run_callbacks'
17222a29 | /usr/share/gems/gems/audited-5.8.0/lib/audited/sweeper.rb:16:in around'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:127:in block in run_callbacks'
17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:138:in run_callbacks'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/abstract_controller/callbacks.rb:233:in process_action'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal/rescue.rb:23:in process_action'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal/instrumentation.rb:67:in block in process_action'
17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/notifications.rb:206:in block in instrument'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/notifications/instrumenter.rb:24:in instrument'
17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/notifications.rb:206:in instrument'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal/instrumentation.rb:66:in process_action'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal/params_wrapper.rb:259:in process_action'  17222a29 | /usr/share/gems/gems/activerecord-7.0.10/lib/active_record/railties/controller_runtime.rb:27:in process_action'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/abstract_controller/base.rb:151:in process'  17222a29 | /usr/share/gems/gems/actionview-7.0.10/lib/action_view/rendering.rb:39:in process'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal.rb:188:in dispatch'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_controller/metal.rb:251:in dispatch'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/routing/route_set.rb:49:in dispatch'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/routing/route_set.rb:32:in serve'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/routing/mapper.rb:18:in block in <class:Constraints>'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/routing/mapper.rb:48:in serve'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/journey/router.rb:50:in block in serve'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/journey/router.rb:32:in each'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/journey/router.rb:32:in serve'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/routing/route_set.rb:852:in call'
17222a29 | /usr/share/gems/gems/katello-4.21.0/lib/katello/middleware/organization_created_enforcer.rb:18:in call'  17222a29 | /usr/share/gems/gems/katello-4.21.0/lib/katello/middleware/event_daemon.rb:10:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'
17222a29 | /usr/share/gems/gems/apipie-dsl-2.6.2/lib/apipie_dsl/static_dispatcher.rb:67:in call'  17222a29 | /usr/share/gems/gems/apipie-rails-1.5.0/lib/apipie/static_dispatcher.rb:72:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/static.rb:23:in call'
17222a29 | /usr/share/foreman/lib/foreman/middleware/libvirt_connection_cleaner.rb:9:in call'  17222a29 | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in call'
17222a29 | /usr/share/gems/gems/apipie-rails-1.5.0/lib/apipie/middleware/checksum_in_headers.rb:27:in call'  17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/tempfile_reaper.rb:15:in call'
17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/etag.rb:27:in call'  17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/conditional_get.rb:40:in call'
17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/head.rb:12:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/http/permissions_policy.rb:38:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/http/content_security_policy.rb:39:in call'  17222a29 | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in call'
17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/session/abstract/id.rb:266:in context'  17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/session/abstract/id.rb:260:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/cookies.rb:704:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/callbacks.rb:27:in block in call'
17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/callbacks.rb:99:in run_callbacks'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/callbacks.rb:26:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/debug_exceptions.rb:28:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/show_exceptions.rb:29:in call'
17222a29 | /usr/share/gems/gems/railties-7.0.10/lib/rails/rack/logger.rb:40:in call_app'  17222a29 | /usr/share/gems/gems/railties-7.0.10/lib/rails/rack/logger.rb:27:in call'
17222a29 | /usr/share/gems/gems/sprockets-rails-3.5.2/lib/sprockets/rails/quiet_assets.rb:17:in call'  17222a29 | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/remote_ip.rb:93:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/request_id.rb:26:in call'
17222a29 | /usr/share/gems/gems/katello-4.21.0/lib/katello/prevent_json_parsing.rb:12:in call'  17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/method_override.rb:24:in call'
17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/runtime.rb:22:in call'  17222a29 | /usr/share/gems/gems/activesupport-7.0.10/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/executor.rb:14:in call'  17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/sendfile.rb:127:in call'
17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/ssl.rb:77:in call'  17222a29 | /usr/share/gems/gems/actionpack-7.0.10/lib/action_dispatch/middleware/host_authorization.rb:131:in call'
17222a29 | /usr/share/gems/gems/secure_headers-7.1.0/lib/secure_headers/middleware.rb:11:in call'  17222a29 | /usr/share/gems/gems/railties-7.0.10/lib/rails/engine.rb:531:in call'
17222a29 | /usr/share/gems/gems/railties-7.0.10/lib/rails/railtie.rb:226:in public_send'  17222a29 | /usr/share/gems/gems/railties-7.0.10/lib/rails/railtie.rb:226:in method_missing'
17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/urlmap.rb:74:in block in call'  17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/urlmap.rb:58:in each'
17222a29 | /usr/share/gems/gems/rack-2.2.23/lib/rack/urlmap.rb:58:in call'  17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/configuration.rb:279:in call'
17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/request.rb:99:in block in handle_request'  17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/thread_pool.rb:390:in with_force_shutdown'
17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/request.rb:98:in handle_request'  17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/server.rb:472:in process_client'
17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/server.rb:254:in block in run'  17222a29 | /usr/share/gems/gems/puma-6.6.1/lib/puma/thread_pool.rb:167:in block in spawn_thread'
17222a29 | /usr/share/gems/gems/logging-2.4.0/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
2026-09-22T16:24:08 [I|app|17222a29]   Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (Duration: 0.4ms | Allocations: 167)
2026-09-22T16:24:08 [I|app|17222a29]   Rendered layout api/v2/layouts/error_layout.json.erb (Duration: 0.5ms | Allocations: 262)
2026-09-22T16:24:08 [I|app|17222a29] Completed 500 Internal Server Error in 4300ms (Views: 1.2ms | ActiveRecord: 18.2ms | Allocations: 35102)

Expected outcome:
VM gets associated.

Foreman and Proxy versions:
foreman-3.19.1-1.el9.noarch
foreman-cli-3.19.1-1.el9.noarch

Foreman and Proxy plugin versions:

foreman-vmware-3.19.1-1.el9.noarch
rubygem-fog-proxmox-0.16.0-1.el9.noarch
rubygem-foreman_fog_proxmox-0.24.0-1.fm3_19.el9.noarch**
Distribution and version:
RHEL 9**

Other relevant data:

Am I doing something wrong?

The issue is in foreman_fog_proxmox. Hammer correctly sends the VM ID in the API request:

PUT /api/compute_resources/11/associate/106

Foreman then calls:

associator.associate_hosts([@vm])

However, the Proxmox plugin overrides this method without accepting any arguments:

def associate_hosts

This causes the following error:

wrong number of arguments (given 1, expected 0)

The plugin override should accept the optional VM collection:

def associate_hosts(vms = compute_resource.vms(:eager_loading => true))
  vms.each do |vm|
    associate_vm(vm) if Host.for_vm_uuid(compute_resource, vm).empty?
  end
end

Therefore, Hammer’s --vm-id handling appears to work correctly. The fix should be made in foreman_fog_proxmox so its associate_hosts override remains compatible with Foreman’s single-VM association API.

The separate Resource compute_resource not found by id '4' error is likely caused by an incorrect compute-resource ID or organization/location context.

File an issue in the project: Issues · theforeman/foreman_fog_proxmox · GitHub

Thank you so much for this very helpful answer. I will open an issue for foreman proxmox fog.
The vmware association only works after fixing the proxmox code.

Issue: