我是包装工的新手。这就是我想要实现的目标。我想根据是否定义了 vm-disk-size2 来创建具有单个存储磁盘或双存储磁盘的 centos VM。如何通过变量传递整个存储映射?基本上我试图从命令行或文件中将“storage { disk_size = var.vm-disk-size, disk_thin_provisioned = true }”作为变量传递。
source "vsphere-iso" "centos" {
CPUs = var.vm-cpu-num
RAM = var.vm-mem-size
RAM_reserve_all = false
boot_command = [
"<tab> inst.text inst.ks=hd:fd0:/${ var.ks-file } <enter><wait>"
]
boot_order = "disk,cdrom,floppy"
boot_wait = "10s"
cluster = var.vsphere-cluster
communicator = "ssh"
convert_to_template = true
datastore = var.vsphere-datastore
disk_controller_type = ["pvscsi"]
floppy_files = [
var.ks-file
]
guest_os_type = "centos7_64Guest"
host = var.vsphere-host
insecure_connection = "true"
iso_paths = [
var.iso_url
]
network_adapters {
network = var.vsphere-network
network_card = "vmxnet3"
}
notes = "Build via Packer"
password = var.vsphere-password
ssh_password = var.ssh_password
ssh_username = "root"
storage {
disk_size = var.vm-disk-size
disk_thin_provisioned = true
}
storage {
disk_size = var.vm-disk-size2
disk_thin_provisioned = true
}
username = var.vsphere_user
vcenter_server = var.vsphere-server
vm_name = var.vm-name
}
我正在尝试这样的事情,但还没有运气..
dynamic "storage" {
for_each = var.storage
content {
disk_size = storage.key
disk_thin_provisioned = true
}
}
并且存储被定义为 variables.pkr.hcl 中的列表变量
variable "storage" { default = [] }
像这样运行 Packer:
packer build -var ks-file='"ks-2disk.cf"' -var storage='"["51200","25600"]"' .
此时出现此错误:Error: Extra characters after expression
第 1 行:(源代码不可用)
成功解析了一个表达式,但在它后面发现了多余的字符。