Update vmcreate1.sh

This commit is contained in:
2025-10-22 19:46:54 +00:00
parent d4431e6517
commit 05dc7fd3b5

View File

@@ -32,6 +32,7 @@ embed_key(){
# #
} }
while getopts "a:f:h" opt; do while getopts "a:f:h" opt; do
case $opt in case $opt in
a) haadd=true ;; a) haadd=true ;;
@@ -41,7 +42,8 @@ while getopts "a:f:h" opt; do
esac esac
done done
cat ./hosts | while read line
cat $file | while read line
do do
ip=$(echo $line | cut -d ' ' -f 1) ip=$(echo $line | cut -d ' ' -f 1)
hostname=$(echo $line | cut -d ' ' -f 2) hostname=$(echo $line | cut -d ' ' -f 2)
@@ -60,13 +62,21 @@ do
qm set $vmnum --ipconfig0 ip=$ip/24,gw=10.10.35.1 qm set $vmnum --ipconfig0 ip=$ip/24,gw=10.10.35.1
qm cloudinit update $vmnum qm cloudinit update $vmnum
qm start $vmnum qm start $vmnum
# ДОБАВИТЬ правило HA если $haadd echo "VMs from $1 successfully created"
if [ haadd ]
then
ha-manager add vm:$vmnum --state started --max_relocate 2
ha-manager rules add node-affinity gfx-rule --resources vm:$vmnum --nodes pve1,pve2,pve3 --strict 1
# ОБЯЗАТЕЛЬНО ПРОВЕРИТЬ КОМАНДУ!!!
fi
echo "HA rules added"
done done
# Финальная часть
if [ -e hosts.tmp] if [ -e hosts.tmp]
then then
rm hosts.tmp rm hosts.tmp
fi fi
echo "VMs from 'hosts' successfully created"
if [ -v $privkey ] if [ -v $privkey ]
then then
echo "Generated private key $privkey" echo "Generated private key $privkey"