I use the templatefile function to generate a preseed.cfg file, but it doesn't work with the packer-plugin-xenserver plugin, I usually do that with the vmware-iso plugin, which makes it difficult for me to modify the OS installation with a single configuration using a simple -var.
here is build script that i migrate from vmware-iso.
packer {
required_version = ">= 1.9.4"
required_plugins {
xenserver = {
version = ">= 0.7.4"
source = "github.com/vatesfr/xenserver"
}
}
}
locals {
build_os_environment_type = var.os_environment_type == "server" ? "Server" : "Desktop"
data_source_content = {
"ks.cfg" = templatefile("${path.root}/http/ks.pkrtpl.hcl", {
os_username = var.os_username
os_password = var.os_password
os_language = var.os_language
os_keyboard = var.os_keyboard
os_timezone = var.os_timezone
os_ntp_server = var.os_ntp_server
http_mirror = var.http_mirror
common_data_source = var.common_data_source
environment_type_package = var.os_environment_type == "desktop" ? join(" ", var.type_desktop_package) : ""
network = templatefile("${path.root}/http/network.pkrtpl.hcl", {
nic = var.vm_network_device
ip = var.vm_ip_address
netmask = var.vm_ip_netmask
gateway = var.vm_ip_gateway
dns = var.vm_dns_list
})
storage = templatefile("${path.root}/http/storage.pkrtpl.hcl", {
disk = var.vm_disk_device
swap = var.vm_disk_use_swap
partitions = var.vm_disk_partitions
lvm = var.vm_disk_lvm
})
additional_packages = join(" ", var.additional_packages)
})
}
data_source_command = var.common_data_source == "http" ? "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "file=/media/ks.cfg"
mount_cdrom_command = "<leftAltOn><f2><leftAltOff> <enter><wait> mount /dev/sr1 /media<enter> <leftAltOn><f1><leftAltOff>"
mount_cdrom = var.common_data_source == "http" ? " " : local.mount_cdrom_command
remove_sudoers_user = var.sudoers_remove == "true" ? var.os_username : "no_user"
vm_name = "${var.os_system_name} ${var.os_system_version} ${local.build_os_environment_type}"
}
source "xenserver-iso" "debian" {
iso_checksum = var.iso_checksum
iso_url = var.iso_url
sr_iso_name = var.sr_iso_name
sr_name = var.sr_name
tools_iso_name = var.tools_iso_name
remote_host = var.remote_host
remote_password = var.remote_password
remote_username = var.remote_username
http_directory = var.http_directory
ip_getter = var.ip_getter
boot_command = [
"<wait3s>c",
"linux /install.amd/vmlinuz<spacebar>",
"auto-install/enable=true<spacebar>",
"debconf/priority=critical<spacebar>",
"interface=${var.vm_network_device}<spacebar>",
"${local.data_source_command}<spacebar>",
"ipv6.disable=1<spacebar>",
"noprompt --<enter>",
"initrd /install.amd/initrd.gz<enter>",
"boot<enter>",
"<enter>",
"<enter>",
"${local.mount_cdrom}",
"<down><down><down><down><enter>"
]
firmware = var.firmware
boot_wait = var.boot_wait
clone_template = var.clone_template
vm_name = local.vm_name
vm_description = var.vm_description
vcpus_max = var.vcpus_max
vcpus_atstartup = var.vcpus_atstartup
vm_memory = var.vm_memory
network_names = var.network_names
disk_size = var.disk_size
disk_name = var.disk_name
vm_tags = var.vm_tags
ssh_username = var.ssh_username
ssh_password = var.ssh_password
ssh_wait_timeout = var.ssh_wait_timeout
ssh_handshake_attempts = var.ssh_handshake_attempts
output_directory = "${var.output_directory}/${local.vm_name}"
keep_vm = var.keep_vm
format = var.format
#floppy_files = []
}
build {
sources = ["xenserver-iso.debian"]
}
Can you tell me if there is another way to do this?
I use the templatefile function to generate a preseed.cfg file, but it doesn't work with the packer-plugin-xenserver plugin, I usually do that with the vmware-iso plugin, which makes it difficult for me to modify the OS installation with a single configuration using a simple -var.
here is build script that i migrate from vmware-iso.
packer { required_version = ">= 1.9.4" required_plugins { xenserver = { version = ">= 0.7.4" source = "github.com/vatesfr/xenserver" } } } locals { build_os_environment_type = var.os_environment_type == "server" ? "Server" : "Desktop" data_source_content = { "ks.cfg" = templatefile("${path.root}/http/ks.pkrtpl.hcl", { os_username = var.os_username os_password = var.os_password os_language = var.os_language os_keyboard = var.os_keyboard os_timezone = var.os_timezone os_ntp_server = var.os_ntp_server http_mirror = var.http_mirror common_data_source = var.common_data_source environment_type_package = var.os_environment_type == "desktop" ? join(" ", var.type_desktop_package) : "" network = templatefile("${path.root}/http/network.pkrtpl.hcl", { nic = var.vm_network_device ip = var.vm_ip_address netmask = var.vm_ip_netmask gateway = var.vm_ip_gateway dns = var.vm_dns_list }) storage = templatefile("${path.root}/http/storage.pkrtpl.hcl", { disk = var.vm_disk_device swap = var.vm_disk_use_swap partitions = var.vm_disk_partitions lvm = var.vm_disk_lvm }) additional_packages = join(" ", var.additional_packages) }) } data_source_command = var.common_data_source == "http" ? "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "file=/media/ks.cfg" mount_cdrom_command = "<leftAltOn><f2><leftAltOff> <enter><wait> mount /dev/sr1 /media<enter> <leftAltOn><f1><leftAltOff>" mount_cdrom = var.common_data_source == "http" ? " " : local.mount_cdrom_command remove_sudoers_user = var.sudoers_remove == "true" ? var.os_username : "no_user" vm_name = "${var.os_system_name} ${var.os_system_version} ${local.build_os_environment_type}" } source "xenserver-iso" "debian" { iso_checksum = var.iso_checksum iso_url = var.iso_url sr_iso_name = var.sr_iso_name sr_name = var.sr_name tools_iso_name = var.tools_iso_name remote_host = var.remote_host remote_password = var.remote_password remote_username = var.remote_username http_directory = var.http_directory ip_getter = var.ip_getter boot_command = [ "<wait3s>c", "linux /install.amd/vmlinuz<spacebar>", "auto-install/enable=true<spacebar>", "debconf/priority=critical<spacebar>", "interface=${var.vm_network_device}<spacebar>", "${local.data_source_command}<spacebar>", "ipv6.disable=1<spacebar>", "noprompt --<enter>", "initrd /install.amd/initrd.gz<enter>", "boot<enter>", "<enter>", "<enter>", "${local.mount_cdrom}", "<down><down><down><down><enter>" ] firmware = var.firmware boot_wait = var.boot_wait clone_template = var.clone_template vm_name = local.vm_name vm_description = var.vm_description vcpus_max = var.vcpus_max vcpus_atstartup = var.vcpus_atstartup vm_memory = var.vm_memory network_names = var.network_names disk_size = var.disk_size disk_name = var.disk_name vm_tags = var.vm_tags ssh_username = var.ssh_username ssh_password = var.ssh_password ssh_wait_timeout = var.ssh_wait_timeout ssh_handshake_attempts = var.ssh_handshake_attempts output_directory = "${var.output_directory}/${local.vm_name}" keep_vm = var.keep_vm format = var.format #floppy_files = [] } build { sources = ["xenserver-iso.debian"] }Can you tell me if there is another way to do this?