Overview
This page describes the process of automating the creation of new virtual machines (VMs) using Python scripts. The automation includes generating XML configuration files, copying disk images, and modifying fingerprints for enhanced security.
Prerequisites:
Python Environment: Ensure Python 3.x is installed.
Libraries: Install required Python libraries:
Location: DevOps Automation Scripts Repository
Steps:
Step-1
In the python script, some varibales that need to initialised for configuration of new virtual machine. the variables are
vm_count_per_emp=int(input("No of VMs per employee: "))
disk_image_path="/data1/guest-images"
guestname_to_be_cloned=""
startup_script_path=""
This python script is at the Devops Automation Scripts repository Link.
Section of Shell Script File Contents:
apt purge openssh-server -y
apt install openssh-server -y
systemctl restart ssh
systemctl status ssh
cp /etc/machine-id /etc/machind-id.bkp
cp /var/lib/dbus/machine-id /var/lib/dbus/machine-id.bkp
echo "mac-id" > /etc/machine-id
echo "mac-id" > /var/lib/dbus/machine-id
cp /etc/hosts /etc/hosts.bkp
# copy_disk("/path/to/source_disk.img", "/data1/guest-images/new_vm_disk.img")
Execute First Boot Script:
Run the above shell script at the VM’s first boot for initial setup.
Conclusion:
This documentation provides a structured approach to automate VM creation, leveraging Python for XML manipulation, disk operations, and security enhancements. Adjust scripts and configurations as per specific project requirements.