packer-plugin-proxmox icon indicating copy to clipboard operation
packer-plugin-proxmox copied to clipboard

An argument named "cd_files" is not expected here.

Open prologic opened this issue 3 years ago • 10 comments

When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.

Overview of the Issue

Running a packer build using the latest version of Packer and this plugin against a Proxmox VE cluster failed with the above error. From documentation and examples in the wild the following piece of HCL should be supproted:

  additional_iso_files {
    iso_storage_pool = "local"
    cd_files = ["cloudinit/*"]
    cd_label = "cidata"
    unmount = true
  }

This was added in #33

Reproduction Steps

  1. Clonse https://git.mills.io/prologic/packer-proxmox-ubuntu
  2. Follow README

Plugin and Packer version

$ packer version
Packer v1.8.0
$ packer plugins installed
/usr/local/bin/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64
/usr/local/bin/github.com/ivoronin/sshkey/packer-plugin-sshkey_v1.0.2_x5.0_darwin_amd64
/usr/local/bin/github.com/hashicorp/proxmox/packer-plugin-proxmox_v1.0.6_x5.0_darwin_amd64
/usr/local/bin/github.com/vultr/vultr/packer-plugin-vultr_v2.4.4_x5.0_darwin_amd64

Simplified Packer Buildfile

See: https://git.mills.io/prologic/packer-proxmox-ubuntu

Operating system and Environment details

OS, macOS / Darwin / Intel

Log Fragments and crash.log files

(⎈ |local:default)
prologic@Jamess-iMac
Thu May 26 13:52:37
~/Projects/packer-proxmox-ubuntu
 (master) 0
$ packer build -var 'proxmox_node_name=vz1' .
Error: Unsupported argument

  on sources.pkr.hcl line 50:
  (source code not available)

An argument named "cd_files" is not expected here.

Error: Unsupported argument

  on sources.pkr.hcl line 51:
  (source code not available)

An argument named "cd_label" is not expected here.



==> Wait completed after 5 microseconds

==> Builds finished but no artifacts were created.

prologic avatar May 26 '22 03:05 prologic

@azr / @SwampDragons Either of you able to help here? I'm quite sure I'm doing something wrong, but for all intents and purposes I'm pretty sure I'm also using the right arguments and HCL here 🤔 I think

prologic avatar May 30 '22 03:05 prologic

I'm seeing the same thing

source "proxmox-iso" "production-proxmox" {
  additional_iso_files {
    unmount  = true
    cd_files = ["${path.root}/bootstrap/meta-data", "${path.root}/bootstrap/user-data"]
    cd_label = "cidata"
  }
...
}
packer build -timestamp-ui \
                -only proxmox-iso.production-proxmox \
                ubuntu.pkr.hcl
Error: Unsupported argument

  on ubuntu.pkr.hcl line 147:
  (source code not available)

An argument named "cd_files" is not expected here.

Error: Unsupported argument

  on ubuntu.pkr.hcl line 148:
  (source code not available)

An argument named "cd_label" is not expected here.



==> Wait completed after 1 microsecond

==> Builds finished but no artifacts were created.

weikinhuang avatar May 31 '22 12:05 weikinhuang

Seeing this as well.

source "proxmox-iso" "isobuild" {

  additional_iso_files {
    iso_storage_pool         = "local-btrfs"
    cd_files                 = ["./isoinclude/*"]
    cd_label                 = "automation"
    unmount                  = "true"
  }
...
}
Error: Unsupported argument

  on isobuild.pkr.hcl line 120:
  (source code not available)

An argument named "cd_files" is not expected here.

Error: Unsupported argument

  on isobuild.pkr.hcl line 121:
  (source code not available)

An argument named "cd_label" is not expected here.


==> Wait completed after 87 microseconds

==> Builds finished but no artifacts were created.

Anyone have a solution?

nathenv avatar Aug 13 '22 19:08 nathenv

For all with this issue, has anyone tried running your code in json form instead of HCL? I'm testing that just to prove if anything works, though I keep hitting some weirdness with my user-data file, but at least getting to that point.

I'm converting vsphere-iso code written in HCL, but when I try to validate I get dozens of similar issues: unsupported argument or whatever argument is supposed to be a string, etc. For giggles I cloned an example repo found online, that was still in json, changed the pertinent info to match the filling code, and it makes it past validate and at least starts to boot.

Is it just that HCL is the issue with this plugin?

Anyone confirm?

brantleyp1 avatar Sep 03 '22 03:09 brantleyp1

Have not tried to be honest. Someone needs to debug this and see what needs to be fixed 👌

prologic avatar Sep 04 '22 01:09 prologic

Just finally got the kids to bed and am trying again. I can confirm, running all the same options as before but in json format vs HCL, it is working with no issues.

brantleyp1 avatar Sep 04 '22 01:09 brantleyp1

Interesting 🤔 How is the HCL causing problems here?

prologic avatar Sep 04 '22 03:09 prologic

I'm not exactly sure but this json code is working (well, my provisioners are failing for some dumb reason and I'm not sure if it's that poor little i5 that the code is currently trying to build on, but it takes 45-60 minutes before it finally fails at some silly ansible issue)

	"builders": [
		{
			"type": "proxmox-iso",
			"proxmox_url": "https://{{user `proxmox_host`}}/api2/json",
			"insecure_skip_tls_verify": true,
			"username": "{{user `proxmox_api_user`}}",
			"password": "{{user `proxmox_api_password`}}",

			"vm_name": "build-{{user `template_name`}}",
			"vm_id": "{{ user `vmid` }}",
			"node": "{{user `proxmox_node_name`}}",
			"cores": "{{ user `cores` }}",
			"sockets": "{{ user `sockets` }}",
			"memory": "{{ user `memory` }}",
			"os": "l26",
			"scsi_controller": "virtio-scsi-pci",
			"network_adapters": [
				{
					"model": "virtio",
					"bridge": "vmbr0"
				}
			],
			"disks": [
				{
					"type": "scsi",
					"disk_size": "{{ user `disk_size`}}",
					"storage_pool": "{{user `datastore`}}",
					"storage_pool_type": "{{user `datastore_type`}}",
					"format": "raw",
					"cache_mode": "writeback"
				}
			],

			"ssh_timeout": "90m",
			"ssh_password": "{{ user `ssh_password` }}",
			"ssh_username": "{{ user `ssh_username` }}",

			"qemu_agent": true,
			"unmount_iso": true,

			"iso_file": "{{user `iso`}}",
			"template_description": "{{ user `template_description` }}",
			"template_name": "template-{{ user `template_name` }}",

			"additional_iso_files": [
				{
				"cd_files": [
				  "../boot_config/ubuntu/meta-data",
				  "../boot_config/ubuntu/user-data",
				  "../boot_config/ubuntu/preseed.cfg"
				],
				"iso_storage_pool": "local",
				"cd_label": "cidata"
				}
			],

			"boot_wait": "3s",
			"boot_command": [
                                "<enter><enter><f6><esc><wait>",
                                "autoinstall ip=dhcp ds=nocloud;<enter><wait>",
                                "<wait><enter>"
			]
		}
	],

But this HCL definitely does not work well, I get at least a dozen errors about either incorrect or in some what unsupported or not in the right place. This is more or less directly copied from my production code, with the differences between vsphere/proxmox as needed.

source "proxmox-iso" "ubuntu" {
  # Proxmox settings
  proxmox_url              = var.proxmox_url
  username                 = var.proxmox_username
  password                 = var.proxmox_password
  insecure_skip_tls_verify = var.proxmox_connection
  node                     = var.proxmox_node

  # VM Settings
  unmount_iso  = true
  ssh_username = var.connection_username
  ssh_password = var.connection_password
  ssh_timeout  = "20m"
  ssh_port     = "22"
  iso_file     = [var.os_iso_path]
  iso_checksum = var.iso_checksum
  vm_name      = "build-${local.vm_name}"
  os           = var.guest_os_type
  network_adapters {
    bridge = var.vm_bridge
    model  = var.nic_model
  }
  disks {
    disk_size         = var.root_disk_size
    type              = var.disk_type
    storage_pool      = local-zfs
    storage_pool_type = zfspool
    format            = raw
  }
  sockets      = var.num_cpu
  cores        = var.num_cores
  memory       = var.vm_ram
  boot_wait    = "5s"
  boot_command = var.boot_command

  additional_iso_files {
    cd_files = [
      "./boot_config/${var.os_family}/meta-data",
      "./boot_config/${var.os_family}/user-data",
      "./boot_config/${var.os_family}/preseed.cfg"
    ]
    cd_label = "cidata"
  }
  template_name        = "template_${local.vm_name}"
  #template_description = local.linux_notes
}

Running validate with PACKER_LOG=1 for both formats in windows side by side, they diverge after checking my default config directory, etc.

From validating the json code (aka working):

2022/09/03 23:15:05 Old default config directory found: /Users/myuser/.packer.d
2022/09/03 23:15:05 [TRACE] Starting internal plugin packer-builder-proxmox-iso
2022/09/03 23:15:05 Starting plugin: /usr/local/Cellar/packer/1.8.3/libexec/bin/packer []string{"/usr/local/Cellar/packer/1.8.3/libexec/bin/packer", "plugin", "packer-builder-proxmox-iso"}

It proceeds to repeat the config lookups again, but finally succeeds and reports the config is valid.

On the HCL code (aka not working):

2022/09/03 23:45:14 Old default config directory found: /Users/myuser/.packer.d
2022/09/03 23:45:14 [TRACE] validateValue: not active for proxmox_password, so skipping
2022/09/03 23:45:14 [TRACE] validateValue: not active for os_version, so skipping

The only thing I can think to try next is now that I have a json config that mostly works, I'll try hashi's converter tool to convert it to HCL, maybe there's a silly error there?

brantleyp1 avatar Sep 04 '22 04:09 brantleyp1

Well, I have a new theory but am too tired to test it now. I just went through and hard coded all the things that had been set in variable files and it validated cleanly. So maybe the issue isn't HCL, but somewhere in the variable lookup process...

Dunno, just food for thought.

brantleyp1 avatar Sep 04 '22 05:09 brantleyp1

Ok, I can't explain it, but I just went through and reconverted everything to variables and it still works. I did realize a few of the variables weren't wrapped in quotations, which might explain some of the errors, and the iso_file variable was wrapped in brackets, most likely because that's required on the vsphere builder. I hope all my issues weren't strictly from a silly template error.

This seems to work:

proxmox.pkr.hcl:

locals {
  linux_notes     = "Template based on ${var.os_family}-${var.os_version} with CIS hardening, built using packer on {{ isotime \"2006-01-02\" }} at {{isotime \"3:04PM\"}}"
  win_notes       = "Template based on ${var.os_family} ${var.os_version}, built using packer on {{ isotime \"2006-01-02\" }} at {{isotime \"3:04PM\"}}"
  vm_name         = "${var.os_family}${var.os_version}"
}

## ubuntu source
source "proxmox" "ubuntu" {
  # Proxmox settings
  proxmox_url              = var.proxmox_url
  username                 = var.proxmox_username
  password                 = var.proxmox_password
  insecure_skip_tls_verify = var.proxmox_connection
  node                     = var.proxmox_node

  # VM Settings
  unmount_iso  = true
  ssh_username = var.connection_username
  ssh_password = var.connection_password
  ssh_timeout  = var.timeout
  ssh_port     = "22"
  iso_file     = var.os_iso_path
  iso_checksum = var.iso_checksum
  vm_name      = "build-${local.vm_name}"
  os           = var.guest_os_type
  network_adapters {
    bridge = var.vm_bridge
    model  = var.nic_type
  }
  disks {
    disk_size         = var.root_disk_size
    type              = var.disk_type
    storage_pool      = var.storage_pool
    storage_pool_type = var.storage_pool_type
    format            = var.root_disc_format
  }
  sockets      = var.num_cpu
  cores        = var.num_cores
  memory       = var.vm_ram
  boot_wait    = "5s"
  boot_command = var.boot_command

  additional_iso_files {
    cd_files = [
      "./boot_config/${var.os_family}/meta-data",
      "./boot_config/${var.os_family}/user-data",
      "./boot_config/${var.os_family}/preseed.cfg"
    ]
    cd_label = "cidata"
    iso_storage_pool = "local"
  }
  template_name        = "template-${local.vm_name}"
  template_description = local.linux_notes
}

## ubuntu build
build {
  sources = [
    "source.proxmox.ubuntu",
  ]

  provisioner "shell" {
    execute_command = "sudo -S bash {{ .Path }}"
    script          = "./boot_config/ubuntu/baseInit.sh"
  }

  provisioner "ansible" {
    playbook_file = "ubuntu-cis-playbook.yml"
  }

  provisioner "ansible" {
    playbook_file = "./boot_config/ubuntu/fix_autoupdate.yml"
  }

  provisioner "ansible" {
    playbook_file = "/etc/ansible/playbook/home.yml"
  }

  provisioner "shell" {
    execute_command = "sudo -S bash {{ .Path }}"
    script          = "./boot_config/ubuntu/post_cleanup.sh"
  }
}

with variables.pkr.hcl:

variable "proxmox_url" {
  default     = "https://1.2.3.4:8006/api2/json"
}
variable "proxmox_username" {
  default     = "root@pam"
}
variable "proxmox_password" {
  description = "Password to authenticate to proxmox"
  default     = "apassword"
}
variable "proxmox_connection" {
  description = "true/false insecure_connection to proxmox"
  default     = "true"
}


variable "proxmox_node" {
  default     = "pve2"
}
variable "connection_username" {
  description = "username to connect to vm during build process"
  default     = "user"
}
variable "connection_password" {
  description = "password to connect to vm during build process"
  default     = "anotherpassword"
}
variable "timeout" {
  description = "not sure why I need so high a timeout but here we are"
  default = "90m"
}
variable "iso_checksum" {}
variable "os_version" {}
variable "os_iso_path" {}
variable "guest_os_type" {
  default = "l26"
}
variable "storage_pool" {
  default = "local-zfs"
}
variable "storage_pool_type" {
  default = "zfspool"
}
variable "disk_type" {
  default = "scsi"
}
variable "root_disc_format" {
  default = "raw"
}
variable "root_disk_size" {
  default = "20g"
}
variable "nic_type" {
  default = "virtio"
}
variable "vm_bridge" {
  default = "vmbr0"
}
variable "num_cpu" {
  default = 4
}
variable "num_cores" {
  default = 1
}
variable "vm_ram" {
  default = 4096
}
variable "os_family" {
  description = "OS Family builds the paths needed for packer"
  default     = ""
}
variable "boot_command" {} #set in specific var file

and I have a 20.04.pkrvars.hcl file with:

os_version = "2004"
os_family  = "ubuntu"
guest_os_type = "l26"
os_iso_path  = "local:iso/ubuntu-20.04.2-live-server-amd64.iso"
so_checksum = "d1f2bf834bbe9bb43faf16f9be992a6f3935e65be0edece1dee2aa6eb1767423"
boot_command = [
  "<enter><enter><f6><esc><wait>",
  "autoinstall ip=dhcp ds=nocloud;<enter><wait>",
  "<wait><enter>"
]

I'm building it with packer build -var-file=20.04.pkrvars.hcl --only proxmox.ubuntu .

brantleyp1 avatar Sep 04 '22 21:09 brantleyp1