#!/bin/bash # Script to copy Ubuntu template from LINSTOR to local storage on each node # This is necessary because LINSTOR doesn't support cloning operations properly set -e TEMPLATE_VMID=9000 TEMPLATE_NAME="ubuntu-2404-cloudinit" SOURCE_STORAGE="linstor_storage" TARGET_STORAGE="local" NODES=("acemagician" "elitedesk" "thinkpad") echo "=== Copying template $TEMPLATE_NAME (VMID: $TEMPLATE_VMID) to local storage on each node ===" for node in "${NODES[@]}"; do echo "" echo "--- Processing node: $node ---" # Check if template already exists locally on this node if ssh root@$node "qm status $TEMPLATE_VMID &>/dev/null"; then echo "✓ Template already exists on $node" # Check if it's on local storage if ssh root@$node "qm config $TEMPLATE_VMID | grep -q 'local:'"; then echo "✓ Template is already on local storage" continue fi fi echo "→ Cloning template from LINSTOR to local storage on $node..." # Clone the template to local storage with a temporary VMID TEMP_VMID=$((TEMPLATE_VMID + 1000)) ssh root@$node "qm clone $TEMPLATE_VMID $TEMP_VMID \ --name ${TEMPLATE_NAME}-local \ --full \ --storage $TARGET_STORAGE \ --target $node" || { echo "✗ Failed to clone template on $node" continue } echo "✓ Template copied successfully to $node (VMID: $TEMP_VMID)" echo " Note: You can now use VMID $TEMP_VMID or rename to $TEMPLATE_VMID after removing the LINSTOR version" done echo "" echo "=== Template copy complete ===" echo "" echo "Next steps:" echo "1. Verify templates exist on each node: ssh root@ 'qm list'" echo "2. Update Terraform to use local templates or new VMIDs" echo "3. Optionally remove LINSTOR template after testing"