refactor: move Packer templates to top-level packer/ directory

This commit is contained in:
2026-02-25 20:51:20 -06:00
parent b51cd1a868
commit 75e0d99495
36 changed files with 0 additions and 40 deletions

View File

@@ -0,0 +1,32 @@
# AGENTS.md file
## Project overview
- Hashicorp Packer files to build Ubuntu 24.04.03 tmeplate VMs for Proxmox
- Cloudinit is used to configure the OS
## Code style guidelines
- Proxmox variables are set in proxmox.pkrvrs.hcl
- General OS variables are set in ubuntu-24.04.pkrvars.hcl
- VM specific variables are set in vm-[<size>].pkrvars.hcl
## Dev environment tips
## Program excecution
```bash
packer build -var-file ./ubuntu-24.04.pkrvars.hcl \
-var-file ./proxmox.pkrvars.hcl \
-var-file ./vm-small.pkrvars.hcl \
-var 'ssh_password=<ssh_password>' \
-var 'proxmox_password=<proxmox_password>' .
```
## Testing instructions
## PR instructions
- Title format: [<project_name>] <Title>
## Security considerations

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 eaksel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1 @@
datasource_list: [ConfigDrive, NoCloud]

View File

@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINnSM/9fO8rz/amqkyoGUzUKNNzzmtSXPwOCr1O9zKNO ansible

View File

@@ -0,0 +1,74 @@
# Kickstart file for Fedora 41 Server (Text-based Installation)
#
# For use with the Fedora Server netinstall ISO.
# Boot the installer with:
# linux /isolinux/vmlinuz inst.ks=http://<server>/<path>/ks.cfg
#
# For a local file on a USB drive, you can use:
# linux /isolinux/vmlinuz inst.ks=hd:LABEL=<USB_LABEL>:/ks.cfg
# Use text mode install
text
# Disable Initial Setup on first boot
firstboot --disable
# Keyboard layout
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Installation source
url --mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=fedora-42&arch=x86_64
# Network information
network --bootproto=dhcp --device=link --activate
network --hostname=fedora.localdomain
# Root password
rootpw $5$CXpezfLKTajPP7yI$VM8STd3QaHBTKMe2DLTmK5p.lEGbUYYZV8jGG3nxX2/ --iscrypted
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
skipx
# System timezone
timezone US/Chicago --utc
# Add a user named wed
user --groups=wheel --name=wed --password=$5$UOpZHG55fWCHlNSp$nFnpaVLb9enbQTebHo4SKBqolGr39SMYo2ZshHCe2d3 --iscrypted --gecos="wed"
# System bootloader configuration
bootloader --location=mbr --append="crashkernel=auto"
# Clear the Master Boot Record
zerombr
# Remove partitions
clearpart --all --initlabel
# Automatically create partitions using LVM
autopart --type=lvm
# Reboot after successful installation
reboot
%packages --ignoremissing
qemu-guest-agent
python3-libdnf5
#Make sure that this package gets installed because if you use DHCP this is how Promxox and then Packer will know the IP address to connect to
#@^Infrastructure Server
%end
%post --nochroot --logfile=/mnt/sysimage/root/ks-post.log
# Disable quiet boot and splash screen
sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/etc/default/grub
sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/boot/grub2/grubenv
# Passwordless sudo for the user 'wed'
echo "wed ALL=(ALL) NOPASSWD: ALL" >> /mnt/sysimage/etc/sudoers.d/wed
%end

View File

View File

@@ -0,0 +1,51 @@
#cloud-config
autoinstall:
version: 1
source:
id: ubuntu-server
ssh:
install-server: true
allow-pw: true
disable_root: true
# ssh_quiet_keygen: true
# allow_public_ssh_keys: true
ssh_pwauth: true
locale: en_US.UTF-8
keyboard:
layout: us
refresh-installer:
update: true
packages:
- qemu-guest-agent
- chrony
storage:
layout:
name: lvm # direct
policy: all
# swap:
# filename: /swap.img
# size: auto
user-data:
disable_root: true
package_upgrade: false
timezone: America/Chicago
users:
- name: wed
primary-group: users
groups: sudo
lock_passwd: false # true
passwd: "$6$KuJJYQtKFO02HoEG$AzpYknAjxx1E7LqH.T3eZou5rgQ2RTkxstHwuRaXflT6ZN2NPPS0SiD/F.KdZmz4A3/OR2VNmfoSzuoYwzdfT."
shell: /bin/bash
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINnSM/9fO8rz/amqkyoGUzUKNNzzmtSXPwOCr1O9zKNO ansible
sudo: ALL=(ALL) NOPASSWD:ALL
shutdown: reboot

View File

@@ -0,0 +1,41 @@
#cloud-config
autoinstall:
version: 1
early-commands:
# Stop ssh for packer
- sudo systemctl stop ssh
locale: en_US
keyboard:
layout: us
identity:
hostname: ubuntu-server
username: wed
password: '$1$Cc71g3Aa$WUMTLZg7B94dhHdxT7J/P/'
ssh:
install-server: yes
allow-pw: yes
storage:
layout:
name: lvm
apt:
geoip: true
primary:
- arches: [i386, amd64]
uri: "http://archive.ubuntu.com/ubuntu"
# packages:
# - curl
# - unzip
# - openssh-server
# - util-linux-extra
# - qemu-guest-agent
# - cloud-init
user-data:
disable_root: false
late-commands:
- sed -i -e 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config
- sed -i -e 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config
- echo 'wed ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/wed
- curtin in-target --target=/target -- vmware-toolbox-cmd config set deployPkg enable-custom-scripts true
- curtin in-target --target=/target -- chmod 440 /etc/sudoers.d/wed
- curtin in-target --target=/target -- apt-get update
- curtin in-target --target=/target -- apt-get upgrade --yes

View File

@@ -0,0 +1,14 @@
##################################################################################
# VARIABLES
##################################################################################
# Credentials
proxmox_username = "root@pam"
# Proxmox Objects
proxmox_node = "fantasyland"
proxmox_domain = "local.mk-labs.cloud"
proxmox_vm_storage_pool = "templates"
#proxmox_insecure_connection = false # Default: true
proxmox_iso_storage_pool = "local"

View File

@@ -0,0 +1,12 @@
#!/bin/bash -eux
pip uninstall -y ansible
dnf clean all
# Zero out the rest of the free space using dd, then delete the written file.
#dd if=/dev/zero of=/EMPTY bs=1M
#rm -f /EMPTY
# Add `sync` so Packer doesn't quit too early, before the large file is deleted.
sync

View File

@@ -0,0 +1,51 @@
---
- name: "Setup.yml"
hosts: localhost
gather_facts: yes
become: yes
tasks:
- name: Colorize root shell prompt
lineinfile:
path: /root/.bashrc
line: 'export PS1="\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h:\[$(tput sgr0)\]\[\033[38;5;6m\][\w]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"'
state: present
- name: Alias vi to vim
lineinfile:
path: /root/.bashrc
line: "alias vi='vim'"
state: present
- name: Create vim configuration file
file:
path: /root/.vimrc
state: touch
owner: root
group: root
mode: 0644
- name: Configure vim
blockinfile:
path: /root/.vimrc
block: |
set nocompatible
set number
set autoindent
syntax on
highlight Comment ctermfg=LightCyan
marker: ""
state: present
- name: Disable GSSAPIAuthentication
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^GSSAPIAuthentication"
line: "GSSAPIAuthentication no"
state: present
- name: Update CA bundle (RedHat)
get_url:
url: https://curl.haxx.se/ca/cacert.pem
dest: /etc/pki/tls/certs/ca-bundle.crt
force: yes
when: ansible_os_family == "RedHat"

View File

@@ -0,0 +1,136 @@
##################################################################################
# LOCALS
##################################################################################
# Reminder to disable the firewall before starting (or allow port 8543)
# sudo systemctl stop firewalld
locals {
buildtime = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
}
packer {
required_plugins {
ansible = {
version = ">= 1.1.3"
source = "github.com/hashicorp/ansible"
}
name = {
version = ">= 1.2.3"
source = "github.com/hashicorp/proxmox"
}
}
}
##################################################################################
# SOURCE
##################################################################################
source "proxmox-iso" "ubuntu-2404" {
boot_iso {
type = "scsi"
iso_file = "${var.proxmox_iso_storage_pool}:iso/${var.iso_file}"
unmount = true
iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum}"
}
os = "l26"
bios = "ovmf"
vm_id = "${var.vm_id}"
efi_config {
efi_storage_pool = "${var.proxmox_vm_storage_pool}"
efi_type = "4m"
#pre_enrolled_keys = true
}
# VM Cloud-Init Settings
cloud_init = true
cloud_init_storage_pool = "${var.proxmox_vm_storage_pool}"
boot_command = [
"<esc><wait>",
"e<wait>",
"<down><down><down><end>",
"<bs><bs><bs><bs><wait>",
"autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ---<wait>",
"<f10><wait>"
]
boot = "c"
boot_wait = "5s"
# PACKER Autoinstall Settings
http_directory = "./http"
# (Optional) Bind IP Address and Port
# http_bind_address = "10.1.149.166"
http_port_min = 8543
http_port_max = 8543
sockets = "${var.vm_cpu_sockets}"
cores = "${var.vm_cpu_cores}"
cpu_type = "host"
# machine = "q35"
memory = "${var.vm_mem_size}"
scsi_controller = "virtio-scsi-single"
disks {
storage_pool = "${var.proxmox_vm_storage_pool}"
disk_size = "${var.vm_disk_size}G"
}
network_adapters {
model = "virtio"
bridge = "${var.proxmox_bridge}"
# vlan_tag = "${var.proxmox_vlan}"
firewall = "true"
}
node = "${var.proxmox_node}"
username = "${var.proxmox_username}"
password = "${var.proxmox_password}"
proxmox_url = "https://${var.proxmox_node}.${var.proxmox_domain}:8006/api2/json"
ssh_timeout = "15m"
ssh_username = "${var.ssh_username}"
ssh_password = "${var.ssh_password}"
ssh_private_key_file = "${var.ssh_private_key}"
template_description = "Ubuntu 24.04.3, generated on ${timestamp()}"
template_name = "${var.vm_name}"
}
##################################################################################
# BUILD
##################################################################################
# inline = ["dnf -y update", "dnf -y install python-pip", "python3 -m pip install --upgrade pip", "alternatives --set python /usr/bin/python3", "pip3 install ansible"]
build {
sources = ["source.proxmox-iso.ubuntu-2404"]
# name = "ubuntu-24.04.3"
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
provisioner "shell" {
inline = [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"sudo rm /etc/ssh/ssh_host_*",
"sudo truncate -s 0 /etc/machine-id",
"sudo apt -y autoremove --purge",
"sudo apt -y clean",
"sudo apt -y autoclean",
"sudo cloud-init clean",
"sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
"sudo rm -f /etc/netplan/00-installer-config.yaml",
"sudo sync"
]
}
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
provisioner "file" {
source = "files/99-pve.cfg"
destination = "/tmp/99-pve.cfg"
}
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #3
provisioner "shell" {
inline = [ "sudo cp /tmp/99-pve.cfg /etc/cloud/cloud.cfg.d/99-pve.cfg" ]
}
}

View File

@@ -0,0 +1,9 @@
##################################################################################
# VARIABLES
##################################################################################
# ISO Objects
iso_file = "ubuntu-24.04.3-live-server-amd64.iso"
iso_checksum = "c3514bf0056180d09376462a7a1b4f213c1d6e8ea67fae5c25099c6fd3d8274b"
iso_checksum_type = "sha256"

View File

@@ -0,0 +1,151 @@
# Proxmox variable definitions
variable "proxmox_username" {
type = string
description = "The username for authenticating to Proxmox."
default = ""
sensitive = true
}
variable "proxmox_password" {
type = string
description = "The plaintext password for authenticating to Proxmox."
default = ""
sensitive = true
}
variable "proxmox_node" {
type = string
description = "The Proxmox node to store the templates on."
default = ""
}
variable "proxmox_domain" {
type = string
description = "The domain the Proxmox node resizes in."
default = ""
}
variable "proxmox_insecure_verify" {
type = bool
description = "If true, does not validate the proxmox server's TLS certificate."
default = true
}
variable "proxmox_vm_storage_pool" {
type = string
description = "The storage pool where the VM will live."
default = ""
}
# Virtual Machine variables
variable "vm_name" {
type = string
description = "The template vm name"
default = ""
}
variable "vm_id" {
type = number
description = "The ID of virtual machine."
}
variable "vm_cpu_sockets" {
type = number
description = "The number of virtual CPUs sockets."
default = "1"
}
variable "vm_cpu_cores" {
type = number
description = "The number of virtual CPUs cores per socket."
default = "1"
}
variable "vm_mem_size" {
type = number
description = "The size for the virtual memory in MB."
}
variable "vm_disk_size" {
type = number
description = "The size of the primary virtual disk in GiB."
}
variable "proxmox_bridge" {
type = string
description = "The Proxmox bridge the NIC connects to."
}
#variable "proxmox_vlan" {
# type = number
# description = "The VLAN the NIC is on."
#}
variable "vm_boot_wait" {
type = string
description = "The time to wait before boot (in seconds)."
default = ""
}
variable "shell_scripts" {
type = list(string)
description = "A list of scripts."
default = []
}
# ISO Objects
variable "proxmox_iso_storage_pool" {
type = string
description = "The storage pool where the ISO is located."
default = ""
}
variable "iso_url" {
type = string
description = "The url to retrieve the iso image"
default = ""
}
variable "iso_file" {
type = string
description = "The file name of the guest operating system ISO image installation media."
default = ""
}
variable "iso_checksum" {
type = string
description = "The checksum of the ISO image."
default = ""
}
variable "iso_checksum_type" {
type = string
description = "The checksum type of the ISO image. Ex: sha256"
default = ""
}
# SSH info
variable "ssh_username" {
type = string
description = "The username to use to authenticate over SSH."
default = ""
sensitive = true
}
variable "ssh_password" {
type = string
description = "The plaintext password to use to authenticate over SSH."
default = ""
sensitive = true
}
variable "ssh_private_key" {
type = string
description = "The private key to use to authenticate over SSH."
default = ""
sensitive = true
}

View File

@@ -0,0 +1,18 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "ubuntu-24.04-large-plus"
vm_id = "9204"
vm_cpu_sockets = "1"
vm_cpu_cores = "4"
vm_mem_size = "4096"
vm_disk_size = "48"
proxmox_bridge = "vmbr0"
#proxmox_vlan = "71"
ssh_username = "wed"

View File

@@ -0,0 +1,18 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "ubuntu-24.04-large"
vm_id = "9203"
vm_cpu_sockets = "1"
vm_cpu_cores = "4"
vm_mem_size = "4096"
vm_disk_size = "32"
proxmox_bridge = "vmbr0"
#proxmox_vlan = "71"
ssh_username = "wed"

View File

@@ -0,0 +1,18 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "ubuntu-24.04-medium"
vm_id = "9202"
vm_cpu_sockets = "1"
vm_cpu_cores = "2"
vm_mem_size = "4096"
vm_disk_size = "16"
proxmox_bridge = "vmbr0"
#proxmox_vlan = "71"
ssh_username = "wed"

View File

@@ -0,0 +1,17 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "ubuntu-24.04-small"
vm_id = "9201"
vm_cpu_sockets = "1"
vm_cpu_cores = "2"
vm_mem_size = "2048"
vm_disk_size = "8"
proxmox_bridge = "vmbr0"
ssh_username = "wed"

View File

@@ -0,0 +1,18 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "ubuntu-24.04-xlarge-plus"
vm_id = "9206"
vm_cpu_sockets = "1"
vm_cpu_cores = "4"
vm_mem_size = "8192"
vm_disk_size = "128"
proxmox_bridge = "vmbr0"
#proxmox_vlan = "71"
ssh_username = "wed"

View File

@@ -0,0 +1,18 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "ubuntu-24.04-xlarge"
vm_id = "9205"
vm_cpu_sockets = "1"
vm_cpu_cores = "4"
vm_mem_size = "8192"
vm_disk_size = "64"
proxmox_bridge = "vmbr0"
#proxmox_vlan = "71"
ssh_username = "wed"