How to define dedicated ESX host to provision a VM on it (via Rest API)


I’m creating/provisioning Virtual machines via Foreman Rest API with vmware vcenter integration. Now i’m facing the problem, that in some cases i have to provision a vm to a dedicated ESXI host. I’m not able to find any doc about this topic.

Goal is to create a VM directly on a ESXi Host. (Because of customers requirements)

Foreman & Foreman Smart Proxy Version:

Currently my data for compute attributes looks like this:

“compute_attributes”: {
“cpus”: “2”,
“corespersocket”: “1”,
“memory_mb”: “2048”,
“firmware”: “efi”,
“cluster”: “SHARED/TEST”,
“resource_pool”: “Resources”,
“path”: “/Datencenter/DC1/Autoprovisioning”,
“guest_id”: “rhel8_64Guest”,
“hardware_version”: “Default”,
“memoryHotAddEnabled”: “1”,
“cpuHotAddEnabled”: “1”,
“add_cdrom”: “0”,
“boot_order”: [
“start”: “1”,
“annotation”: “”,
“scsi_controllers”: {
“scsiControllers”: [
“type”: “VirtualLsiLogicController”,
“key”: 1000
“volumes”: [
“thin”: true,
“name”: “Hard disk”,
“mode”: “persistent”,
“controllerKey”: 1000,
“sizeGb”: 30,
“storagePod”: “LIN_DS_TEST”,
“datastore”: null

Thanks in advanced.



I will build to an esxi host with Foreman and send you the json output. I will use the webui but it should still match up to what you are trying to do.

I think it is not possible as the vCenter thinks in Clusters, not Hosts and support for a single ESXi is not available, so you would need to have the structure in the vCenter. Out of curiosity: Why the restriction to a specific Host?

Thanks a lot!

We are running a strech cluster over multiple locations, but in some cases it is required to pin one vm on a dedicated location which requires to select a dedicated host. This is not the solution i prefer, but as this is currently implemented in this way, i have to stay on that solution.

Ok, so it is very likely that you have to do this after provisioning in the vCenter.

Or is something going to break provisioning already if started in the wrong location? If yes, as a workaround you could create the VM in advance, apply the restrictions and then provision on the already existing VM. This would mean a loss of comfort, but should work.

This is would be the way, if this does not work via Foreman call.
Either create the host in Foreman and move them afterwards via VCenter api to the correct host or create the vm and register them afterwards in Foreman.

I did look at the fog-vsphere code and there was a commit added to support just ESXi hosts, i’ll work on it this week as I have been able to build on one back with Foreman 2.x, have not tried in a while so maybe something changed.


I was able to connect to the esxi server as a compute resource, get it see vms, create a compute profile, but when I goto create a host, it fails with mac can't be blank. I can see the networks come back ok:

2022-08-16T10:47:30 [E|app|d889338f] VMW: args [  <Fog::Vsphere::Compute::Network
 d889338f |     id="HaNetwork-VM Network",
 d889338f |     name="VM Network",
 d889338f |     datacenter="ha-datacenter",
 d889338f |     accessible=true,
 d889338f |     virtualswitch=nil,
 d889338f |     vlanid=nil,
 d889338f |     _ref="HaNetwork-VM Network"
 d889338f |   >]

I know there was a lot of refactoring of networks in fog-vsphere to support NSX and to improve performance. I will file a redmine issue and link it here, in the meantime I would do your approach of:

Create the vm and register them afterwards in Foreman for the time being

Hi, thanks for all your comments. We have now solved in in this way, that we select a dedicated datastore which is either spreaded over multiple datacenters or has just a single location. With this option we do not need to select a host.
Thanks & BR