Score:0

Using Packer to deploy Ubuntu 20.04 to Proxmox

us flag

Problem

TLDR: I've got this doing most of the AutoInstall (I think?) but it keeps bringing up the GUI install after it goes through the AutoInstall. Looking for any input into why it keeps bringing up the GUI. /TLDR

Longer Version: I am trying to figure out how to deploy ubuntu (and eventually other distros) to Proxmox by using Hashicorp Packer. I've got most of the configs setup and working... sort of? It's successfully "deploying" but it can't finish the initial setup, it keeps going through the AutoInstall, but then still brings up the GUI install. From stepping through the GUI manually, after it finishes the AutoInstall portion, it seems everything is already filled out (minus the user identity portion, ie FullName/Username/etc). It doesn't seem to even need to find an IP addr, like when you step through just the GUI, so I think DHCP is working fine?

I've tried looking at a few other similar-ish questions, but their solutions haven't worked for me (yet).

Theories

I've got a few theories, but none seem to work out quite right, or I'm not sure how to test them.

  1. I'm forgetting something in the user-data (yaml), and its trying to bring up the GUI because of this.
  2. I'm missing some config parameter in the .pkr.hcl file that is necessary for proxmox to set up the vm correctly?
  3. Something is weird with the Ubuntu version I'm using, maybe I need a different ISO? But the stuff I've read just says that the Cloud-init feature just swaps out the legacy preseed.cfg for the user-data (yaml) file, so I'm doubtful about this theory.
  4. I need to set some kernel feature? Honestly not sure where to start here, I'm also pretty sure if this was the case I would have seen something about it somewhere else. But hey, maybe I just looked in the wrong places?
  5. The user-data file isn't being loaded into Ubuntu properly?

Hopeful outcomes

  1. If you know the magic sauce, please grace me with it :)
  2. If you know how to get Ubuntu 20.04 to redirect some of its logs during install, so I can take a deeper look, that'd be appreciated! Same for better packer logging (aside from -debug, I've already tried that). I've tried /var/log/installer, but I don't think I have a firm grasp of whats going on. But I don't see any failures, aside from an SSH Key error, and I can't see any indication of user-data download or failures to download.
  3. If you have any ideas on how to test some of my theories, or any other theories I'd love to hear them!
  4. If you can see what I'm doing wrong in the below config files please point them out! I've been trying to do this in a SILO for a few days now and am up against a wall I don't know how to get over

Updates (ongoing)

  1. found seed from http://192.168.0.144:80/user-data not supported by DataSourceNoCloud [seed=None][dsmode=net] in /var/log/cloud-init.log looking into why that came back, any advice would be appreciated :)
  2. Ok so I figured out why the above error occurred, seems it wasn't in proper YAML format. I just dumped the file into a YAML formatter and then copy pasted it back into my target file.
  3. Now the error is that the loaded YAML file is blank /var/lib/cloud/seed/nocloud/user-data, again I'd appreciate any advice :)

Hint

If you're cool enough to try replicating this stuff, or if you've stumbled into this after its (hopefully) been answered, make your life easier by using a example.auto.pkrvars.hcl file.

Versions

Proxmox: Proxmox VE 7.1-4
Windows: Windows 10 Pro : 10.0.19043.0
Packer: 1.7.10

Example.pkr.hcl

packer {
  required_plugins {
    proxmox = {
      version = " >= 1.0.1"
      source  = "github.com/hashicorp/proxmox"
    }
  }
}

source "proxmox-iso" "proxmox-ubuntu-20" {
  proxmox_url = "https://proxmox.lan:8006/api2/json"
  vm_name     = "packer-ubuntu-20"
  iso_url      = "http://iso.repo.lan/ubuntu-20.04.3-live-server-amd64.iso"
  iso_checksum = "f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98"
  username         = "${var.pm_user}"
  password         = "${var.pm_pass}"
  token            = "${var.pm_token}"
  node             = "proxmox"
  iso_storage_pool = "local"

  ssh_username           = "${var.ssh_user}"
  ssh_password           = "${var.ssh_pass}"
  ssh_timeout            = "20m"
  ssh_pty                = true
  ssh_handshake_attempts = 20

  boot_wait      = "5s"
  http_directory = "http" # Starts a local http server, serves Preseed file
  boot_command = [
    "<esc><wait><esc><wait><f6><wait><esc><wait>",
    "<bs><bs><bs><bs><bs>",
    "ip=${cidrhost("192.168.0.0/24", 9)}::${cidrhost("192.168.0.0/24", 1)}:${cidrnetmask("192.168.0.0/24")}::::${cidrhost("192.168.0.0/24", 1)} ",
    "autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/",
    "--- <enter>"
  ]

  insecure_skip_tls_verify = true

  template_name        = "packer-ubuntu-20"
  template_description = "packer generated ubuntu-20.04.3-server-amd64"
  unmount_iso          = true

  pool       = "packer"
  memory     = 4096
  cores      = 1
  sockets    = 1
  os         = "l26"
  qemu_agent = true
  cloud_init = true
  # scsi_controller = "virtio-scsi-pci"
  disks {
    type              = "scsi"
    disk_size         = "30G"
    storage_pool      = "local-lvm"
    storage_pool_type = "lvm"
    format            = "raw"
  }
  network_adapters {
    bridge   = "vmbr0"
    model    = "virtio"
    firewall = true
    # vlan_tag = 1
  }
}

build {
  sources = ["source.proxmox-iso.proxmox-ubuntu-20"]
  provisioner "shell" {
    inline = [
      "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
      "ls /"
    ]
  }
}

vars.pkr.hcl

variable "pm_user" {
  type        = string
  description = "Proxmox User Name"
  default     = "packer@pam!<api-tag>"
}
variable "pm_pass" {
  type        = string
  description = "Proxmox User Password"
  default     = "packer"
}
variable "pm_token" {
  type        = string
  description = "Proxmox API Token"
}
variable "ssh_user" {
  type        = string
  description = "SSH User"
  default     = "packer"
}
variable "ssh_pass" {
  type        = string
  description = "SSH Password"
  default     = "packer"
}
variable "vm_name" {
  type        = string
  description = "VM Name"
  default     = "packer_hostname"
}

http/user-data

autoinstall:
  version: 1
  locale: en_US.UTF-8
  keyboard:
    layout: en
    variant: us
  identity:
    hostname: packer-ubuntu-20
    password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0" #ubuntu
    username: ubuntu
    realname: ubuntu
  refresh-installer: 
    update: false
  ssh:
    install-server: yes
    allow-pw: yes
  packages:
    - qemu-guest-agent
  storage:
    layout:
      name: direct
    swap:
      size: 0

Sources

https://www.aerialls.eu/posts/ubuntu-server-2004-image-packer-subiquity-for-proxmox/
https://ubuntu.com/server/docs/install/autoinstall-reference
https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
https://cloudinit.readthedocs.io/en/latest/topics/modules.html#write-files
https://cloudalbania.com/posts/2022-01-homelab-with-proxmox-and-packer/

Score:0
us flag

Answer

As luck would have it, I was searching in a completely erroneous direction SMH.
The issue is that I didn't read the Cloud-init FAQs closely enough. All I had to do was add #cloud-config as the first line in my user-data file.

The below configs will work, for anyone who's interested.

I put the full docs here. Feel free to peruse if interested https://github.com/aRustyDev/packer

Example.pkr.hcl

packer {
  required_plugins {
    proxmox = {
      version = " >= 1.0.1"
      source  = "github.com/hashicorp/proxmox"
    }
  }
}

source "proxmox-iso" "proxmox-ubuntu-20" {
  proxmox_url = "https://proxmox.lan:8006/api2/json"
  vm_name     = "packer-ubuntu-20"
  iso_url      = "http://iso.repo.lan/ubuntu-20.04.3-live-server-amd64.iso"
  iso_checksum = "f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98"
  username         = "${var.pm_user}"
  password         = "${var.pm_pass}"
  token            = "${var.pm_token}"
  node             = "proxmox"
  iso_storage_pool = "local"

  ssh_username           = "${var.ssh_user}"
  ssh_password           = "${var.ssh_pass}"
  ssh_timeout            = "20m"
  ssh_pty                = true
  ssh_handshake_attempts = 20

  boot_wait      = "5s"
  http_directory = "http" # Starts a local http server, serves Preseed file
  boot_command = [
    "<esc><wait><esc><wait><f6><wait><esc><wait>",
    "<bs><bs><bs><bs><bs>",
    "ip=${cidrhost("192.168.0.0/24", 9)}::${cidrhost("192.168.0.0/24", 1)}:${cidrnetmask("192.168.0.0/24")}::::${cidrhost("192.168.0.0/24", 1)} ",
    " autoinstall ds=nocloud-net;s=http://httpd.proxmox.local:80/preseed/ubuntu-20/ ",
    "--- <enter>"
  ]

  insecure_skip_tls_verify = true

  template_name        = "packer-ubuntu-20"
  template_description = "packer generated ubuntu-20.04.3-server-amd64"
  unmount_iso          = true

  pool       = "packer"
  memory     = 4096
  cores      = 1
  sockets    = 1
  os         = "l26"
  qemu_agent = true
  disks {
    type              = "scsi"
    disk_size         = "30G"
    storage_pool      = "local-lvm"
    storage_pool_type = "lvm"
    format            = "raw"
  }
  network_adapters {
    bridge   = "vmbr0"
    model    = "virtio"
    firewall = true
  }
}

build {
  sources = ["source.proxmox-iso.proxmox-ubuntu-20"]
  provisioner "shell" {
    inline = [
      "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
      "ls /"
    ]
  }
}

vars.pkr.hcl

variable "pm_user" {
  type        = string
  description = "Proxmox User Name"
  default     = "packer@pam!<api-tag>"
}
variable "pm_pass" {
  type        = string
  description = "Proxmox User Password"
  default     = "packer"
}
variable "pm_token" {
  type        = string
  description = "Proxmox API Token"
}
variable "ssh_user" {
  type        = string
  description = "SSH User"
  default     = "packer"
}
variable "ssh_pass" {
  type        = string
  description = "SSH Password"
  default     = "packer"
}
variable "vm_name" {
  type        = string
  description = "VM Name"
  default     = "packer_hostname"
}

http/user-data

#cloud-config
autoinstall:
  version: 1
  locale: en_US.UTF-8
  keyboard:
    layout: en
    variant: us
  identity:
    hostname: packer-ubuntu-20
    password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0" #ubuntu
    username: ubuntu
    realname: ubuntu
  refresh-installer: 
    update: false
  ssh:
    install-server: yes
    allow-pw: yes
  packages:
    - qemu-guest-agent
  storage:
    layout:
      name: direct
    swap:
      size: 0
David avatar
cn flag
Answers do not include advertising please remove.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.