No obvious error when using Content Library ISO in vsphere-iso

Running vSphere v7.0.1 and Packer v1.6.6, I am trying to build a VM using an ISO from the Content Library. I define the path as:

"iso_paths": [
    "ISOs/ubuntu-18.04.5-server-amd64/ubuntu-18.04.5-server-amd64.iso"
  ],

When I run the build I don’t get a verbose error output and so I’m unsure what’s wrong:

2021/02/15 11:57:18 Starting build run: vsphere-iso
2021/02/15 11:57:18 Running builder: vsphere-iso
2021/02/15 11:57:18 [INFO] (telemetry) Starting builder vsphere-iso
2021/02/15 11:57:18 packer-builder-vsphere-iso plugin: No URLs were provided to Step Download. Continuing...
2021/02/15 11:57:18 packer-builder-vsphere-iso plugin: No CD files specified. CD disk will not be made.
==> vsphere-iso: Creating VM...
==> vsphere-iso: error creating vm: something went wrong when creating the VM
==> vsphere-iso: Step "StepCreateVM" failed
==> vsphere-iso: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?

I have added all the permissions defined in vsphere-iso and no permission issues are coming up for the packer user. It does create a VM, but without a CD/DVD drive. Is it just not finding the ISO? Am I defining the path wrong?

Could you provide full logs? You can get them by running the build setting PACKER_LOG=1.

Here is the full log output, slightly edited for privacy:

2021/02/16 09:00:38 [INFO] Packer version: 1.6.6 [go1.15.5 darwin amd64]
2021/02/16 09:00:38 Checking 'PACKER_CONFIG' for a config file path
2021/02/16 09:00:38 'PACKER_CONFIG' not set; checking the default config file path
2021/02/16 09:00:38 Attempting to open config file: /Users/USER/.packerconfig
2021/02/16 09:00:38 [WARN] Config file doesn't exist: /Users/USER/.packerconfig
2021/02/16 09:00:38 Setting cache directory: /Users/USER/packer_cache
2021/02/16 09:00:38 Creating plugin client for path: /usr/local/bin/packer
2021/02/16 09:00:38 Starting plugin: /usr/local/bin/packer []string{"/usr/local/bin/packer", "plugin", "packer-builder-vsphere-iso"}
2021/02/16 09:00:38 Waiting for RPC address for: /usr/local/bin/packer
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: [INFO] Packer version: 1.6.6 [go1.15.5 darwin amd64]
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: Checking 'PACKER_CONFIG' for a config file path
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: 'PACKER_CONFIG' not set; checking the default config file path
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: Attempting to open config file: /Users/USER/.packerconfig
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: [WARN] Config file doesn't exist: /Users/USER/.packerconfig
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: Setting cache directory: /Users/USER/packer_cache
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: args: []string{"packer-builder-vsphere-iso"}
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: Plugin address: unix /var/folders/kw/ljks13q92xg2d5chv2zy5km80000gp/T/packer-plugin861829774
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: Waiting for connection...
2021/02/16 09:00:38 Received unix RPC address for /usr/local/bin/packer: addr is /var/folders/kw/ljks13q92xg2d5chv2zy5km80000gp/T/packer-plugin861829774
2021/02/16 09:00:38 packer-builder-vsphere-iso plugin: Serving a plugin connection...
2021/02/16 09:00:38 Creating plugin client for path: /usr/local/bin/packer
2021/02/16 09:00:38 Starting plugin: /usr/local/bin/packer []string{"/usr/local/bin/packer", "plugin", "packer-provisioner-shell"}
2021/02/16 09:00:38 Waiting for RPC address for: /usr/local/bin/packer
2021/02/16 09:00:38 packer-provisioner-shell plugin: [INFO] Packer version: 1.6.6 [go1.15.5 darwin amd64]
2021/02/16 09:00:38 packer-provisioner-shell plugin: Checking 'PACKER_CONFIG' for a config file path
2021/02/16 09:00:38 packer-provisioner-shell plugin: 'PACKER_CONFIG' not set; checking the default config file path
2021/02/16 09:00:38 packer-provisioner-shell plugin: Attempting to open config file: /Users/USER/.packerconfig
2021/02/16 09:00:38 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /Users/USER/.packerconfig
2021/02/16 09:00:38 packer-provisioner-shell plugin: Setting cache directory: /Users/USER/packer_cache
2021/02/16 09:00:38 packer-provisioner-shell plugin: args: []string{"packer-provisioner-shell"}
2021/02/16 09:00:38 Received unix RPC address for /usr/local/bin/packer: addr is /var/folders/kw/ljks13q92xg2d5chv2zy5km80000gp/T/packer-plugin178538386
2021/02/16 09:00:38 packer-provisioner-shell plugin: Plugin address: unix /var/folders/kw/ljks13q92xg2d5chv2zy5km80000gp/T/packer-plugin178538386
2021/02/16 09:00:38 packer-provisioner-shell plugin: Waiting for connection...
2021/02/16 09:00:38 packer-provisioner-shell plugin: Serving a plugin connection...
2021/02/16 09:00:38 Creating plugin client for path: /usr/local/bin/packer
2021/02/16 09:00:38 Starting plugin: /usr/local/bin/packer []string{"/usr/local/bin/packer", "plugin", "packer-provisioner-ansible"}
2021/02/16 09:00:38 Waiting for RPC address for: /usr/local/bin/packer
2021/02/16 09:00:38 packer-provisioner-ansible plugin: [INFO] Packer version: 1.6.6 [go1.15.5 darwin amd64]
2021/02/16 09:00:38 packer-provisioner-ansible plugin: Checking 'PACKER_CONFIG' for a config file path
2021/02/16 09:00:38 packer-provisioner-ansible plugin: 'PACKER_CONFIG' not set; checking the default config file path
2021/02/16 09:00:38 packer-provisioner-ansible plugin: Attempting to open config file: /Users/USER/.packerconfig
2021/02/16 09:00:38 packer-provisioner-ansible plugin: [WARN] Config file doesn't exist: /Users/USER/.packerconfig
2021/02/16 09:00:38 packer-provisioner-ansible plugin: Setting cache directory: /Users/USER/packer_cache
2021/02/16 09:00:38 packer-provisioner-ansible plugin: args: []string{"packer-provisioner-ansible"}
2021/02/16 09:00:38 Received unix RPC address for /usr/local/bin/packer: addr is /var/folders/kw/ljks13q92xg2d5chv2zy5km80000gp/T/packer-plugin274561758
2021/02/16 09:00:38 packer-provisioner-ansible plugin: Plugin address: unix /var/folders/kw/ljks13q92xg2d5chv2zy5km80000gp/T/packer-plugin274561758
2021/02/16 09:00:38 packer-provisioner-ansible plugin: Waiting for connection...
2021/02/16 09:00:38 packer-provisioner-ansible plugin: Serving a plugin connection...
2021/02/16 09:00:38 Preparing build: vsphere-iso
2021/02/16 09:00:39 packer-provisioner-ansible plugin: ansible-playbook version: 2.10.5
2021/02/16 09:00:39 Build debug mode: false
2021/02/16 09:00:39 Force build: true
2021/02/16 09:00:39 On error: ask
2021/02/16 09:00:39 Waiting on builds to complete...
vsphere-iso: output will be in this color.

2021/02/16 09:00:39 Starting build run: vsphere-iso
2021/02/16 09:00:39 Running builder: vsphere-iso
2021/02/16 09:00:39 [INFO] (telemetry) Starting builder vsphere-iso
2021/02/16 09:00:39 packer-builder-vsphere-iso plugin: No URLs were provided to Step Download. Continuing...
2021/02/16 09:00:39 packer-builder-vsphere-iso plugin: No CD files specified. CD disk will not be made.
==> vsphere-iso: Creating VM...
==> vsphere-iso: error creating vm: something went wrong when creating the VM
==> vsphere-iso: Step "StepCreateVM" failed
==> vsphere-iso: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)? c
2021/02/16 09:00:43 [INFO] (telemetry) ending vsphere-iso
==> Wait completed after 3 seconds 760 milliseconds
2021/02/16 09:00:43 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2021/02/16 09:00:43 machine readable: vsphere-iso,error []string{"error creating vm: something went wrong when creating the VM"}
==> Builds finished but no artifacts were created.
Build 'vsphere-iso' errored after 3 seconds 760 milliseconds: error creating vm: something went wrong when creating the VM

2021/02/16 09:00:43 [INFO] (telemetry) Finalizing.
==> Wait completed after 3 seconds 760 milliseconds

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: error creating vm: something went wrong when creating the VM

==> Builds finished but no artifacts were created.
2021/02/16 09:00:43 waiting for all plugin processes to complete...
2021/02/16 09:00:43 /usr/local/bin/packer: plugin process exited
2021/02/16 09:00:43 /usr/local/bin/packer: plugin process exited
2021/02/16 09:00:43 /usr/local/bin/packer: plugin process exited

Here is the VM builder JSON configuration:

"builders": [
  {
    "CPUs": 4,
    "RAM": 16384,
    "boot_command": [
      "<enter><wait><f6><wait><esc><wait>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs>",
      "/install/vmlinuz",
      " initrd=/install/initrd.gz",
      " priority=critical",
      " locale=en_US",
      " preeseed/url=http://url.com/preseed/ubuntu.cfg",
      "<enter>"
    ],
    "boot_wait": "10s",
    "cdrom_type": "sata",
    "cluster": "VxRail-Virtual-SAN-Cluster-1aec9d6d-843d-48c1-9000-ab08bb8e7907",
    "content_library_destination": {
      "cluster": "VxRail-Virtual-SAN-Cluster-1aec9d6d-843d-48c1-9000-ab08bb8e7907",
      "folder": "folder/deployment/build",
      "library": "VM Templates",
      "resource_pool": "pool/deployment/continuous deployment"
    },
    "datastore": "VxRail-Virtual-SAN-Datastore-1aec9d6d-843d-48c1-9000-ab08bb8e7907",
    "disk_controller_type": "nvme",
    "folder": "folder/deployment/build",
    "guest_os_type": "ubuntu64Guest",
    "insecure_connection": true,
    "ip_wait_timeout": "5m",
    "iso_paths": [
      "ISOs/ubuntu-18.04.5-server-amd64/ubuntu-18.04.5-server-amd64.iso"
    ],
    "network_adapters": [
      {
        "network": "vCenter Server Network-1aec9d6d-843d-48c1-9000-ab08bb8e7907",
        "network_card": "vmxnet3"
      }
    ],
    "password": "{{ user `vcenter_pass` }}",
    "remove_cdrom": true,
    "resource_pool": "pool/deployment/continuous deployment",
    "shutdown_command": "echo '{{ user `ssh_pass` }}' | sudo -S systemctl poweroff",
    "ssh_password": "{{ user `ssh_pass` }}",
    "ssh_port": 22,
    "ssh_username": "{{user `ssh_user`}}",
    "storage": [
      {
        "disk_size": 204800,
        "disk_thin_provisioned": true
      }
    ],
    "type": "vsphere-iso",
    "username": "{{ user `vcenter_user` }}",
    "vcenter_server": "vcenter.internet.net",
    "vm_name": "ubuntu_template"
  }
],

It places the VM in the correct folder and resource pool, it just fails out having not added a CDROM drive.

Packer creates the VM and after that reads the ISO from the content library. Your build is failing in the VM creation and the problem is not related with reading the ISO from the Content Library.

You’re right that the logs are not verbose enough to know exactly where in the creation the build failed but I don’t blame Packer for this. I’m looking at the code and the process doesn’t fail but when Packer checks the created Object it doesn’t contain the expected VM.

Could you rerun the build with -on-erro=ask, just like you did, and check from the UI if the VM is there being created?

Running it there is a VM created but it is missing the CDROM and only has 1 CPU with 32MB of RAM so it seems to be failing somewhere in the middle. However, I have narrowed it down to a permissions issue. I made the packer user an Administrator in Global Permission and it worked. I am at a bit of a loss because I have verified the packer user has the permissions defined in the documentation (minus permissions for floppy which I interpreted to be optional as I don’t use floppy) so I suppose I will need to go through one by one and figure out what it’s missing. Unfortunately VMWare wasn’t helpful either as the event log for both the failed and successful run were the same. I was hoping for some kind of error like “packer user denied permissions to X”, but no such luck.