Proxmox, packer Ubuntu autoinstall

Hi all,

I have been trying all day to set up a ci/cd pipeline to build images with packer for my proxmox node. I have used this post as a reference along with the proxmox packer documentation. Packer Ubuntu 20.04 autoinstall via CD drive.

I would use the http server but my gitlab runner is on a kubernetes cluster. I thought maybe building a custom instance of the packer image as an option but this seems much simpler. I am positive my issue is in my pkr.hcl file and was hoping someone here would enlighten me. Thank you in advance. The error I receive when I run my pipeline job is

 `Error: Unsupported argument` `  on ubuntu-server-jammy.pkr.hcl line 76:` `  (source code not available)` `An argument named "cd_files" is not expected here`

Here is my hcl file

# Ubuntu Server jammy
# ---
# Packer Template to create an Ubuntu Server (jammy) on Proxmox

# Variable Definitions


# Resource Definiation for the VM Template
source "proxmox" "ubuntu-server-jammy" {

  # Proxmox Connection Settings
  proxmox_url = var.proxmox_api_url
  username    = var.proxmox_api_token_id
  token       = var.proxmox_api_token_secret
  # (Optional) Skip TLS Verification
  insecure_skip_tls_verify = true

  # VM General Settings
  node                 = "hv1"
  vm_id                = "9006"
  vm_name              = "Hashi-ubuntu-server-jammy-1"
  template_description = "Hashistack"

  # VM OS Settings
  # (Option 1) Local ISO File
  # iso_file = "local:iso/ubuntu-22.04-live-server-amd64.iso"
  # - or -
  # (Option 2) Download ISO
  iso_url          = "https://releases.ubuntu.com/22.04/ubuntu-22.04.1-live-server-amd64.iso"
  iso_checksum     = "10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb"
  iso_storage_pool = "ISO_Storage" # Specify your storage pool
  unmount_iso      = true
  
  # VM System Settings
  qemu_agent = true

  # VM Hard Disk Settings
  scsi_controller = "virtio-scsi-pci"

  disks {
    disk_size         = "20G"
    format            = "raw"
    storage_pool      = "pool1" #Specify your storage pool
    storage_pool_type = "zfs"   #Specify pool type
    type              = "virtio"
  }

  # VM CPU Settings
  cores = "8"

  # VM Memory Settings
  memory = "16384"

  # VM Network Settings
  network_adapters {
    model    = "virtio"
    bridge   = "vmbr0"
    firewall = "false"
  }


  # VM Cloud-Init Settings
  cloud_init              = true
  cloud_init_storage_pool = "pool1" # Specify your storage pool

  # PACKER Boot Commands
  boot_command = [
    "<esc><wait>",
    "e<wait>",
    "<down><down><down><end>",
    "<bs><bs><bs><bs><wait>",
    "autoinstall ds=nocloud-net;s=/cidata/ ---<wait>",
    "<f10><wait>"
  ]

  cd_files = ["./http/meta-data", "./http/user-data"]
  cd_label = "cidata"
  boot      = "c"
  boot_wait = "5s"

  # PACKER Autoinstall Settings
  #http_directory = "http"
  # (Optional) Bind IP Address and Port
   #http_bind_address = "0.0.0.0"
   #http_port_min = 8802
   #http_port_max = 8802

  ssh_username = "ubuntu"

  # (Option 1) Add your Password here
  ssh_password = "ubuntu"
  # - or -
  # (Option 2) Add your Private SSH KEY file here
  #ssh_private_key_file = "~/.ssh/ansible"

  # Raise the timeout, when installation takes longer
  ssh_timeout = "20m"
}

# Build Definition to create the VM Template
build {

  name    = "Hashi-ubuntu-server-jammy"
  sources = ["source.proxmox.ubuntu-server-jammy"]

  # Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
  provisioner "shell" {
    inline = [
      "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
      "sudo rm /etc/ssh/ssh_host_*",
      "sudo truncate -s 0 /etc/machine-id",
      "sudo apt -y autoremove --purge",
      "sudo apt -y clean",
      "sudo apt -y autoclean",
      "sudo cloud-init clean",
      "sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
      "sudo sync"
    ]
  }

  provisioner "shell" {
    inline = [
      "sudo wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg",
      "echo deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main | sudo tee /etc/apt/sources.list.d/hashicorp.list",
      "sudo apt update",
      "sudo apt install nomad -y",
      "sudo apt install consul -y",
      "sudo apt install vault -y",
    ]
  }

  # Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
  provisioner "file" {
    source      = "99-pve.cfg"
    destination = "/tmp/99-pve.cfg"
  }

  # Provisioning the VM Template for Cloud-Init Integration in Proxmox #3
  provisioner "shell" {
    inline = ["sudo cp /tmp/99-pve.cfg /etc/cloud/cloud.cfg.d/99-pve.cfg"]
  }

  # Add additional provisioning scripts here
  # ...
}

I made some progress by correcting my syntax… Doh!

  iso_url          = "https://releases.ubuntu.com/22.04/ubuntu-22.04.1-live-server-amd64.iso"
  iso_checksum     = "10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb"
  iso_storage_pool = "ISO_Storage" # Specify your storage pool
  unmount_iso      = true
  additional_iso_files {
    cd_files = [
      "./http/meta-data",
      "./http/user-data"
    ]
    cd_label = "cidata"
    iso_storage_pool = "local"
  }

However proxmox does not use the supported ISO creation that packer tries to use.

could not find a supported CD ISO creation command (the supported commands are: xorriso, mkisofs, hdiutil, oscdimg)

I then installed mkisofs and got the following from proxmox

Note, selecting 'genisoimage' instead of 'mkisofs' 

Seems like this is going to fight the whole way there. So next I tried xorriso for grins and got the same error from the job.

Update:

I fixed the error concerning CD ISO creation. It seems the packer image doesn’t come with it so I added it to my ci/cd pipeline

stages:
  - validate
  - build

image:
   name: hashicorp/packer
   entrypoint:
      - '/usr/bin/env'
      - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
  - apk add xorriso

validate:
  stage: validate
  script:
    - packer --version
    - echo "Running Packer Validate"
    - packer init .
    - packer validate .

build:
  stage: build
  script:
    - packer init .
    - echo "Running Packer Build"
    - packer build .