vSphere workflow example

Note: Support for workflows is experimental and subject to change

This example will demonstrate an installation of a series of VMWARE ESXI servers and their registration into a vCenter using the OS template concept and worklows.

We will be using the CLI for this and some familiarity with it is required. Please follow Using the CLI guide to setup the CLI.

Creating assets

  1. Download the ISO and upload the files to the repo
  2. Create a new asset for the bootloader (as an URL):
metalcloud-cli asset create --url "https://repointegration.bigstepcloud.com/.tftp/boot/uefi-esxi/bootx64.efi" --filename "esxi.efi" --mime "application/octet-stream" --usage "bootloader"
  1. Create a new boot.cfg file to configure the bootloader
bootstate=0
title=Loading ESXi installer
timeout=5
prefix=/images/ESXi
kernel=b.b00
kernelopt=ks=http://172.17.107.2/tftp8069/ks-01-mac.cfg ip=dhcp
modules=jumpstrt.gz --- useropts.gz --- features.gz --- k.b00 --- chardevs.b00 --- user.b00 --- procfs.b00 --- uc_intel.b00 --- uc_amd.b00 --- uc_hygon.b00 --- vmx.v00 --- vim.v00 --- sb.v00 --- s.v00 --- ata_liba.v00 --- ata_pata.v00 --- ata_pata.v01 --- ata_pata.v02 --- ata_pata.v03 --- ata_pata.v04 --- ata_pata.v05 --- ata_pata.v06 --- ata_pata.v07 --- block_cc.v00 --- bnxtnet.v00 --- bnxtroce.v00 --- brcmfcoe.v00 --- char_ran.v00 --- ehci_ehc.v00 --- elxiscsi.v00 --- elxnet.v00 --- hid_hid.v00 --- i40en.v00 --- iavmd.v00 --- igbn.v00 --- ima_qla4.v00 --- ipmi_ipm.v00 --- ipmi_ipm.v01 --- ipmi_ipm.v02 --- iser.v00 --- ixgben.v00 --- lpfc.v00 --- lpnic.v00 --- lsi_mr3.v00 --- lsi_msgp.v00 --- lsi_msgp.v01 --- lsi_msgp.v02 --- misc_cni.v00 --- misc_dri.v00 --- mtip32xx.v00 --- ne1000.v00 --- nenic.v00 --- net_bnx2.v00 --- net_bnx2.v01 --- net_cdc_.v00 --- net_cnic.v00 --- net_e100.v00 --- net_e100.v01 --- net_enic.v00 --- net_fcoe.v00 --- net_forc.v00 --- net_igb.v00 --- net_ixgb.v00 --- net_libf.v00 --- net_mlx4.v00 --- net_mlx4.v01 --- net_nx_n.v00 --- net_tg3.v00 --- net_usbn.v00 --- net_vmxn.v00 --- nfnic.v00 --- nhpsa.v00 --- nmlx4_co.v00 --- nmlx4_en.v00 --- nmlx4_rd.v00 --- nmlx5_co.v00 --- nmlx5_rd.v00 --- ntg3.v00 --- nvme.v00 --- nvmxnet3.v00 --- nvmxnet3.v01 --- ohci_usb.v00 --- pvscsi.v00 --- qcnic.v00 --- qedentv.v00 --- qfle3.v00 --- qfle3f.v00 --- qfle3i.v00 --- qflge.v00 --- sata_ahc.v00 --- sata_ata.v00 --- sata_sat.v00 --- sata_sat.v01 --- sata_sat.v02 --- sata_sat.v03 --- sata_sat.v04 --- scsi_aac.v00 --- scsi_adp.v00 --- scsi_aic.v00 --- scsi_bnx.v00 --- scsi_bnx.v01 --- scsi_fni.v00 --- scsi_hps.v00 --- scsi_ips.v00 --- scsi_isc.v00 --- scsi_lib.v00 --- scsi_meg.v00 --- scsi_meg.v01 --- scsi_meg.v02 --- scsi_mpt.v00 --- scsi_mpt.v01 --- scsi_mpt.v02 --- scsi_qla.v00 --- sfvmk.v00 --- shim_isc.v00 --- shim_isc.v01 --- shim_lib.v00 --- shim_lib.v01 --- shim_lib.v02 --- shim_lib.v03 --- shim_lib.v04 --- shim_lib.v05 --- shim_vmk.v00 --- shim_vmk.v01 --- shim_vmk.v02 --- smartpqi.v00 --- uhci_usb.v00 --- usb_stor.v00 --- usbcore_.v00 --- vmkata.v00 --- vmkfcoe.v00 --- vmkplexe.v00 --- vmkusb.v00 --- vmw_ahci.v00 --- xhci_xhc.v00 --- elx_esx_.v00 --- btldr.t00 --- esx_dvfi.v00 --- esx_ui.v00 --- esxupdt.v00 --- weaselin.t00 --- lsu_hp_h.v00 --- lsu_inte.v00 --- lsu_lsi_.v00 --- lsu_lsi_.v01 --- lsu_lsi_.v02 --- lsu_lsi_.v03 --- lsu_lsi_.v04 --- lsu_smar.v00 --- native_m.v00 --- qlnative.v00 --- rste.v00 --- vmware_e.v00 --- vsan.v00 --- vsanheal.v00 --- vsanmgmt.v00 --- tools.t00 --- xorg.v00 --- imgdb.tgz --- imgpayld.tgz
build=
updated=0
  1. Create a new asset with the bootloader config file boot.cfg file (as a text file). You can name th asset’s filename in any way you see fit. It will be mapped to the proper path later.
cat boot.cfg | metalcloud-cli asset create  --filename "esxiboot.cfg" --mime "text/plain" --pipe
  1. Create a new file to configure the install process: ks-01-mac.cfg
#### Tested with: ESXi 6.7

### Accept the VMware End User License Agreement
vmaccepteula

# Set the root password
rootpw Setup00!

# Clear paritions and install
clearpart --firstdisk --overwritevmfs
install --firstdisk --overwritevmfs

# Set the network to DHCP on the first network adapter
network --bootproto=dhcp --device=vmnic0

### Reboot ESXi Host
reboot --noeject

%firstboot --interpreter=busybox

# enable & start SSH
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

# enable & start ESXi Shell
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

# Suppress ESXi Shell warning
esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

%post --interpreter=python --ignorefailure=true
import time
stampFile = open('/finished.stamp', mode='w')
stampFile.write( time.asctime() )
  1. Create new asset (as a text file):
cat ks-01-mac.cfg | metalcloud-cli asset create --filename "ks-01-mac.cfg" --mime "text/plain" --pipe
  1. Create an OS template for ESXI.
metalcloud-cli template create --label esxi --name esxi --initial-password 'Setup00!' --template-architecture uefi --os-architecture x86 --os-type ESXi --os-version 1  --description "installs esxi" --initial-user "root"  --initial-ssh-port 22 --boot-type uefi-only --local-disk-supported
  1. Associate all assets to the template with their respective paths
metalcloud-cli asset associate --id 'bootx64.efi' --template_id esxi --path '/bootx64.efi'
metalcloud-cli asset associate --id 'esxiboot.cfg' --template_id esxi --path '/boot.cfg'
metalcloud-cli asset associate --id 'ks-01-mac.cfg' --template_id esxi --path '/ks-01-mac.cfg'
  1. Update the OS template to specify it’s bootloader for install
metalcloud-cli template update --id esxi --install_bootloader_asset 'bootx64.efi'

Configuring an instance array to install ESXI

  1. create an infrastructure
metalcloud-cli infrastructure create --dc us-santaclara --label vmware
  1. create an instance_array with the newly created template
metalcloud-cli instance-array create --infra vmware --template esxi --instance-count 1 --label esxi --boot local-drives
  1. View infrastructure
metalcloud-cli infrastructure get --id vmware
Infrastructure vmware (4144)
+-------+----------------+-----------+-----------------------------------------------------------------+---------+
| ID    | OBJECT_TYPE    | LABEL     | DETAILS                                                         | STATUS  |
+-------+----------------+-----------+-----------------------------------------------------------------+---------+
| 23883 | InstanceArray  | esxi      | 1 instances (1 RAM, 1 cores, 0 disks local_drives esxi4 [#50] ) | ordered |
+-------+----------------+-----------+-----------------------------------------------------------------+---------+
Total: 1 elements

Creating a stage definition for enroll into vCenter

Documentation for vCenter REST API is available here. We’re calling host create.

  1. Create a variable for the host of the vcenter
echo "https://172.17.108.75/" | metalcloud-cli variable create --name vcenter --pipe
  1. Create a secret for the credentials
echo "Basic YWRtaW5pc3RyYXRvckB2c3BoZXJlLmxvY2FsOkRlbGxSMGNrcyE=" | metalcloud-cli secret create --name vcenter-creds --pipe
  1. Create a stage definition to login
metalcloud-cli stage create --label "vcenter-login" --title "vcenter-login" --type "HTTPRequest" --http-request-method GET --http_request_url='{{vcenter}}/rest/com/vmware/cis/session' --vars "vcenter"
  1. Create a stage definition to add the host to the vmware. Notice the IP obtained from the context {{vmware_ipv4_address_0_0}}
echo '{{vmware_ipv4_address_0_0}}' | ./metalcloud-cli stage create --label "vcenter-host-add" --title "vcenter-host-add" --type "HTTPRequest" --http-request-method GET --http-request-url='{{vcenter}}/rest/vcenter/host' --http-request-header-authorization '{{vcenter_creds}}' --vars "vcenter,vcenter_creds,vmware_ipv4_0" --http-request-body-from-pipe

Create a workflow

$ metalcloud-cli workflow create --label "vmware" --title "Add host to vCenter" --usage infrastructure

Add stages to workflow

$ metalcloud-cli stage-definition add-to-workflow --id vcenter-login --workflow wmware --runlevel 1
$ metalcloud-cli stage-definition add-to-workflow --id 'vcenter-host-add' --workflow wmware --runlevel 2

Verify the stages

metalcloud-cli workflow list --id wmware
Stage Definitions:
+-------+---------------+------------------+-------------+----------+---------------------+
| ID    | INFRASTRUCTRE | STAGE            | TYPE        | RUNLEVEL | OUTPUT              |
+-------+---------------+------------------+-------------+----------+---------------------+
| 816   | wmware        | vcenter-login    | post_deploy | 1        |                     |
| 818   | wmware        | vcenter-host-add | post_deploy | 2        |                     |
+-------+---------------+------------------+-------------+----------+---------------------+
Total: 2 

Add workflow to infrastructure

We add the workflow to the infrastructure using a reference stage definition which instructs the system to call a workflow.

metalcloud-cli stage-definition create --title "ref VMWARE" --label refvmware --type WorkflowReference --workflow add-host-to-vcenter

Deploy infrastructure

metalcloud-cli infrastructure deploy --id wmware --autoconfirm