Chef integration with knife esx – My VMware Kitchen part2

Share This:


vmwarePart1 : chef-server-prep-for-knife-vsphere-and-knife-esx-vcooking-my-vmware-kitchen can be accessed here:

My environment: – – chef server – – chef workstation – – vCenter Server – – ESXi node – – ESXi node

After completing previous lab, we are ready to use knife esx and automatically provision Virtual Machine.

Think of scenario where customer visits on-demand portal where he enters VM specification and expects that resource to be available ASAP.

Of course you’ll store that information in some database.

You could use the information from that database to trigger chef knife esx to provision that resource, even better configure anything with chef using newly created node as a target for cookbooks.

Of course there is so much more to it, getting back to customer with connection details etc. But you get what I’m trying to say here. Hopefully 😀

First of all, create folder directory on one of your datastores and create template file you’d like to use. Note that it has to have vmware tools installed.

I have created simple Debian template called TemplateDeb4chef and copied it in to DatastoreA/templates/







Now is the time to have a look at knife-esx potential :

Part of the command line options (there’s more by running the command with help flag)

–vm-disk FILE The path to the VMDK disk file
–vm-name NAME The Virtual Machine name
–vm-cpus CPUS The Virtual Machine total number of virtual cpus (for the calculation see below) (default: 1)
–vm-cpu-cores CPU_CORES The number of cores per CPU socket. The number of sockets is calculated as <CPUS>=<SOCKETS>*<CPU_CORES> (default: 1)
–datastore NAME The Datastore to use for the VM files (default: datastore1)
–guest-id NAME The VM GuestID (default: otherGuest)
–vm-memory MEM The VM memory in MB (default: 512)
-N NAME | –node-name NAME The Chef node name for your new node
–prerelease Install the pre-release chef gems
–bootstrap-version VERSION The version of Chef to install
-d DISTRO | –distro DISTRO Bootstrap a distro using a template (default: ubuntu10.04-gems)
–template-file TEMPLATE Full path to location of template to use
–use-template NAME Try to use an existing template instead of importing disk
-r RUN_LIST | –run-list RUN_LIST Comma separated list of roles/recipes to apply
-j JSON_ATTRIBUTES | –json-attributes JSON_ATTRIBUTES A JSON string to be added to the first run of chef-client
-x USERNAME | –ssh-user USERNAME The ssh username (default: root)
-P PASSWORD | –ssh-password PASSWORD The ssh password
-G GATEWAY | –ssh-gateway GATEWAY The ssh password
-i IDENTITY_FILE | –identity-file IDENTITY_FILE The SSH identity file used for authentication
–no-host-key-verify Disable host key verification
–vm-network network[,network..] Network where nic is attached to (default: ‘VM Network’)
-M mac[,mac..] | –mac-address mac[,mac..] Mac address list
–skip-bootstrap Skip bootstrap process (Deploy only mode)
–async Deploy the VMs asynchronously (Ignored unless combined with –batch)
–batch script.yml Use a batch file to deploy multiple VMs

By looking at above parameters we can now start the sweet stuff:


INFO: Using configuration from /home/cannon/.chef/knife.rbConnecting to ESX host…

Creating VM UbuVMbyChef
Using template TemplateDeb4Chef.vmdk
Cloning template…
VM Created
VM Name: UbuVMbyChef
VM Memory: 512 MB

Waiting server…
VM IP Address:

Waiting for sshd… …………… done
Connecting to
Can not find bootstrap definition for ubuntu10.04-gems
ERROR: Errno::ENOENT: No such file or directory


Error??? Yes. Basically we haven’t provided a bootstrap file which is still left to created for the next lab. More information can be found here, this can be ignored for now:

Here’s vCenter view on newly created VM:
















Issues / Notes:

#Distributed Switch
I have found it difficult to attach a VM to network on Distribution Switch, I tested:
– Ext
– Ext[DSwitch]
-“Ext (DSwitch)”
After all had to go to vm and swap the network once it was deployed. – I’ll keep looking for answer on this.

#VM Template size
If the VM template size is too big , session with ESXi host get’s timeout and error is produced:
Cloning template…
ERROR: RbVmomi::Fault: NotAuthenticated:

More post to come.


2 thoughts on “Chef integration with knife esx – My VMware Kitchen part2

  1. Just wondering if you’d made any progress on figuring out how to get it to start the VM with the network enabled. It’s driving me insane having to go and manually enable it on every VM…kinda defeats the purpose of automation.

    I tried digging through the ESX API but didn’t really find anything useful for integrating with Chef to make it happen :/

  2. I agree, it works perfectly fine using standard switch, but I couldn’t get it going on Distributed switch and I moved on. As workaround I think I did trigger powershell script and use powercli to configure anything after this point. Syntax was more-less:
    (where $vm is the name of VM used in Chef configuration)
    $vm = get-vm
    $newPG = “dmz”
    get-vm $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $newPG -Confirm:$false

Leave a comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.