diff --git a/packer/libvirt/arch/arch-minimal.auto.pkrvars.hcl b/packer/libvirt/arch/arch-minimal.auto.pkrvars.hcl index ca96f68..8c61328 100644 --- a/packer/libvirt/arch/arch-minimal.auto.pkrvars.hcl +++ b/packer/libvirt/arch/arch-minimal.auto.pkrvars.hcl @@ -3,6 +3,8 @@ checksum_url = "https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x8 host_ssh_user = "michael" host_ssh_address = "server.balsillie.net" +host_ssh_private_key = "/home/michael/.ssh/conf.d/home/michael_server_copy.key" +host_ssh_known_hosts = "/home/michael/.ssh/known_hosts_server" guest_hostname = "arch-minimal-template" cpu_count = 2 @@ -12,7 +14,7 @@ arch = "x86_64" chipset = "pc-q35-6.1" loader_type = "pflash" loader_path = "/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd" -secure_boot = true +secure_boot = false nvram_template = "/usr/share/edk2-ovmf/x64/OVMF_VARS.fd" nvram_path_base = "/var/lib/libvirt/qemu/nvram" @@ -26,7 +28,7 @@ ssh_source = "192.168.20.0/24" guest_ssh_user = "arch" guest_ssh_port = 22 -guest_ssh_private_key = "~/.ssh/conf.d/home/arch@arch_template.key" +guest_ssh_private_key = "/home/michael/.ssh/conf.d/home/arch@arch_template.key" guest_ssh_public_key = "~/.ssh/conf.d/home/arch@arch_template.key.pub" network_address = "192.168.21.200/24" diff --git a/packer/libvirt/arch/arch-minimal.build.pkr.hcl b/packer/libvirt/arch/arch-minimal.build.pkr.hcl index 86c8e6c..f3e9e6f 100644 --- a/packer/libvirt/arch/arch-minimal.build.pkr.hcl +++ b/packer/libvirt/arch/arch-minimal.build.pkr.hcl @@ -25,8 +25,8 @@ data "http" "image_checksum" { } locals { - image_checksum = split(" ",data.http.image_checksum)[0] - libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${var.host_ssh_address}/system" + image_checksum = split(" ",data.http.image_checksum.body)[0] + libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${var.host_ssh_address}/system?keyfile=${var.host_ssh_private_key}&no_verify=1" nvram_path = "${var.nvram_path_base}/${var.guest_hostname}_VARS.fd" cidata_name = "${var.volume_name}_cidata" } @@ -47,8 +47,10 @@ source "libvirt" "arch-minimal" { chipset = var.chipset loader_type = var.loader_type loader_path = var.loader_path - nvram_template = var.nvmram_template - nvram_path = local.nvram_path + // nvram_template = var.nvram_template + // nvram_path = local.nvram_path + nvram_template = local.nvram_path + nvram_path = var.nvram_template secure_boot = var.secure_boot volume { @@ -65,6 +67,7 @@ source "libvirt" "arch-minimal" { type = "external" urls = [var.image_url] checksum = local.image_checksum + // checksum = "f237ada9ba61431f6aebb066d2b3f0b5b432ea21da6034d98248725df1417545" } } @@ -77,19 +80,19 @@ source "libvirt" "arch-minimal" { type = "cloud-init" meta_data = jsonencode({ - "instance-id" = ${var.guest_hostname} - "hostname" = ${var.guest_hostname} + "instance-id" = "${var.guest_hostname}" + "hostname" = "${var.guest_hostname}" }) user_data = format("#cloud-config\n%s", jsonencode({ - "packages" = [ + "packages" = [ "qemu-guest-agent", "ufw" ] - "runcmd" = [ + "runcmd" = [ ["systemctl", "enable", "--now", "qemu-guest-agent"], ["ufw", "enable"], - ["ufw", "allow", "from", ${var.ssh_source}, "to", "port", "22", "proto", "tcp"], + ["ufw", "allow", "from", "${var.ssh_source}", "to", "port", "22", "proto", "tcp"], ["systemctl", "enable", "--now", "ufw"] ] })) @@ -103,16 +106,15 @@ source "libvirt" "arch-minimal" { name = "en*" } dhcp4 = false - addresses = [${var.network_address}] - gateway4 = ${var.network_gateway} + addresses = ["${var.network_address}"] + gateway4 = "${var.network_gateway}" nameservers = { - addresses = [${var.network_nameserver}] - search = [${var.network_domain}] + addresses = ["${var.network_nameserver}"] + search = ["${var.network_domain}"] } } } }) - } } @@ -127,14 +129,14 @@ source "libvirt" "arch-minimal" { network_address_source = "agent" graphics { - type = "spice" - port = 5900 + type = "vnc" + port = 5902 } communicator { - ssh_username = var.guest_ssh_user - ssh_port = var.guest_ssh_port - ssh_private_key = var.guest_ssh_private_key + ssh_username = var.guest_ssh_user + ssh_port = var.guest_ssh_port + ssh_private_key_file = var.guest_ssh_private_key } communicator_interface = "default-network" } diff --git a/packer/libvirt/arch/arch-minimal.variables.pkr.hcl b/packer/libvirt/arch/arch-minimal.variables.pkr.hcl index 9034332..87f38df 100644 --- a/packer/libvirt/arch/arch-minimal.variables.pkr.hcl +++ b/packer/libvirt/arch/arch-minimal.variables.pkr.hcl @@ -91,6 +91,7 @@ variable "guest_ssh_pass" { type = string sensitive = true description = "Password for SSH connection to the guest VM." + default = "placeholder" } variable "guest_ssh_port" { @@ -119,14 +120,24 @@ variable "ssh_source" { description = "The subnet that will be added to the firewall SSH exception during cloud-init." } +variable "host_ssh_user" { + type = string + description = "The user to connect to the hypervisor as, used to construct the libvirt URI." +} + variable "host_ssh_address" { type = string description = "The address of the hypervisor, used to construct the libvirt URI." } -variable "host_ssh_user" { +variable "host_ssh_private_key" { type = string - description = "The user to connect to the hypervisor as, used to construct the libvirt URI." + description = "File path to the SSH key used to authenticate to the hypervisor host." +} + +variable "host_ssh_known_hosts" { + type = string + description = "File path to the known_hosts file for validating the hypervisor host connection." } variable "network_address" { diff --git a/packer/libvirt/arch/templates/meta_data.j2 b/packer/libvirt/arch/templates/meta_data.j2 deleted file mode 100644 index e69de29..0000000 diff --git a/packer/libvirt/arch/templates/network_config.j2 b/packer/libvirt/arch/templates/network_config.j2 deleted file mode 100644 index e69de29..0000000 diff --git a/packer/libvirt/arch/templates/user_data.j2 b/packer/libvirt/arch/templates/user_data.j2 deleted file mode 100644 index e69de29..0000000