Json worked, hcl2 doesn’t. I’m completely new to Packer and I need a way to replace kickstart injection on kvm based hypervisor to vSphere, and I can’t use pxe boot.
I stared working with json because I didn’t realize it was deprecated and replaced with hcl2. My json was working until I converted it to hcl2 and now I’m at a loss. Im looking at examples and my own files and I could use some help here.
The first one is basically just copy/paste from Vmware examples.
vsphere_endpoint = "vcenter.internal.domain.net"
vsphere_username = "Administrator@vsphere.local"
vsphere_password = "blablabla"
vsphere_insecure_connection = true
vsphere_datacenter = "lab"
vsphere_cluster = "esxi.internal.domain.net"
vsphere_datastore = "ds_lab"
vsphere_network = "vmnet_lab"
vsphere_folder = "lab-packer-test"
vsphere_set_host_for_datastore_uploads = false
Then there is this packer-test:
packer {
required_plugins {
vsphere = {
source = "github.com/hashicorp/vsphere"
version = "~> 1"
}
}
}
variable "HTTP_IP" {
type = string
default = "10.0.0.10:81"
}
variable "HTTP_PATH" {
type = string
default = "packer-test/ks.cfg"
}
variable "version" {
type = string
default = "0.0.3"
}
source "vsphere-iso" "autogenerated_1" {
CPU_hot_plug = true
CPUs = 2
RAM = 4096
RAM_hot_plug = true
boot_command = ["<up><tab><bs><bs><bs><bs><bs><bs> text ip=dhcp hostname=packer-test inst.ks=http://${var.HTTP_IP}/${var.HTTP_PATH}<enter><wait><enter>"]
cluster = "${var.vsphere_cluster}"
convert_to_template = false
create_snapshot = false
datacenter = "${var.vsphere_datacenter}"
datastore = "${var.vsphere_datastore}"
disk_controller_type = "pvscsi"
folder = "${var.lan-test}"
guest_os_type = "rockylinux_64Guest"
host = "${var.vsphere_host}"
insecure_connection = "${var.vsphere_insecure_connection}"
iso_paths = [" [${var.vsphere_datastore}] isos/rocky-8.8-x86_64-dvd1.iso"]
network_adapters {
network = "${var.vsphere_network}"
network_card = "vmxnet3"
}
notes = "Packer test RockyLinux version ${var.version}"
password = "${var.vsphere_password}"
shutdown_command = "/sbin/halt -h -p"
ssh_username = "ingemar"
ssh_private_key_file = "/Users/itsme/.ssh/id_rsa"
storage {
disk_size = 120000
disk_thin_provisioned = true
}
username = "${var.vsphere_username}"
vcenter_server = "${var.vsphere_host}"
vm_name = "packer-test"
}
build {
sources = ["source.vsphere-iso.autogenerated_1"]
provisioner "shell" {
execute_command = "bash '{{ .Path }}'"
expect_disconnect = true
script = "${path.root}/requirements.sh"
}
}
Whether I specify the build with -var-file=
or without doesn’t seem to matter. From what I gather it looks for files in the same dir.
This what happens:
packer build packer-test.json.pkr.hcl
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 62:
(source code not available)
This object does not have an attribute named "vsphere_insecure_connection".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 78:
(source code not available)
This object does not have an attribute named "vsphere_host".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 53:
(source code not available)
This object does not have an attribute named "vsphere_cluster".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 65:
(source code not available)
This object does not have an attribute named "vsphere_network".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 56:
(source code not available)
This object does not have an attribute named "vsphere_datacenter".
Error: Incorrect attribute value type
on packer-test.json.pkr.hcl line 58:
(source code not available)
Inappropriate value for attribute "disk_controller_type": list of string
required.
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 59:
(source code not available)
This object does not have an attribute named "lan-test".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 57:
(source code not available)
This object does not have an attribute named "vsphere_datastore".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 69:
(source code not available)
This object does not have an attribute named "vsphere_password".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 63:
(source code not available)
This object does not have an attribute named "vsphere_datastore".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 61:
(source code not available)
This object does not have an attribute named "vsphere_host".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 77:
(source code not available)
This object does not have an attribute named "vsphere_username".
So it doesn’t pick up any variable it seems?
When I specify both files with -var-file=
the same thing happens:
packer build -var-file=vsphere.pkrvars.hcl packer-test.json.pkr.hcl
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 77:
(source code not available)
This object does not have an attribute named "vsphere_username".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 56:
(source code not available)
This object does not have an attribute named "vsphere_datacenter".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 63:
(source code not available)
This object does not have an attribute named "vsphere_datastore".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 61:
(source code not available)
This object does not have an attribute named "vsphere_host".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 69:
(source code not available)
This object does not have an attribute named "vsphere_password".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 57:
(source code not available)
This object does not have an attribute named "vsphere_datastore".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 78:
(source code not available)
This object does not have an attribute named "vsphere_host".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 53:
(source code not available)
This object does not have an attribute named "vsphere_cluster".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 59:
(source code not available)
This object does not have an attribute named "lan-test".
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 62:
(source code not available)
This object does not have an attribute named "vsphere_insecure_connection".
Error: Incorrect attribute value type
on packer-test.json.pkr.hcl line 58:
(source code not available)
Inappropriate value for attribute "disk_controller_type": list of string
required.
Error: Unsupported attribute
on packer-test.json.pkr.hcl line 65:
(source code not available)
This object does not have an attribute named "vsphere_network".
Could someone please have a look at those files and help me out?
Appreciate the help!
Thanks.