#!/bin/bash set -e # 1. Libvirt Volumes prüfen und ggf. löschen VOLUMES=("k3s-server-disk.qcow2" "k3s-agent-1-disk.qcow2" "k3s-agent-2-disk.qcow2" "k3s-common-init.iso" "fedora-cloud-base.qcow2") POOL="default" echo "Prüfe und lösche ggf. alte Libvirt-Volumes..." for vol in "${VOLUMES[@]}"; do if sudo virsh vol-list $POOL | grep -q "$vol"; then echo "Lösche Volume: $vol" sudo virsh vol-delete --pool $POOL "$vol" fi done # 2. OpenTofu initialisieren und anwenden echo "Initialisiere OpenTofu..." cd ./tofu rm -rf .terraform/ .terraform.lock.hcl terraform.tfstate terraform.tfstate.backup tofu.tfstate tofu.tfstate.backup tofu init echo "Plane Infrastruktur..." tofu plan echo "Wende Infrastruktur an..." tofu apply -auto-approve cd .. # 3. Ansible-Playbook if [ -f ./ansible/k3s_setup.yml ]; then echo "Starte K3s-Ansible-Playbook..." ansible-playbook -i ./ansible/inventory.ini ./ansible/k3s_setup.yml -e 'ansible_ssh_common_args="-o StrictHostKeyChecking=accept-new"' --ask-become-pass fi # 4. Kubeconfig setzen echo "Setze KUBECONFIG..." export KUBECONFIG=$(realpath ./kubeconfig) echo "KUBECONFIG ist gesetzt auf $KUBECONFIG" # 5. Flux Bootstrap echo "Starte Flux-Bootstrap..." echo $GIT_TOKEN flux bootstrap git \ --url=https://codeberg.org/Pata1704/homelab_gitops.git \ --branch=main \ --path=./clusters/production \ --token-auth echo "Cluster-Bootstrap abgeschlossen!"