-
Bug
-
Resolution: Duplicate
-
Major
-
None
-
6.18.0
-
False
-
Moderate
-
Satellite Rocket Sprint 3
-
sat-rocket
-
None
-
None
-
None
-
None
-
Yes
From community post:
I’m currently using Foreman 3.15 with a VMware vCenter compute resource.
I’m trying to provision a new host by cloning an existing VMware VM (not a template) using the “Image” provisioning method.
However, the provisioning fails with the following error:
undefined method `include?' for nil:NilClass
This appears to originate from the fog-vsphere plugin, specifically in the method get_vm_by_name in:
/usr/share/gems/gems/fog-vsphere-3.7.1/lib/fog/vsphere/requests/compute/get_virtual_machine.rb:40
The issue occurs because name is nil, and name.include?('/') is called without a check, causing a crash.
Expected behavior:
I expect Foreman to allow me to clone an existing VM (not a template) by specifying its name, and to handle this process gracefully without crashing if parameters are missing or misconfigured.
Steps to reproduce:
- In Foreman 3.15, go to Hosts > Create Host
- Use provision method = Image
- Select a compute profile and a VMware compute resource
- Fill in the VM settings (CPU, memory, disks, etc.)
- Attempt to submit the form without explicitly setting the “VM to clone”
Result:
The orchestration fails with:
025-08-06T18:41:07 [I|app|92eedfa1] Backtrace for 'Failed to create a compute VCenter xxxxxx (VMware) instance mysrv: undefined method `include?' for nil:NilClass 92eedfa1 | ' error (NoMethodError): undefined method `include?' for nil:NilClass 92eedfa1 | /usr/share/gems/gems/fog-vsphere-3.7.1/lib/fog/vsphere/requests/compute/get_virtual_machine.rb:40:in `get_vm_by_name' 92eedfa1 | /usr/share/gems/gems/fog-vsphere-3.7.1/lib/fog/vsphere/requests/compute/get_virtual_machine.rb:23:in `get_vm_ref' 92eedfa1 | /usr/share/gems/gems/fog-vsphere-3.7.1/lib/fog/vsphere/requests/compute/get_virtual_machine.rb:7:in `get_virtual_machine' 92eedfa1 | /usr/share/gems/gems/fog-vsphere-3.7.1/lib/fog/vsphere/requests/compute/vm_clone.rb:27:in `vm_clone_check_options' 92eedfa1 | /usr/share/gems/gems/fog-vsphere-3.7.1/lib/fog/vsphere/requests/compute/vm_clone.rb:111:in `vm_clone' 92eedfa1 | /usr/share/foreman/app/models/compute_resources/foreman/model/vmware.rb:608:in `clone_vm' 92eedfa1 | /usr/share/foreman/app/models/compute_resources/foreman/model/vmware.rb:516:in `create_vm' 92eedfa1 | /usr/share/foreman/app/models/concerns/orchestration/compute.rb:108:in `setCompute' 92eedfa1 | /usr/share/foreman/app/models/concerns/orchestration.rb:220:in `execute' 92eedfa1 | /usr/share/foreman/app/models/concerns/orchestration.rb:149:in `block in process' 92eedfa1 | /usr/share/foreman/app/models/concerns/orchestration.rb:141:in `each' 92eedfa1 | /usr/share/foreman/app/models/concerns/orchestration.rb:141:in `process' 92eedfa1 | /usr/share/foreman/app/models/concerns/orchestration.rb:41:in `around_save_orchestration' 92eedfa1 | /usr/share/gems/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:127:in `block in run_callbacks' 92eedfa1 | /usr/share/gems/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:138:in `run_callbacks' 92eedfa1 | /usr/share/gems/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:929:in `_run_save_callbacks' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/callbacks.rb:455:in `create_or_update' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/timestamp.rb:126:in `create_or_update' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/persistence.rb:615:in `save' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/validations.rb:47:in `save' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/transactions.rb:298:in `block in save' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status' 92eedfa1 | /usr/share/gems/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'