This tool automates clonning of a VM without the need of a VCenter by using the VMWare's VSphere/ESX command line interface.
Cloning a VM usually requires VCenter based on official documentation which means additional license (cost). This is a 'hack' way of cloning a template VM to a new VM in a fast, cost effective and quick fashion. You can run multiple clone processes to automate creating of multiple VMs from a single source template.
ESXi is built on the Linux kernel. And that gives us a lot of power and flexibility . All you need is ssh shell access and you can pretty much perform any task as you would on a linux box.
Cloning manually through ESXi GUI can be really cumbersome and time consuming process. This tool automates those tasks using ESX cli . It takes care of :
- Gathering VM datastore location
- creating target VM folder
- copying and customizing target VM files
- registering newly cloned VM with ESXi
- Login to ESXi with ssh
- Direct download to ESX shell :
wget -O clone-vm-esx.sh https://raw.githubusercontent.com/rizviz/clone-vm-esx/main/clone-vm.sh --no-check -certificate ; chmod +x clone-vm-esx.sh
- Clone desired VM e.g. :
sh clone-vm.sh ub22-template-v2 k8snode01
- Clone the repo
git clone https://github.com/rizviz/clone-vm-esx.git
- Copy the shell script to ESX host through scp
cd clone-vm-esx; scp clone-vm-esx.sh [email protected]
- Login to ESXi host with ssh
- Execute the shell script on the ESXi shell as :
sh clone-vm.sh <source_vm_name> <target_vm_name>
- Example:
sh clone-vm.sh ub22-template-v2 k8snode01
Once the cloning is complete , power up new VM and select "I Copied it" from the pop up menu on the ESXi client. Don't forget to change the hostname and IP of the target VM to avoid conflict with source VM configuration
Following are needed before installing : ESX SSH service enabled, SSH username/password , a template VM (or for that matter any VM you'd want to clone) and enough disk space in the datastore for cloning the VM.
- Cloning process is dependent on disk size and CPU/Mem of the ESX host. e.g. 8GB disk VM will take about 3-4 minutes but 32GB will take longer.
@rizviz
This project is licensed under the Apache License - see the LICENSE.md file for details