The problem:

  • We’ve just generated ova or ovf and vmdk files using Packer.
  • We need to upload the file(s) to vSphere and run the VM.
  • We want to use a docker container with ovftools.

The solution

Assumptions:

  • We have the ovftool docker image (I’ll describe the image in a separate post).
  • We have sufficient rights to upload ova files to a folder in vSphere host.
  • We have user name and password to login to vSphere host

Fragment of the Makefile:

[. . .]
DEPLOY         = ovftool --acceptAllEulas --overwrite --powerOffTarget
VI             = vi://$(VSPHERE_USER):$(VSPHERE_PASS)@labvcenter.dub.kloudtech.net/$(DATACENTER)/host/DUBLIN/$(VHOST)/
DEPLOY_VARS    = -ds=$(DATASTORE) -vf=$(VFOLDER) --network=$(NETWORK) -n=$(VM_NAME) $(OVF_TARGET) "$(VI)"
OVFTOOL_DEPLOY = $(DEPLOY) $(DEPLOY_VARS)

# deploy target
ddeploy:
    docker run --net="host" -ti --rm -v $(PWD):/opt/packer-vm -v $(PWD)/.ovftool.ssldb:/root/.ovftool.ssldb -w /opt/packer-vm ovftools:latest $(OVFTOOL_DEPLOY)

[. . .]

Running make:

$ make ddeploy DATASTORE=<my-datastore> NETWORK=<my-network-name> VHOST=<my-vsphere-host> DATACENTER=<my-data-center-name>