packer { required_plugins { qemu = { version = ">=1.0.0" source = "github.com/hashicorp/qemu" } } } variable "admin_username" { type = string } variable "admin_password_hash" { type = string sensitive = true } variable "admin_ssh_key" { type = string } variable "ansible_username" { type = string } variable "ansible_ssh_key" { type = string } variable "iso_url" { type = string default = "https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10-latest-x86_64-minimal.iso" } variable "iso_checksum" { type = string default = "sha256:de75c2f7cc566ea964017a1e94883913f066c4ebeb1d356964e398ed76cadd12" } source "qemu" "rocky10" { iso_url = var.iso_url iso_checksum = var.iso_checksum output_directory = "output-rocky10" shutdown_command = "shutdown -h now" format = "qcow2" disk_size = 20480 http_directory = "http" communicator = "ssh" ssh_username = "root" ssh_password = "HaveATemporaryPasswordHere" ssh_timeout = "20m" boot_wait = "20s" boot_command = [ "", "e", # edit boot entry "", # go to linux line end " inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg", " console=tty0 console=ttyS0,115200n8", " ip=dhcp", "" # boot with edited entry ] headless = true qemu_binary = "/usr/bin/qemu-system-x86_64" accelerator = "kvm" cpus = 2 memory = 2048 qemuargs = [ ["-serial", "file:serial.log"], ["-cpu", "host"], ["-display", "none"] ] } build { sources = ["source.qemu.rocky10"] provisioner "file" { source = "scripts/setup-admin-user.sh" destination = "/tmp/setup-admin-user.sh" } provisioner "file" { source = "scripts/setup-ansible-user.sh" destination = "/tmp/setup-ansible-user.sh" } # Run setup-admin-user.sh provisioner "shell" { inline = [ "chmod +x /tmp/setup-admin-user.sh", "/tmp/setup-admin-user.sh \"${var.admin_username}\" \"${var.admin_password_hash}\" \"${var.admin_ssh_key}\"" ] } provisioner "shell" { inline = [ "chmod +x /tmp/setup-ansible-user.sh", "/tmp/setup-ansible-user.sh \"${var.ansible_username}\" \"${var.ansible_ssh_key}\"" ] } }