From 80b9360d05269d5092f70d3702557f8a0318af00 Mon Sep 17 00:00:00 2001 From: AJ Schroeder <6432150+ajschroeder@users.noreply.github.com> Date: Sat, 29 Jun 2024 10:43:05 -0500 Subject: [PATCH] feat: rocky 9 updates --- builds/linux/rocky/9/data/storage.pkrtpl.hcl | 2 +- .../rocky/9/linux-rocky.auto.pkrvars.hcl | 3 +- builds/linux/rocky/9/linux-rocky.pkr.hcl | 59 +++++++++++++------ builds/linux/rocky/9/variables.pkr.hcl | 2 +- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/builds/linux/rocky/9/data/storage.pkrtpl.hcl b/builds/linux/rocky/9/data/storage.pkrtpl.hcl index 2ec0342..b35af89 100644 --- a/builds/linux/rocky/9/data/storage.pkrtpl.hcl +++ b/builds/linux/rocky/9/data/storage.pkrtpl.hcl @@ -70,4 +70,4 @@ logvol %{ endif ~} %{ endfor ~} -%{ endfor ~} +%{ endfor ~} \ No newline at end of file diff --git a/builds/linux/rocky/9/linux-rocky.auto.pkrvars.hcl b/builds/linux/rocky/9/linux-rocky.auto.pkrvars.hcl index d4c34a4..06c6d33 100644 --- a/builds/linux/rocky/9/linux-rocky.auto.pkrvars.hcl +++ b/builds/linux/rocky/9/linux-rocky.auto.pkrvars.hcl @@ -13,9 +13,10 @@ vm_os_version = "9" // Virtual Machine Guest Operating System Setting vm_os_type = "l26" +vm_cloudinit = true // Virtual Machine Hardware Settings -vm_bios = "seabios" +vm_bios = "ovmf" vm_cpu_count = 1 vm_cpu_sockets = 1 vm_cpu_type = "x86-64-v2-AES" diff --git a/builds/linux/rocky/9/linux-rocky.pkr.hcl b/builds/linux/rocky/9/linux-rocky.pkr.hcl index 731ea55..4c9b15d 100644 --- a/builds/linux/rocky/9/linux-rocky.pkr.hcl +++ b/builds/linux/rocky/9/linux-rocky.pkr.hcl @@ -33,10 +33,32 @@ data "git-repository" "cwd" {} // Defines the local variables. locals { + + bios_boot_command = [ + "", + "", + " text ${local.data_source_command}", + "" + ] + + uefi_boot_command = [ + // This sends the "up arrow" key, typically used to navigate through boot menu options. + "", + // This sends the "e" key. In the GRUB boot loader, this is used to edit the selected boot menu option. + "e", + // This sends two "down arrow" keys, followed by the "end" key, and then waits. This is used to navigate to a specific line in the boot menu option's configuration. + "", + // This types the string "text" followed by the value of the 'data_source_command' local variable. + // This is used to modify the boot menu option's configuration to boot in text mode and specify the kickstart data source configured in the common variables. + "text ${local.data_source_command}", + // This sends the "enter" key, waits, turns on the left control key, sends the "x" key, and then turns off the left control key. This is used to save the changes and exit the boot menu option's configuration, and then continue the boot process. + "x" + ] + build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("DD-MM-YYYY hh:mm ZZZ", "${timestamp()}" ) build_version = data.git-repository.cwd.head - build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}\nCloud-Init: ${var.vm_cloud_init_enable}" + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}\nCloud-Init: ${var.vm_cloudinit}" vm_disk_type = var.vm_disk_type == "virtio" ? "vda" : "sda" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) manifest_path = "${path.cwd}/manifests/" @@ -50,6 +72,7 @@ locals { vm_os_language = var.vm_os_language vm_os_keyboard = var.vm_os_keyboard vm_os_timezone = var.vm_os_timezone + vm_cloudinit = var.vm_cloudinit network = templatefile("${abspath(path.root)}/data/network.pkrtpl.hcl", { device = var.vm_bridge_interface ip = var.vm_ip_address @@ -72,6 +95,7 @@ locals { } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/ks.cfg" : "inst.ks=/cdrom/ks.cfg" vm_name = "${var.vm_os_family}-${var.vm_os_name}-${var.vm_os_version}" + boot_command = var.vm_bios == "ovmf" ? local.uefi_boot_command : local.bios_boot_command vm_bios = var.vm_bios == "ovmf" ? var.vm_firmware_path : null } @@ -136,12 +160,7 @@ source "proxmox-iso" "linux-rocky" { http_port_max = var.common_data_source == "http" ? var.common_http_port_max : null boot = var.vm_boot boot_wait = var.vm_boot_wait - boot_command = [ - "", - "", - " text ${local.data_source_command}", - "" - ] + boot_command = local.boot_command dynamic "additional_iso_files" { for_each = var.common_data_source == "disk" ? [1] : [] @@ -156,8 +175,8 @@ source "proxmox-iso" "linux-rocky" { template_description = "${local.build_description}" # VM Cloud Init Settings - cloud_init = var.vm_cloud_init_enable - cloud_init_storage_pool = var.vm_cloud_init_enable == true ? var.vm_storage_pool : null + cloud_init = var.vm_cloudinit + cloud_init_storage_pool = var.vm_cloudinit == true ? var.vm_storage_pool : null } @@ -166,18 +185,22 @@ build { sources = ["source.proxmox-iso.linux-rocky"] provisioner "ansible" { - user = "${var.build_username}" - playbook_file = "${path.cwd}/ansible/main.yml" - roles_path = "${path.cwd}/ansible/roles" + user = "${var.build_username}" + galaxy_file = "${path.cwd}/ansible/linux-requirements.yml" + galaxy_force_with_deps = true + playbook_file = "${path.cwd}/ansible/linux-playbook.yml" + roles_path = "${path.cwd}/ansible/roles" ansible_env_vars = [ - "ANSIBLE_CONFIG=${path.cwd}/ansible/ansible.cfg" + "ANSIBLE_CONFIG=${path.cwd}/ansible/ansible.cfg", + "ANSIBLE_PYTHON_INTERPRETER=/usr/libexec/platform-python" ] extra_arguments = [ "--extra-vars", "display_skipped_hosts=false", - "--extra-vars", "BUILD_USERNAME=${var.build_username}", - "--extra-vars", "BUILD_SECRET='${var.build_key}'", - "--extra-vars", "ANSIBLE_USERNAME=${var.ansible_username}", - "--extra-vars", "ANSIBLE_SECRET='${var.ansible_key}'", + "--extra-vars", "build_username=${var.build_username}", + "--extra-vars", "build_key='${var.build_key}'", + "--extra-vars", "ansible_username=${var.ansible_username}", + "--extra-vars", "ansible_key='${var.ansible_key}'", + "--extra-vars", "enable_cloudinit='${var.vm_cloudinit}'", ] } @@ -198,7 +221,7 @@ build { vm_os_type = "${var.vm_os_type}" vm_mem_size = "${var.vm_mem_size}" vm_network_card_model = "${var.vm_network_card_model}" - vm_cloud_init_enable = "${var.vm_cloud_init_enable}" + vm_cloud_init_enable = "${var.vm_cloudinit}" } } } diff --git a/builds/linux/rocky/9/variables.pkr.hcl b/builds/linux/rocky/9/variables.pkr.hcl index 15810aa..12a2164 100644 --- a/builds/linux/rocky/9/variables.pkr.hcl +++ b/builds/linux/rocky/9/variables.pkr.hcl @@ -171,7 +171,7 @@ variable "vm_vlan_tag" { // Cloud-Init Settings -variable "vm_cloud_init_enable" { +variable "vm_cloudinit" { type = bool description = "Enable or disable cloud-init drive in Proxmox. (e.g. false)" default = false