Update vmcreate.sh

This commit is contained in:
2025-10-28 15:11:07 +00:00
parent 72991247a5
commit 173b3c9bf8

View File

@@ -98,7 +98,7 @@ mksnippet () {
fi
if [ $password ]; then
phash=$(cat $password | mkpasswd -m sha-256 -s)
sed -i "s|.*password.*|password: ${phash}|" "$snippet"
sed -i "s|.*password.*|password: ${password}|" "$snippet"
fi
if [ $pubkey ]; then
sed -i "s|.*ssh-rsa.*| - $(cat ${pubkey})|" "$snippet"
@@ -246,12 +246,6 @@ do
fi
done
### DEBUG 1
echo "DEBUG cat hosts.tmp:"
cat hosts.tmp; echo
###
# Подготовительные операции закончены, приступаем к выполнению.
read -p "Script is ready to create $(cat hosts.tmp | wc -l) VMs. Press Enter"
@@ -270,16 +264,7 @@ do
hostname=$(echo -n $line | cut -d ';' -f 2)
vmid=$(get_vmid "$ip")
mksnippet
#### DEBUG 2
echo "IP: $ip"
echo "hostname: $hostname"
echo "VMID: $vmid"
echo "VLAN: $vlan"
echo "TAG: $tag"
echo "$snippet:"
cat "$snippet"
####
echo -n "Now cloning VM $vmnum from a template....."
echo -n "Now cloning VM $vmid from a template....."
qm clone 5000 $vmid --name $hostname --full > /dev/null
if [ $? -eq 0 ]; then
echo "OK"
@@ -294,10 +279,8 @@ do
sed -i "s|tag=35|tag=$vlan|" /etc/pve/qemu-server/${vmid}.conf
# sed -i "s|vmbr0|vmbr1|" /etc/pve/qemu-server/${vmid}.conf
qm cloudinit update $vmid
### DEBUG
echo "DEBUG: ${vmid}.conf"
cat /etc/pve/qemu-server/${vmid}.conf
###
echo "Snippet:"
cat $snippet
# # Migrate VM to target node
# echo -n "Migrating VM $vmid to pve${node}....."
# qm migrate $vmid pve${node} &&
@@ -307,12 +290,16 @@ do
# echo "ERROR"
# exit 9
# fi
# qm start $vmid ВРЕМЕННО ОТКЛЮЧЕНО
read -p "Press enter to start VM"
qm start $vmid &&
if [ $? -eq 0 ]; then
echo "VM ${vmid} started successfully"
fi
if [ $harule ]; then
ha-manager add vm:$vmid --state started --max_relocate 2
ha-manager rules add node-affinity $harule --resources vm:$vmid --nodes pve1,pve2,pve3 --strict 1
ha-manager add vm:$vmid --state started --max_relocate 2 &&
ha-manager rules add node-affinity $harule --resources vm:$vmid --nodes pve1,pve2,pve3 --strict 1 &&
echo "HA rule added"
# ОБЯЗАТЕЛЬНО ПРОВЕРИТЬ КОМАНДУ!!!
if [ $? -ne0 ]; then echo "Error creating HA rule"
fi
done