Compare commits
6 Commits
8266670f1d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a529df043 | ||
|
|
435ca041c0 | ||
|
|
f25c33eaca | ||
|
|
c99938e744 | ||
|
|
e038dcef97 | ||
|
|
0a32075220 |
@@ -1,44 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Function to get latest Fedora Rawhide image URL using a more reliable method
|
|
||||||
get_fedora_latest_rawhide_url() {
|
|
||||||
local base_url="https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud/x86_64/images/"
|
|
||||||
|
|
||||||
# Method 1: Try fetching the latest link from the directory
|
|
||||||
local temp_dir
|
|
||||||
temp_dir=$(mktemp -d)
|
|
||||||
|
|
||||||
# Download the HTML directory listing
|
|
||||||
if curl -s -o "$temp_dir/listing.html" "$base_url"; then
|
|
||||||
# Look for lines with qcow2 files that match our pattern
|
|
||||||
local latest_file
|
|
||||||
latest_file=$(grep -i "Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2" "$temp_dir/listing.html" | \
|
|
||||||
sort -r | head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
|
||||||
|
|
||||||
if [[ -n "$latest_file" ]]; then
|
|
||||||
echo "${base_url}${latest_file}"
|
|
||||||
else
|
|
||||||
# If we can't find a specific file, try to find any valid Fedora image
|
|
||||||
local any_file
|
|
||||||
any_file=$(grep -i "Fedora-Cloud-Base-Generic.*\.qcow2" "$temp_dir/listing.html" | \
|
|
||||||
head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
|
||||||
|
|
||||||
if [[ -n "$any_file" ]]; then
|
|
||||||
echo "${base_url}${any_file}"
|
|
||||||
else
|
|
||||||
# Return empty string if we can't find any valid file
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# If network fails, return empty string to skip Fedora download
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
rm -rf "$temp_dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Image URLs with dynamic Fedora URL handling
|
# Image URLs with dynamic Fedora URL handling
|
||||||
IMAGES=(
|
IMAGES=(
|
||||||
"https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
"https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
||||||
@@ -47,14 +8,9 @@ IMAGES=(
|
|||||||
"https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
"https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
||||||
"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||||
"https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2"
|
"https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2"
|
||||||
|
"https://download.fedoraproject.org/pub/fedora/linux/releases/43/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-43-1.6.x86_64.qcow2"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add Fedora image if we can get a valid URL
|
|
||||||
FEDORA_URL=$(get_fedora_latest_rawhide_url)
|
|
||||||
if [[ -n "$FEDORA_URL" ]]; then
|
|
||||||
IMAGES+=("$FEDORA_URL")
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Target directory
|
# Target directory
|
||||||
TARGET_DIR="/var/lib/libvirt/images"
|
TARGET_DIR="/var/lib/libvirt/images"
|
||||||
|
|
||||||
23
environments/fedora-cloud-server-43-bios/main.tf
Normal file
23
environments/fedora-cloud-server-43-bios/main.tf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">= 0.13"
|
||||||
|
required_providers {
|
||||||
|
libvirt = {
|
||||||
|
source = "dmacvicar/libvirt"
|
||||||
|
version = "0.8.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "libvirt" {
|
||||||
|
uri = "qemu+ssh://lukas@192.168.1.170/system"
|
||||||
|
}
|
||||||
|
|
||||||
|
module "shared_modules" {
|
||||||
|
source = "../../shared_modules"
|
||||||
|
|
||||||
|
vm_name = "f43-bios"
|
||||||
|
image_location = "https://download.fedoraproject.org/pub/fedora/linux/releases/43/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-43-1.6.x86_64.qcow2"
|
||||||
|
ssh_key = "" # please provide a SSH public key
|
||||||
|
enable_cloudinit = true
|
||||||
|
# disk_size_bytes = 101474836480
|
||||||
|
}
|
||||||
192
main_launcher.sh
Executable file
192
main_launcher.sh
Executable file
@@ -0,0 +1,192 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Main launcher script for terraform image management tools
|
||||||
|
# This script provides a menu interface to run the other scripts in proper order
|
||||||
|
|
||||||
|
# Function to display usage
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 [options]"
|
||||||
|
echo " options:"
|
||||||
|
echo " -h, --help Display this help message"
|
||||||
|
echo " -y, --yes Automatically answer 'yes' to all prompts"
|
||||||
|
echo " -n, --no Automatically answer 'no' to all prompts"
|
||||||
|
echo ""
|
||||||
|
echo "Example:"
|
||||||
|
echo " $0 # Interactive mode with default 'yes'"
|
||||||
|
echo " $0 -y # Non-interactive mode with auto 'yes'"
|
||||||
|
echo " $0 -n # Non-interactive mode with auto 'no'"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
AUTO_YES=false
|
||||||
|
AUTO_NO=false
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
-y|--yes)
|
||||||
|
AUTO_YES=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-n|--no)
|
||||||
|
AUTO_NO=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Function to get user confirmation
|
||||||
|
confirm() {
|
||||||
|
local prompt="$1"
|
||||||
|
local default="$2" # "yes" or "no"
|
||||||
|
|
||||||
|
if [[ "$AUTO_YES" = true ]]; then
|
||||||
|
echo "$prompt [Y/n]: yes"
|
||||||
|
return 0
|
||||||
|
elif [[ "$AUTO_NO" = true ]]; then
|
||||||
|
echo "$prompt [y/N]: no"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Default behavior - yes is default
|
||||||
|
if [[ "$default" = "no" ]]; then
|
||||||
|
echo -n "$prompt [y/N]: "
|
||||||
|
else
|
||||||
|
echo -n "$prompt [Y/n]: "
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -r answer
|
||||||
|
|
||||||
|
# If empty answer, use default
|
||||||
|
if [[ -z "$answer" ]]; then
|
||||||
|
answer="$default"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Convert to lowercase for comparison
|
||||||
|
answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
if [[ "$answer" = "y" || "$answer" = "yes" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if a script exists and is executable
|
||||||
|
check_script() {
|
||||||
|
local script="$1"
|
||||||
|
if [[ ! -f "$script" ]] || [[ ! -x "$script" ]]; then
|
||||||
|
echo "Error: Script '$script' not found or not executable"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to run a script with proper error handling
|
||||||
|
run_script() {
|
||||||
|
local script="$1"
|
||||||
|
local description="$2"
|
||||||
|
local args="$3"
|
||||||
|
|
||||||
|
echo "=== $description ==="
|
||||||
|
|
||||||
|
if check_script "$script"; then
|
||||||
|
if [[ -n "$args" ]]; then
|
||||||
|
echo "Running: $script $args"
|
||||||
|
"$script" "$args"
|
||||||
|
else
|
||||||
|
echo "Running: $script"
|
||||||
|
"$script"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local exit_code=$?
|
||||||
|
if [[ $exit_code -eq 0 ]]; then
|
||||||
|
echo "✓ $description completed successfully"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "✗ $description failed with exit code $exit_code"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "✗ $description skipped due to missing script"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if libvirt images directory exists
|
||||||
|
check_images_directory() {
|
||||||
|
local image_dir="/var/lib/libvirt/images"
|
||||||
|
|
||||||
|
if [[ ! -d "$image_dir" ]]; then
|
||||||
|
echo "Warning: Directory $image_dir does not exist"
|
||||||
|
if confirm "Would you like to create it?" "yes"; then
|
||||||
|
if ! sudo mkdir -p "$image_dir"; then
|
||||||
|
echo "Error: Could not create directory $image_dir"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
echo "Directory $image_dir created successfully"
|
||||||
|
else
|
||||||
|
echo "Skipping image directory check"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Directory $image_dir exists"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main execution logic
|
||||||
|
main() {
|
||||||
|
echo "=== Terraform Image Management Launcher ==="
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Validate image directory
|
||||||
|
if ! check_images_directory; then
|
||||||
|
echo "Exiting due to image directory issues"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Ask if user wants to download images
|
||||||
|
if confirm "Do you want to download OS images?" "yes"; then
|
||||||
|
if ! run_script "./download_images.sh" "Downloading OS Images"; then
|
||||||
|
echo "Image download failed. Proceeding to update script..."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Ask if user wants to update image locations
|
||||||
|
if confirm "Do you want to update image locations to use local files?" "yes"; then
|
||||||
|
if ! run_script "./update_image_locations.sh" "Updating Image Locations"; then
|
||||||
|
echo "Image location update failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Ask if user wants to update SSH keys
|
||||||
|
if confirm "Do you want to update SSH keys in terraform files?" "yes"; then
|
||||||
|
if ! run_script "./update_ssh_keys.sh" "Updating SSH Keys"; then
|
||||||
|
echo "SSH key update failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "=== All operations completed ==="
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main function if script is executed directly
|
||||||
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
@@ -16,6 +16,18 @@ variable "pool_path" {
|
|||||||
default = "/opt/tf_tmp_storage"
|
default = "/opt/tf_tmp_storage"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "disk_size_gb" {
|
||||||
|
description = "Disk size in GB"
|
||||||
|
type = number
|
||||||
|
default = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "disk_size_bytes" {
|
||||||
|
description = "Disk size in bytes"
|
||||||
|
type = number
|
||||||
|
default = 20 * 1024 * 1024 * 1024
|
||||||
|
}
|
||||||
|
|
||||||
variable "instance_count" {
|
variable "instance_count" {
|
||||||
description = "Number of instances to create"
|
description = "Number of instances to create"
|
||||||
type = number
|
type = number
|
||||||
|
|||||||
@@ -1,9 +1,25 @@
|
|||||||
resource "libvirt_volume" "vm_disk" {
|
# Base volume (template/parent)
|
||||||
count = var.instance_count
|
resource "libvirt_volume" "base_vm_image" {
|
||||||
name = "${var.vm_name}-${count.index}"
|
name = "${var.vm_name}-base"
|
||||||
pool = "${var.vm_name}-pool"
|
pool = "${var.vm_name}-pool"
|
||||||
source = var.image_location
|
source = var.image_location
|
||||||
format = "qcow2"
|
format = "qcow2"
|
||||||
|
|
||||||
depends_on = [libvirt_pool.tf_tmp_storage]
|
depends_on = [
|
||||||
|
libvirt_pool.tf_tmp_storage
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clone volume with resizable size
|
||||||
|
resource "libvirt_volume" "vm_disk" {
|
||||||
|
count = var.instance_count
|
||||||
|
name = "${var.vm_name}-${count.index}"
|
||||||
|
pool = "${var.vm_name}-pool"
|
||||||
|
format = "qcow2"
|
||||||
|
size = var.disk_size_bytes
|
||||||
|
base_volume_id = libvirt_volume.base_vm_image.id
|
||||||
|
|
||||||
|
depends_on = [
|
||||||
|
libvirt_volume.base_vm_image
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -89,6 +89,7 @@ create_original_url_mapping() {
|
|||||||
cat << 'EOF'
|
cat << 'EOF'
|
||||||
noble-server-cloudimg-amd64.img=https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
|
noble-server-cloudimg-amd64.img=https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
|
||||||
Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2=https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2
|
Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2=https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2
|
||||||
|
Fedora-Cloud-Base-Generic-43-1.6.x86_64.qcow2=https://download.fedoraproject.org/pub/fedora/linux/releases/43/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-43-1.6.x86_64.qcow2
|
||||||
openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2=https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2
|
openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2=https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2
|
||||||
Rocky-10-GenericCloud-Base.latest.x86_64.qcow2=https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2
|
Rocky-10-GenericCloud-Base.latest.x86_64.qcow2=https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2
|
||||||
debian-13-genericcloud-amd64.raw=https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw
|
debian-13-genericcloud-amd64.raw=https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw
|
||||||
Reference in New Issue
Block a user