|
| 1 | +#Generated by packer-kvm/build-packer-templates.yaml |
| 2 | + |
| 3 | +packer { |
| 4 | + required_plugins { |
| 5 | + qemu = { |
| 6 | + version = "~> 1" |
| 7 | + source = "github.com/hashicorp/qemu" |
| 8 | + } |
| 9 | + ansible = { |
| 10 | + version = ">= 1.1.2" |
| 11 | + source = "github.com/hashicorp/ansible" |
| 12 | + } |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +variable "config_file" { |
| 17 | + type = string |
| 18 | + default = "rocky10-kickstart.cfg" |
| 19 | +} |
| 20 | + |
| 21 | +variable "cpu" { |
| 22 | + type = string |
| 23 | + default = "2" |
| 24 | +} |
| 25 | + |
| 26 | +variable "destination_server" { |
| 27 | + type = string |
| 28 | + default = "download.goffinet.org" |
| 29 | +} |
| 30 | + |
| 31 | +variable "disk_size" { |
| 32 | + type = string |
| 33 | + default = "40000" |
| 34 | +} |
| 35 | + |
| 36 | +variable "headless" { |
| 37 | + type = string |
| 38 | + default = "true" |
| 39 | +} |
| 40 | + |
| 41 | +variable "iso_checksum" { |
| 42 | + type = string |
| 43 | + default = "file:https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10-latest-x86_64-boot.iso.CHECKSUM" |
| 44 | +} |
| 45 | + |
| 46 | +variable "iso_url" { |
| 47 | + type = string |
| 48 | + default = "https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10-latest-x86_64-boot.iso" |
| 49 | +} |
| 50 | + |
| 51 | +variable "name" { |
| 52 | + type = string |
| 53 | + default = "rocky" |
| 54 | +} |
| 55 | + |
| 56 | +variable "ram" { |
| 57 | + type = string |
| 58 | + default = "2048" |
| 59 | +} |
| 60 | + |
| 61 | +variable "ssh_password" { |
| 62 | + type = string |
| 63 | + default = "testtest" |
| 64 | +} |
| 65 | + |
| 66 | +variable "ssh_username" { |
| 67 | + type = string |
| 68 | + default = "root" |
| 69 | +} |
| 70 | + |
| 71 | +variable "version" { |
| 72 | + type = string |
| 73 | + default = "10" |
| 74 | +} |
| 75 | + |
| 76 | +source "qemu" "rocky10" { |
| 77 | + accelerator = "kvm" |
| 78 | + boot_command = ["e","<down><down>","<leftCtrlOn>e<leftCtrlOff>","<spacebar>","biosdevname=0","<spacebar>","net.ifnames=0","<spacebar>","inst.text","<spacebar>","inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/http/${var.config_file}","<leftCtrlOn>x<leftCtrlOff>"] |
| 79 | + disk_cache = "none" |
| 80 | + disk_compression = true |
| 81 | + disk_discard = "unmap" |
| 82 | + disk_interface = "virtio" |
| 83 | + disk_size = var.disk_size |
| 84 | + format = "qcow2" |
| 85 | + headless = var.headless |
| 86 | + http_directory = "." |
| 87 | + iso_checksum = var.iso_checksum |
| 88 | + iso_url = var.iso_url |
| 89 | + net_device = "virtio-net" |
| 90 | + output_directory = "artifacts/qemu/${var.name}${var.version}" |
| 91 | + qemu_binary = "/usr/bin/qemu-system-x86_64" |
| 92 | + qemuargs = [["-m", "${var.ram}M"], ["-smp", "${var.cpu}"], ["-cpu", "host"]] |
| 93 | + shutdown_command = "sudo /usr/sbin/shutdown -h now" |
| 94 | + ssh_password = var.ssh_password |
| 95 | + ssh_username = var.ssh_username |
| 96 | + ssh_wait_timeout = "30m" |
| 97 | + boot_wait = "10s" |
| 98 | +} |
| 99 | + |
| 100 | +build { |
| 101 | + sources = ["source.qemu.rocky10"] |
| 102 | + |
| 103 | + provisioner "shell" { |
| 104 | + execute_command = "{{ .Vars }} sudo -E bash '{{ .Path }}'" |
| 105 | + inline = ["dnf -y install python3 python3-pip", "pip3 install ansible"] |
| 106 | + } |
| 107 | + |
| 108 | + provisioner "ansible-local" { |
| 109 | + playbook_dir = "ansible" |
| 110 | + playbook_file = "ansible/playbook.yml" |
| 111 | + } |
| 112 | + |
| 113 | + post-processor "shell-local" { |
| 114 | + environment_vars = ["IMAGE_NAME=${var.name}", "IMAGE_VERSION=${var.version}", "DESTINATION_SERVER=${var.destination_server}"] |
| 115 | + script = "scripts/push-image.sh" |
| 116 | + } |
| 117 | +} |
0 commit comments