From 4530601f15277a906e8fce411487f856996bfa20 Mon Sep 17 00:00:00 2001 From: Matt Reeves Date: Sat, 2 Nov 2024 01:50:25 -0400 Subject: [PATCH] fix up things --- packer/ubuntu-jammy/files/pve.cfg | 1 - .../files/.zshrc | 6 +- .../ubuntu-noble.pkr.hcl} | 35 ++++++---- .../ubuntu-noble2.pkr.hcl} | 55 +++++++++++----- terraform/adguard.tf | 64 ------------------- terraform/cloud-init.tf | 11 +--- terraform/secrets.tfvars | 15 ----- ...tu22-template2.tf => ubuntu-noble-base.tf} | 16 ++--- ...tu22-template.tf => ubuntu-noble-base2.tf} | 18 +++--- terraform/{vars.tf => variables.tf} | 0 10 files changed, 85 insertions(+), 136 deletions(-) delete mode 100644 packer/ubuntu-jammy/files/pve.cfg rename packer/{ubuntu-jammy => ubuntu-noble}/files/.zshrc (74%) rename packer/{ubuntu-jammy/ubuntu-jammy.pkr.hcl => ubuntu-noble/ubuntu-noble.pkr.hcl} (76%) rename packer/{ubuntu-jammy/ubuntu-jammy2.pkr.hcl => ubuntu-noble/ubuntu-noble2.pkr.hcl} (51%) delete mode 100644 terraform/adguard.tf delete mode 100644 terraform/secrets.tfvars rename terraform/{ubuntu22-template2.tf => ubuntu-noble-base.tf} (50%) rename terraform/{ubuntu22-template.tf => ubuntu-noble-base2.tf} (50%) rename terraform/{vars.tf => variables.tf} (100%) diff --git a/packer/ubuntu-jammy/files/pve.cfg b/packer/ubuntu-jammy/files/pve.cfg deleted file mode 100644 index a78672c..0000000 --- a/packer/ubuntu-jammy/files/pve.cfg +++ /dev/null @@ -1 +0,0 @@ -datasource_list: [ConfigDrive, NoCloud] \ No newline at end of file diff --git a/packer/ubuntu-jammy/files/.zshrc b/packer/ubuntu-noble/files/.zshrc similarity index 74% rename from packer/ubuntu-jammy/files/.zshrc rename to packer/ubuntu-noble/files/.zshrc index 4eb8d56..292180c 100644 --- a/packer/ubuntu-jammy/files/.zshrc +++ b/packer/ubuntu-noble/files/.zshrc @@ -10,12 +10,12 @@ plugins=(git ubuntu copypath copyfile dirhistory zsh-interactive-cd docker docke source $ZSH/oh-my-zsh.sh -# Set up Oh My Posh -eval "$(oh-my-posh init zsh --config https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/sonicboom_dark.omp.json)" +# Set up Oh My Posh Theme +eval "$(oh-my-posh init zsh --config /home/mafyuh/.oh-my-posh/themes/sonicboom_dark.omp.json)" # Custom aliases alias dcd="docker compose down" alias dcu="docker compose up -d" # Display system information -neofetch +fastfetch diff --git a/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl b/packer/ubuntu-noble/ubuntu-noble.pkr.hcl similarity index 76% rename from packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl rename to packer/ubuntu-noble/ubuntu-noble.pkr.hcl index 4611b6a..be31d33 100644 --- a/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl +++ b/packer/ubuntu-noble/ubuntu-noble.pkr.hcl @@ -21,7 +21,7 @@ variable "proxmox_api_token_secret" { } # Resource Definiation for the VM Template -source "proxmox-clone" "ubuntu-server-jammy" { +source "proxmox-clone" "ubuntu-server-noble" { # Proxmox Connection Settings proxmox_url = "${var.proxmox_api_url}" @@ -32,12 +32,12 @@ source "proxmox-clone" "ubuntu-server-jammy" { # VM General Settings node = "pve2" - ## See https://git.mafyuh.dev/mafyuh/iac/src/branch/main/terraform/ubuntu22-template2.tf - clone_vm_id = "8101" + + clone_vm_id = "8102" - vm_id = "9999" - vm_name = "ubuntu-server-jammy" - template_description = "Custom Ubuntu Server see https://git.mafyuh.dev/mafyuh/iac/src/branch/main/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl" + vm_id = "9997" + vm_name = "ubuntu-noble-template" + template_description = "Ubuntu Server Noble" # VM System Settings qemu_agent = true @@ -46,7 +46,7 @@ source "proxmox-clone" "ubuntu-server-jammy" { scsi_controller = "virtio-scsi-pci" disks { - disk_size = "4G" + disk_size = "5G" format = "raw" storage_pool = "Fast500Gb" type = "virtio" @@ -75,8 +75,8 @@ source "proxmox-clone" "ubuntu-server-jammy" { build { - name = "ubuntu-server-jammy" - sources = ["source.proxmox-clone.ubuntu-server-jammy"] + name = "ubuntu-server-noble" + sources = ["source.proxmox-clone.ubuntu-server-noble"] ## Cleanup for re-template provisioner "shell" { @@ -88,6 +88,8 @@ build { "sudo apt -y clean", "sudo apt -y autoclean", "sudo cloud-init clean", + "sudo rm -f /var/lib/dbus/machine-id", + "sudo rm -f /var/lib/systemd/random-seed", "sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg", "sudo rm -f /etc/netplan/00-installer-config.yaml", "sudo sync" @@ -103,20 +105,31 @@ build { inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ] } - # Install commonly used things - add alias's - set git config + provisioner "shell" { inline = [ - "sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common qemu-guest-agent net-tools zsh neofetch fzf", + # Install packages and add repositories + "sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch", + "sudo apt-get update", + "sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common net-tools zsh fastfetch fzf", + # Change default shell to zsh "sudo chsh -s $(which zsh) mafyuh", + # Install Docker "curl -fsSL https://get.docker.com | sudo sh", + # Install Oh My Zsh and plugins "sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\" --unattended", "git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting", "git clone https://github.com/zsh-users/zsh-autosuggestions.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions", "git clone https://github.com/zsh-users/zsh-history-substring-search.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-history-substring-search", "git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/you-should-use", + # Install Oh My Posh "mkdir -p /home/mafyuh/.local/bin", "curl -fsSL https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -o /home/mafyuh/.local/bin/oh-my-posh", "sudo chmod +x /home/mafyuh/.local/bin/oh-my-posh", + # Download posh theme locally + "mkdir -p /home/mafyuh/.oh-my-posh/themes", + "curl -fsSL https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/sonicboom_dark.omp.json -o /home/mafyuh/.oh-my-posh/themes/sonicboom_dark.omp.json", + # Setup Git "git config --global user.name \"Mafyuh\"", "git config --global user.email \"matt@mafyuh.com\"", "sudo apt-get -y update" diff --git a/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl b/packer/ubuntu-noble/ubuntu-noble2.pkr.hcl similarity index 51% rename from packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl rename to packer/ubuntu-noble/ubuntu-noble2.pkr.hcl index 3d40ae2..1dc84ac 100644 --- a/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl +++ b/packer/ubuntu-noble/ubuntu-noble2.pkr.hcl @@ -21,7 +21,7 @@ variable "proxmox_api_token_secret" { } # Resource Definiation for the VM Template -source "proxmox-clone" "ubuntu-server-jammy2" { +source "proxmox-clone" "ubuntu-server-noble2" { # Proxmox Connection Settings proxmox_url = "${var.proxmox_api_url}" @@ -32,11 +32,12 @@ source "proxmox-clone" "ubuntu-server-jammy2" { # VM General Settings node = "prox" - clone_vm_id = "8100" + + clone_vm_id = "8103" - vm_id = "9998" - vm_name = "ubuntu-server-jammy2" - template_description = "Custom Ubuntu Server see https://git.mafyuh.dev/mafyuh/iac/src/branch/main/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl" + vm_id = "9996" + vm_name = "ubuntu-noble-template" + template_description = "Ubuntu Server Noble" # VM System Settings qemu_agent = true @@ -45,7 +46,7 @@ source "proxmox-clone" "ubuntu-server-jammy2" { scsi_controller = "virtio-scsi-pci" disks { - disk_size = "4G" + disk_size = "5G" format = "raw" storage_pool = "Fast2Tb" type = "virtio" @@ -74,8 +75,8 @@ source "proxmox-clone" "ubuntu-server-jammy2" { build { - name = "ubuntu-server-jammy2" - sources = ["source.proxmox-clone.ubuntu-server-jammy2"] + name = "ubuntu-server-noble" + sources = ["source.proxmox-clone.ubuntu-server-noble2"] ## Cleanup for re-template provisioner "shell" { @@ -87,33 +88,57 @@ build { "sudo apt -y clean", "sudo apt -y autoclean", "sudo cloud-init clean", + "sudo rm -f /var/lib/dbus/machine-id", + "sudo rm -f /var/lib/systemd/random-seed", "sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg", "sudo rm -f /etc/netplan/00-installer-config.yaml", "sudo sync" ] } - provisioner "file" { source = "files/pve.cfg" destination = "/tmp/pve.cfg" } - provisioner "shell" { inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ] } - # Install Commonly Used Things - add alias's - set git config + provisioner "shell" { inline = [ - "sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common qemu-guest-agent net-tools", + # Install packages and add repositories + "sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch", + "sudo apt-get update", + "sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common net-tools zsh fastfetch fzf", + # Change default shell to zsh + "sudo chsh -s $(which zsh) mafyuh", + # Install Docker "curl -fsSL https://get.docker.com | sudo sh", - "echo \"alias dcu='docker compose up -d'\" >> ~/.bashrc", - "echo \"alias dcd='docker compose down'\" >> ~/.bashrc", + # Install Oh My Zsh and plugins + "sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\" --unattended", + "git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting", + "git clone https://github.com/zsh-users/zsh-autosuggestions.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions", + "git clone https://github.com/zsh-users/zsh-history-substring-search.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-history-substring-search", + "git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/you-should-use", + # Install Oh My Posh + "mkdir -p /home/mafyuh/.local/bin", + "curl -fsSL https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -o /home/mafyuh/.local/bin/oh-my-posh", + "sudo chmod +x /home/mafyuh/.local/bin/oh-my-posh", + # Download posh theme locally + "mkdir -p /home/mafyuh/.oh-my-posh/themes", + "curl -fsSL https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/sonicboom_dark.omp.json -o /home/mafyuh/.oh-my-posh/themes/sonicboom_dark.omp.json", + # Setup Git "git config --global user.name \"Mafyuh\"", "git config --global user.email \"matt@mafyuh.com\"", "sudo apt-get -y update" ] } -} \ No newline at end of file + + provisioner "file" { + source = "files/.zshrc" + destination = "~/.zshrc" + } + +} diff --git a/terraform/adguard.tf b/terraform/adguard.tf deleted file mode 100644 index c837599..0000000 --- a/terraform/adguard.tf +++ /dev/null @@ -1,64 +0,0 @@ -resource "proxmox_virtual_environment_vm" "Adguard" { - - # VM General Settings - node_name = "prox" - vm_id = 206 - name = "Adguard" - description = "DNS Server" - tags = ["tofu", "ubuntu24", "auto-homelab-repo", "infrastructure"] - - agent { - enabled = false # read 'Qemu guest agent' section, change to true only when ready - } - - clone { - vm_id = 8002 - } - - # VM CPU Settings - cpu { - cores = 2 - type = "host" - architecture = "x86_64" - } - - # VM Memory Settings - memory { - dedicated = 2048 - } - - # VM Network Settings - network_device { - bridge = "vmbr0" - } - - # VM Disk Settings - disk { - datastore_id = "Fast2Tb" - size = 60 - interface = "scsi0" - } - - vga { - type = "serial0" - } - - initialization { - ip_config { - ipv4 { - address = "dhcp" - } - } - - user_account {} - } - - lifecycle { - ignore_changes = [ - initialization[0].user_account[0].keys, - initialization[0].user_account[0].password, - initialization[0].user_account[0].username, - ] - } - -} diff --git a/terraform/cloud-init.tf b/terraform/cloud-init.tf index e5f2125..1e13e62 100644 --- a/terraform/cloud-init.tf +++ b/terraform/cloud-init.tf @@ -24,14 +24,9 @@ resource "proxmox_virtual_environment_file" "cloud_config" { sudo: ALL=(ALL) NOPASSWD:ALL runcmd: - apt update - - apt install -y qemu-guest-agent net-tools nfs-common + - apt upgrade -y - timedatectl set-timezone America/New_York - - systemctl enable qemu-guest-agent - - systemctl start qemu-guest-agent - - curl -fsSL https://get.docker.com | sudo sh - su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac' - - su - mafyuh -c 'git config --global user.name "Mafyuh"' - - su - mafyuh -c 'git config --global user.email "matt@mafyuh.com"' - echo "done" > /tmp/cloud-config.done EOF @@ -60,10 +55,8 @@ resource "proxmox_virtual_environment_file" "cloud_config2" { sudo: ALL=(ALL) NOPASSWD:ALL runcmd: - apt update - - timedatectl set-timezone America/New_York - - systemctl enable qemu-guest-agent - - systemctl start qemu-guest-agent - apt upgrade -y + - timedatectl set-timezone America/New_York - su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac' - echo "done" > /tmp/cloud-config.done EOF diff --git a/terraform/secrets.tfvars b/terraform/secrets.tfvars deleted file mode 100644 index ff7e4e1..0000000 --- a/terraform/secrets.tfvars +++ /dev/null @@ -1,15 +0,0 @@ -arrbuntu_ip_address = "" -downloaders_ip_address = "" -init_password = "" -kasm_ip = "" -kasm_ssh_ip = "" -npm_ip_address = "" -prox_ip_address = "" -pve2_ip_address = "" -s3_endpoint = "" -ssh_password = "" -ssh_username = "" -ubu_ip_address = "" -virtual_environment_api = "" -virtual_environment_endpoint = "" -vlan_gateway = "" diff --git a/terraform/ubuntu22-template2.tf b/terraform/ubuntu-noble-base.tf similarity index 50% rename from terraform/ubuntu22-template2.tf rename to terraform/ubuntu-noble-base.tf index b4efe46..1291210 100644 --- a/terraform/ubuntu22-template2.tf +++ b/terraform/ubuntu-noble-base.tf @@ -1,16 +1,18 @@ -resource "proxmox_virtual_environment_vm" "Ubuntu-22-Template2" { - name = "ubuntu-22" +resource "proxmox_virtual_environment_vm" "Ubuntu-Noble-Base" { + name = "ubuntu-noble-base" node_name = "pve2" - vm_id = 8101 - tags = ["tofu", "ubuntu-22"] + vm_id = 8102 + tags = ["tofu", "ubuntu24"] template = true started = false disk { datastore_id = "local-lvm" - file_id = "local:iso/jammy-server-cloudimg-amd64.img" + # See https://www.reddit.com/r/Proxmox/comments/1058ko7/comment/j3s4vli/ for how to inject qemu into base image + # virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent + file_id = "local:iso/noble-server-cloudimg-amd64.img" interface = "scsi0" - size = 4 + size = 5 } agent { @@ -23,8 +25,6 @@ resource "proxmox_virtual_environment_vm" "Ubuntu-22-Template2" { address = "dhcp" } } - - user_data_file_id = proxmox_virtual_environment_file.cloud_config2.id } serial_device {} diff --git a/terraform/ubuntu22-template.tf b/terraform/ubuntu-noble-base2.tf similarity index 50% rename from terraform/ubuntu22-template.tf rename to terraform/ubuntu-noble-base2.tf index 01cc16d..f720794 100644 --- a/terraform/ubuntu22-template.tf +++ b/terraform/ubuntu-noble-base2.tf @@ -1,16 +1,18 @@ -resource "proxmox_virtual_environment_vm" "Ubuntu-22-Template" { - name = "ubuntu-22" +resource "proxmox_virtual_environment_vm" "Ubuntu-Noble-Base2" { + name = "ubuntu-noble-base" node_name = "prox" - vm_id = 8100 - tags = ["tofu", "ubuntu-22"] + vm_id = 8103 + tags = ["tofu", "ubuntu24"] template = true started = false disk { datastore_id = "Fast2Tb" - file_id = "local:iso/jammy-server-cloudimg-amd64.img" + # See https://www.reddit.com/r/Proxmox/comments/1058ko7/comment/j3s4vli/ for how to inject qemu into base image + # virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent + file_id = "local:iso/noble-server-cloudimg-amd64.img" interface = "scsi0" - size = 4 + size = 5 } agent { @@ -23,8 +25,6 @@ resource "proxmox_virtual_environment_vm" "Ubuntu-22-Template" { address = "dhcp" } } - - user_data_file_id = proxmox_virtual_environment_file.cloud_config.id } serial_device {} @@ -43,5 +43,3 @@ cpu { architecture = "x86_64" } } - - diff --git a/terraform/vars.tf b/terraform/variables.tf similarity index 100% rename from terraform/vars.tf rename to terraform/variables.tf