Part1 : chef-server-prep-for-knife-vsphere-and-knife-esx-vcooking-my-vmware-kitchen can be accessed here:
kitchen.vlab.com – 192.168.242.89 – chef server
table.vlab.com – 192.168.242.90 – chef workstation
vc0.vlab.com – 172.16.209.133 – vCenter Server
vhosta.vlab.com – 172.16.209.128 – ESXi node
vhostb.vlab.com – 172.16.209.129 – 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 : https://github.com/maintux/knife-esx
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:
root@table:~/chef-repo/.chef# knife esx vm create --esx-host 172.16.209.129
INFO: Using configuration from /home/cannon/.chef/knife.rbConnecting to ESX host 172.16.209.129…
Creating VM UbuVMbyChef
Using template TemplateDeb4Chef.vmdk
VM Name: UbuVMbyChef
VM Memory: 512 MB
VM IP Address: 192.168.242.253
Waiting for sshd… …………… done
Connecting to 192.168.242.253
Can not find bootstrap definition for ubuntu10.04-gems
ERROR: Errno::ENOENT: No such file or directory
THIS WAS TOO SIMPLE TO BE TRUE!!!!
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: https://docs.chef.io/knife_bootstrap.html
Here’s vCenter view on newly created VM:
Issues / Notes:
I have found it difficult to attach a VM to network on Distribution Switch, I tested:
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:
ERROR: RbVmomi::Fault: NotAuthenticated:
More post to come.