hashicorp / packer-plugin-proxmox

Packer plugin for Proxmox Builder
https://www.packer.io/docs/builders/proxmox
Mozilla Public License 2.0
161 stars 70 forks source link

Cannot upload ISO to proxmox #209

Open comminutus opened 1 year ago

comminutus commented 1 year ago

Overview of the Issue

Running packer build . results in error "write: broken pip"

I am trying to get a Fedora CoreOS ISO template for Proxmox. I was following this example here: https://wirywolf.com/2022/12/coreos-template-on-proxmox-with-packer.html . When I run packer build ., everything looks good until it tries to HTTP POST to my Proxmox cluster. Here is a partial output:

    proxmox-iso.fedora-coreos-k3s: Writing to 'stdio:/tmp/packer438053007.iso' completed successfully.
    proxmox-iso.fedora-coreos-k3s: Done copying paths from CD_dirs
==> proxmox-iso.fedora-coreos-k3s: Post "https://[REDACTED-PVE-HOSTNAME]:8006/nodes/pve1/storage/local/upload": write tcp 192.168.0.67:49638->192.168.70.10:8006: write: broken pipe
==> proxmox-iso.fedora-coreos-k3s: delete volume failed: 501 no such file '/nodes/pve1/storage/local/content/'
Build 'proxmox-iso.fedora-coreos-k3s' errored after 539 milliseconds 335 microseconds: 501 no such file '/nodes/pve1/storage/local/content/'

Sometimes the output is slightly different:

    proxmox-iso.fedora-coreos-k3s: Writing to 'stdio:/tmp/packer1016122831.iso' completed successfully.
    proxmox-iso.fedora-coreos-k3s: Done copying paths from CD_dirs
==> proxmox-iso.fedora-coreos-k3s: 501 for data too large
==> proxmox-iso.fedora-coreos-k3s: delete volume failed: 501 no such file '/nodes/pve1/storage/local/content/'
Build 'proxmox-iso.fedora-coreos-k3s' errored after 556 milliseconds 9 microseconds: 501 no such file '/nodes/pve1/storage/local/content/'

I checked the free space of the volume it's trying to upload to (local-lvm) and it has 353 GB free.

I saw there was issue #81 regarding permissions. I set up a new user as described here https://github.com/hashicorp/packer-plugin-proxmox/issues/81#issuecomment-1349601962 . I also ensured the permissions were setup with PVEDatastoreUser per https://github.com/hashicorp/packer-plugin-proxmox/issues/81#issuecomment-1260186065.

Reproduction Steps

Here's the .pkr.hcl file used for the build, for the sake of privacy I have a separate .auto.pkrvars.hcl that I've omitted but the contents should be self-explanatory based on the variables set below.

packer {
   required_plugins {
        proxmox-iso             = {
            version             = ">= 1.1.3"
            source              = "github.com/hashicorp/proxmox"
        }
   } 
}

# Variables
variable "proxmox_url" {
    type                        = string
}

variable "proxmox_username" {
    type                        = string
}

variable "proxmox_token" {
    type                        = string
    sensitive                   = true
}

variable "proxmox_node" {
    type                        = string
}

variable "proxmox_iso_file" {
    type                        = string
}

variable "proxmox_iso_storage_pool" {
    type                        = string
    default                     = "local"
}

variable "proxmox_iso_checksum" {
    type                        = string
}

variable "proxmox_vm_id" {
    type                        = number
    default                     = 2000
}

variable "proxmox_disk_storage_pool" {
    type                        = string
    default                     = "local-lvm"
}

variable "fedora_coreos_version" {
    type                        = string
}

variable "ssh_private_key_file" {
    type                        = string
}

# Fields: https://developer.hashicorp.com/packer/plugins/builders/proxmox/iso
source "proxmox-iso" "fedora-coreos-k3s" {
    # Required
    proxmox_url                 = var.proxmox_url
    username                    = var.proxmox_username
    token                       = var.proxmox_token
    node                        = var.proxmox_node
    iso_file                    = var.proxmox_iso_file
    iso_storage_pool            = var.proxmox_iso_storage_pool
    iso_checksum                = var.proxmox_iso_checksum

    # Optional
    insecure_skip_tls_verify    = true
    vm_id                       = var.proxmox_vm_id
    memory                      = 4096      # Reported memory will be 2G but ballooning, minimum defined below (1G)
    ballooning_minimum          = 1024  
    cores                       = 2
    cpu_type                    = "host"    # use host cpu type
    os                          = "l26"     # Linux 2.6

    disks {
        type                    = "virtio"
        disk_size               = "30G"
        storage_pool            = var.proxmox_disk_storage_pool
    }

    template_name               = "fcos-${var.fedora_coreos_version}-k3s"
    template_description        = "Template for Fedora CoreOS v${var.fedora_coreos_version} w/ Rancher k3s"
    qemu_agent                  = true
    scsi_controller             = "virtio-scsi-pci"

    additional_iso_files {
        cd_files                = ["./config/example.ign"]
        iso_storage_pool        = "local"
        cd_label                = "ignition"
    }

    boot_wait                   = "2s"
    http_directory              = "config"
    boot_command                = [
        "<spacebar><wait><spacebar><wait><spacebar><wait><spacebar><wait><spacebar><wait>",
        "<tab><wait>",
        "<down><down><end>",
        " ignition.config.url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/installer.ign",
        "<enter>"]

    ssh_username                = "core"
    ssh_private_key_file        = var.ssh_private_key_file
    ssh_timeout                 = "20m"
}

build {
  sources = ["source.proxmox-iso.fedora-coreos-k3s"]

  provisioner "shell" {
    inline = [
      "sudo mkdir /tmp/iso",
      "sudo mount /dev/sr1 /tmp/iso -o ro",
      "sudo coreos-installer install /dev/vda --ignition-file /tmp/iso/template.ign",
      # Packer's shutdown command doesn't seem to work, likely because we run qemu-guest-agent
      # inside a docker container.
      # This will shutdown the VM after 1 minute, which is less than the duration that Packer
      # waits for its shutdown command to complete, so it works out.
      "sudo shutdown -h +1"
    ]
  }
}

Here's the contents of config/example.ign:

{
  "ignition": {
    "version": "3.4.0"
  },
  "passwd": {
    "users": [
      {
        "name": "core",
        "sshAuthorizedKeys": [
          "[REDACTED]"
        ]
      }
    ]
  }
}

To reproduce, run packer build .

Plugin and Packer version

Packer v1.9.2

Operating system and Environment details

Fedora Silverblue 38 x86_64. Packer installed with distrobox and a fedora image with dnf

Set the env var PACKER_LOG=1 for maximum log detail.

newedgex commented 1 year ago

It's working in my case , I have a similar config

==> proxmox-iso.windows10: Creating CD disk...
    proxmox-iso.windows10: xorriso 1.5.6 : RockRidge filesystem manipulator, libburnia project.
    proxmox-iso.windows10: Drive current: -outdev 'stdio:/tmp/packer2091475118.iso'
    proxmox-iso.windows10: Media current: stdio file, overwriteable
    proxmox-iso.windows10: Media status : is blank
    proxmox-iso.windows10: Media summary: 0 sessions, 0 data blocks, 0 data, 15.6g free
    proxmox-iso.windows10: xorriso : WARNING : -volid text does not comply to ISO 9660 / ECMA 119 rules
    proxmox-iso.windows10: Added to ISO image: directory '/'='/tmp/packer_to_cdrom1217354203'
    proxmox-iso.windows10: xorriso : UPDATE :       4 files added in 1 seconds
    proxmox-iso.windows10: xorriso : UPDATE :       4 files added in 1 seconds
    proxmox-iso.windows10: ISO image produced: 203 sectors
    proxmox-iso.windows10: Written to medium : 203 sectors at LBA 0
    proxmox-iso.windows10: Writing to 'stdio:/tmp/packer2091475118.iso' completed successfully.
    proxmox-iso.windows10: Done copying paths from CD_dirs
    proxmox-iso.windows10: Uploaded ISO to isos:iso/packer2091475118.iso

Maybe it's a permission issue on the API level or the directory is really not there?

nick-holmquist commented 1 year ago

I know this is an older issue (based on the date) but looking through this and noticing the similarities to what I dealt with. From the above logs it appears you may be missing the proper proxmox_url

According to your log: proxmox-iso.fedora-coreos-k3s: Post "https://[REDACTED-PVE-HOSTNAME]:8006/nodes/pve1/storage/local/upload":

You don't have your proxmox_url config above so I have to assume you left off the /api/json from the proxmox_url definition. proxmox_url = "https://my.proxmox.local:8006/api2/json"

With the fix just added [#238 ] it removes an extra / only. Based on the above it might be worth it to add proper regex check against the proxmox_url to avoid random issues like this in the future.

majdalshawa commented 6 months ago

if you're still facing the same issue you just need to add a permission PVEDatastoreUser to your api token and then it will be working just fine