2021-06-04 14:41:43 +00:00
|
|
|
packer {
|
|
|
|
required_plugins {
|
|
|
|
windows-update = {
|
2021-06-04 20:39:31 +00:00
|
|
|
version = ">= 0.12.0"
|
2021-06-04 14:41:43 +00:00
|
|
|
source = "github.com/rgl/windows-update"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 07:28:22 +00:00
|
|
|
source "vsphere-iso" "srv2019-template" {
|
2021-06-04 20:31:04 +00:00
|
|
|
vcenter_server = var.vcenter_server
|
|
|
|
username = var.vsphere_username
|
|
|
|
password = var.vsphere_password
|
2021-06-04 14:41:43 +00:00
|
|
|
insecure_connection = "true"
|
|
|
|
|
2021-06-21 07:28:22 +00:00
|
|
|
vm_name = "${var.vm_guestos}-${var.vm_name}-template"
|
2021-06-04 20:31:04 +00:00
|
|
|
datacenter = var.vsphere_datacenter
|
|
|
|
host = var.vsphere_host
|
|
|
|
folder = var.vsphere_folder
|
|
|
|
datastore = var.vsphere_datastore
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
guest_os_type = "windows9Server64Guest"
|
|
|
|
|
|
|
|
boot_order = "disk,cdrom"
|
2021-06-04 17:20:25 +00:00
|
|
|
boot_command = [""]
|
2021-06-04 14:41:43 +00:00
|
|
|
boot_wait = "5m"
|
|
|
|
|
|
|
|
communicator = "winrm"
|
|
|
|
winrm_username = "administrator"
|
2021-06-04 20:31:04 +00:00
|
|
|
winrm_password = var.winrm_password
|
2021-06-04 14:41:43 +00:00
|
|
|
winrm_timeout = "10m"
|
|
|
|
|
2021-06-22 17:40:08 +00:00
|
|
|
RAM = 4096
|
2021-06-04 17:20:25 +00:00
|
|
|
CPUs = 2
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
network_adapters {
|
2021-06-04 20:31:04 +00:00
|
|
|
network = var.vsphere_network
|
2021-06-04 14:41:43 +00:00
|
|
|
network_card = "vmxnet3"
|
|
|
|
}
|
|
|
|
storage {
|
|
|
|
disk_size = 20480
|
|
|
|
disk_thin_provisioned = true
|
|
|
|
}
|
2021-06-04 17:20:25 +00:00
|
|
|
disk_controller_type = ["lsilogic-sas"]
|
|
|
|
usb_controller = ["xhci"]
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
floppy_files = [
|
|
|
|
"packer/preseed/Server2019/Autounattend.xml",
|
|
|
|
"packer/preseed/Server2019/Sysprep_Unattend.xml",
|
|
|
|
"scripts/Set-NetworkProfile.ps1",
|
|
|
|
"scripts/Disable-WinRM.ps1",
|
|
|
|
"scripts/Enable-WinRM.ps1",
|
|
|
|
"scripts/Install-VMwareTools.cmd"
|
|
|
|
]
|
2021-06-21 07:28:22 +00:00
|
|
|
iso_url = local.iso_authenticatedurl
|
|
|
|
iso_checksum = var.iso_checksum
|
|
|
|
iso_paths = var.iso_paths
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
shutdown_command = "C:\\Windows\\System32\\Sysprep\\sysprep.exe /generalize /oobe /unattend:A:\\Sysprep_Unattend.xml"
|
|
|
|
shutdown_timeout = "1h"
|
|
|
|
|
2021-06-04 17:20:25 +00:00
|
|
|
export {
|
2021-06-04 14:41:43 +00:00
|
|
|
images = false
|
2021-06-21 07:28:22 +00:00
|
|
|
output_directory = "/scratch/srv2019-template"
|
2021-06-04 14:41:43 +00:00
|
|
|
}
|
|
|
|
remove_cdrom = true
|
|
|
|
}
|
|
|
|
|
2021-06-21 07:28:22 +00:00
|
|
|
source "vsphere-iso" "srv2019-virtual" {
|
2021-06-04 20:31:04 +00:00
|
|
|
vcenter_server = var.vcenter_server
|
|
|
|
username = var.vsphere_username
|
|
|
|
password = var.vsphere_password
|
2021-06-04 14:41:43 +00:00
|
|
|
insecure_connection = "true"
|
|
|
|
|
2021-06-21 07:28:22 +00:00
|
|
|
vm_name = "${var.vm_guestos}-${var.vm_name}-virtual"
|
2021-06-04 20:31:04 +00:00
|
|
|
datacenter = var.vsphere_datacenter
|
|
|
|
host = var.vsphere_host
|
|
|
|
folder = var.vsphere_folder
|
|
|
|
datastore = var.vsphere_datastore
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
guest_os_type = "windows9Server64Guest"
|
2021-06-21 07:28:22 +00:00
|
|
|
|
2021-06-04 14:41:43 +00:00
|
|
|
boot_order = "disk,cdrom"
|
2021-06-04 17:20:25 +00:00
|
|
|
boot_command = [""]
|
2021-06-04 14:41:43 +00:00
|
|
|
boot_wait = "5m"
|
|
|
|
|
|
|
|
communicator = "winrm"
|
2021-06-04 20:31:04 +00:00
|
|
|
winrm_password = var.winrm_password
|
2021-06-04 14:41:43 +00:00
|
|
|
winrm_timeout = "10m"
|
|
|
|
winrm_username = "administrator"
|
|
|
|
|
2021-06-22 17:40:08 +00:00
|
|
|
RAM = 4096
|
2021-06-04 17:20:25 +00:00
|
|
|
CPUs = 2
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
network_adapters {
|
2021-06-04 20:31:04 +00:00
|
|
|
network = var.vsphere_network
|
2021-06-04 14:41:43 +00:00
|
|
|
network_card = "vmxnet3"
|
|
|
|
}
|
|
|
|
storage {
|
|
|
|
disk_size = 20480
|
|
|
|
disk_thin_provisioned = true
|
|
|
|
}
|
2021-06-04 17:20:25 +00:00
|
|
|
disk_controller_type = ["lsilogic-sas"]
|
|
|
|
usb_controller = ["xhci"]
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
floppy_files = [
|
|
|
|
"packer/preseed/Server2019/Autounattend.xml",
|
|
|
|
"packer/preseed/Server2019/Sysprep_Unattend.xml",
|
|
|
|
"scripts/Set-NetworkProfile.ps1",
|
|
|
|
"scripts/Disable-WinRM.ps1",
|
|
|
|
"scripts/Enable-WinRM.ps1",
|
|
|
|
"scripts/Install-VMwareTools.cmd"
|
|
|
|
]
|
2021-06-21 07:28:22 +00:00
|
|
|
iso_url = local.iso_authenticatedurl
|
|
|
|
iso_checksum = var.iso_checksum
|
|
|
|
iso_paths = var.iso_paths
|
|
|
|
|
|
|
|
shutdown_command = "C:\\Windows\\System32\\Sysprep\\sysprep.exe /generalize /oobe /unattend:A:\\Sysprep_Unattend.xml"
|
|
|
|
shutdown_timeout = "1h"
|
|
|
|
|
|
|
|
export {
|
|
|
|
images = false
|
|
|
|
output_directory = "/scratch/srv2019-virtual"
|
|
|
|
}
|
|
|
|
remove_cdrom = true
|
|
|
|
}
|
|
|
|
|
|
|
|
source "vsphere-iso" "srv2019-baremetal" {
|
|
|
|
vcenter_server = var.vcenter_server
|
|
|
|
username = var.vsphere_username
|
|
|
|
password = var.vsphere_password
|
|
|
|
insecure_connection = "true"
|
|
|
|
|
|
|
|
vm_name = "${var.vm_guestos}-${var.vm_name}-baremetal"
|
|
|
|
datacenter = var.vsphere_datacenter
|
|
|
|
host = var.vsphere_host
|
|
|
|
folder = var.vsphere_folder
|
|
|
|
datastore = var.vsphere_datastore
|
|
|
|
|
|
|
|
guest_os_type = "windows9Server64Guest"
|
|
|
|
|
|
|
|
boot_order = "disk,cdrom"
|
|
|
|
boot_command = [""]
|
|
|
|
boot_wait = "5m"
|
|
|
|
|
|
|
|
communicator = "winrm"
|
|
|
|
winrm_username = "administrator"
|
|
|
|
winrm_password = var.winrm_password
|
|
|
|
winrm_timeout = "10m"
|
|
|
|
|
2021-06-22 13:47:47 +00:00
|
|
|
RAM = 4096
|
2021-06-21 07:28:22 +00:00
|
|
|
CPUs = 2
|
|
|
|
|
|
|
|
network_adapters {
|
|
|
|
network = var.vsphere_network
|
|
|
|
network_card = "vmxnet3"
|
|
|
|
}
|
|
|
|
storage {
|
|
|
|
disk_size = 20480
|
|
|
|
disk_thin_provisioned = true
|
|
|
|
}
|
2021-06-22 17:40:08 +00:00
|
|
|
disk_controller_type = ["lsilogic"]
|
2021-06-21 07:28:22 +00:00
|
|
|
usb_controller = ["xhci"]
|
|
|
|
|
|
|
|
floppy_files = [
|
|
|
|
"packer/preseed/Server2019/Autounattend.xml",
|
|
|
|
"packer/preseed/Server2019/Sysprep_Unattend.xml",
|
|
|
|
"scripts/Set-NetworkProfile.ps1",
|
|
|
|
"scripts/Disable-WinRM.ps1",
|
|
|
|
"scripts/Enable-WinRM.ps1",
|
|
|
|
"scripts/Install-VMwareTools.cmd"
|
2021-06-04 14:41:43 +00:00
|
|
|
]
|
2021-06-21 07:28:22 +00:00
|
|
|
iso_url = local.iso_authenticatedurl
|
|
|
|
iso_checksum = var.iso_checksum
|
|
|
|
iso_paths = var.iso_paths
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
shutdown_command = "C:\\Windows\\System32\\Sysprep\\sysprep.exe /generalize /oobe /unattend:A:\\Sysprep_Unattend.xml"
|
|
|
|
shutdown_timeout = "1h"
|
|
|
|
|
2021-06-04 17:20:25 +00:00
|
|
|
export {
|
2021-06-04 14:41:43 +00:00
|
|
|
images = false
|
2021-06-21 07:28:22 +00:00
|
|
|
output_directory = "/scratch/srv2019-baremetal"
|
2021-06-04 14:41:43 +00:00
|
|
|
}
|
|
|
|
remove_cdrom = true
|
|
|
|
}
|
|
|
|
|
|
|
|
build {
|
|
|
|
sources = [
|
2021-06-21 07:28:22 +00:00
|
|
|
"source.vsphere-iso.srv2019-template",
|
|
|
|
"source.vsphere-iso.srv2019-virtual",
|
|
|
|
"source.vsphere-iso.srv2019-baremetal"
|
2021-06-04 14:41:43 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
provisioner "windows-update" {
|
|
|
|
}
|
|
|
|
|
2021-06-22 07:54:45 +00:00
|
|
|
// provisioner "powershell" {
|
2021-06-22 14:41:19 +00:00
|
|
|
// scripts = [
|
|
|
|
// "scripts/Install-WinGet.ps1"
|
2021-06-22 07:54:45 +00:00
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
// provisioner "powershell" {
|
2021-06-22 14:41:19 +00:00
|
|
|
// inline = [
|
|
|
|
// "winget install mozilla.firefox",
|
|
|
|
// "winget install 7zip.7zip",
|
|
|
|
// "winget install microsoft.dotnetframework"
|
2021-06-22 07:54:45 +00:00
|
|
|
// ]
|
2021-06-22 14:41:19 +00:00
|
|
|
// // valid_exit_codes = [0, 3010]
|
2021-06-22 07:54:45 +00:00
|
|
|
// }
|
2021-06-22 14:41:19 +00:00
|
|
|
provisioner "powershell" {
|
|
|
|
inline = [
|
|
|
|
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12",
|
|
|
|
"Invoke-Expression ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
provisioner "powershell" {
|
|
|
|
inline = [
|
|
|
|
"choco config set --name=limit-output --value=LimitOutput",
|
|
|
|
"choco install -y dotnetfx",
|
|
|
|
"choco install -y 7zip.install",
|
|
|
|
"choco install -y sysinternals",
|
|
|
|
"choco install -y firefox"
|
|
|
|
]
|
|
|
|
valid_exit_codes = [0, 3010]
|
|
|
|
}
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
provisioner "windows-update" {
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "powershell" {
|
2021-06-21 07:28:22 +00:00
|
|
|
only = ["vsphere-iso.srv2019-virtual"]
|
2021-06-04 14:41:43 +00:00
|
|
|
inline = [
|
|
|
|
"New-Item -Path 'C:\\Payload\\Scripts' -ItemType 'Directory' -Force:$True -Confirm:$False"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2021-06-21 07:28:22 +00:00
|
|
|
only = ["vsphere-iso.srv2019-virtual"]
|
2021-06-04 14:41:43 +00:00
|
|
|
destination = "C:\\Payload\\"
|
|
|
|
source = "scripts/Server2019/payload/"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "powershell" {
|
2021-06-21 07:28:22 +00:00
|
|
|
only = ["vsphere-iso.srv2019-virtual"]
|
2021-06-04 14:41:43 +00:00
|
|
|
scripts = [
|
|
|
|
"scripts/Server2019/Register-ScheduledTask.ps1"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
post-processors {
|
|
|
|
post-processor "vsphere" {
|
2021-06-21 07:28:22 +00:00
|
|
|
only = ["vsphere-iso.srv2019-template"]
|
2021-06-04 14:41:43 +00:00
|
|
|
|
2021-06-04 20:31:04 +00:00
|
|
|
host = var.vcenter_server
|
|
|
|
username = var.vsphere_username
|
|
|
|
password = var.vsphere_password
|
2021-06-04 14:41:43 +00:00
|
|
|
insecure = true
|
|
|
|
|
|
|
|
vm_name = "Windows-Server-2019-LTSC"
|
2021-06-04 20:31:04 +00:00
|
|
|
datacenter = var.vsphere_datacenter
|
|
|
|
cluster = var.vsphere_host
|
|
|
|
vm_folder = var.vsphere_templatefolder
|
|
|
|
vm_network = var.vsphere_network
|
|
|
|
datastore = var.vsphere_datastore
|
2021-06-04 14:41:43 +00:00
|
|
|
disk_mode = "thin"
|
|
|
|
|
|
|
|
keep_input_artifact = true
|
|
|
|
overwrite = true
|
|
|
|
}
|
|
|
|
post-processor "vsphere-template" {
|
2021-06-21 07:28:22 +00:00
|
|
|
only = ["vsphere-iso.srv2019-template"]
|
2021-06-04 14:41:43 +00:00
|
|
|
|
2021-06-04 20:31:04 +00:00
|
|
|
host = var.vcenter_server
|
|
|
|
username = var.vsphere_username
|
|
|
|
password = var.vsphere_password
|
2021-06-04 14:41:43 +00:00
|
|
|
insecure = true
|
|
|
|
|
2021-06-04 20:31:04 +00:00
|
|
|
datacenter = var.vsphere_datacenter
|
|
|
|
folder = var.vsphere_templatefolder
|
2021-06-04 14:41:43 +00:00
|
|
|
|
|
|
|
reregister_vm = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post-processor "shell-local" {
|
2021-06-21 07:28:22 +00:00
|
|
|
only = ["vsphere-iso.srv2019-virtual"]
|
2021-06-04 14:41:43 +00:00
|
|
|
inline = [
|
|
|
|
"pwsh -command \"& scripts/Update-OvfConfiguration.ps1 \\",
|
2021-06-21 14:33:11 +00:00
|
|
|
" -OVFFile '/scratch/srv2019-virtual/${var.vm_guestos}-${var.vm_name}-virtual.ovf' \\",
|
2021-06-04 14:41:43 +00:00
|
|
|
" -Parameter @{'appliance.name'='${var.vm_guestos}';'appliance.version'='${var.vm_name}'}\"",
|
|
|
|
"pwsh -file scripts/Update-Manifest.ps1 \\",
|
2021-06-21 14:33:11 +00:00
|
|
|
" -ManifestFileName '/scratch/srv2019-virtual/${var.vm_guestos}-${var.vm_name}-virtual.mf'",
|
2021-06-04 14:41:43 +00:00
|
|
|
"ovftool --acceptAllEulas --allowExtraConfig --overwrite \\",
|
2021-06-21 14:33:11 +00:00
|
|
|
" '/scratch/srv2019-virtual/${var.vm_guestos}-${var.vm_name}-virtual.ovf' \\",
|
2021-06-04 14:41:43 +00:00
|
|
|
" /output/Windows-Server-2019-LTSC.ova"
|
|
|
|
]
|
|
|
|
}
|
2021-06-21 07:28:22 +00:00
|
|
|
post-processor "shell-local" {
|
|
|
|
only = ["vsphere-iso.srv2019-baremetal"]
|
|
|
|
inline = [
|
|
|
|
"qemu-img convert -f vmdk -O raw \\",
|
|
|
|
" /scratch/srv2019-baremetal/${var.vm_guestos}-${var.vm_name}-baremetal-disk-0.vmdk \\",
|
2021-06-22 07:54:45 +00:00
|
|
|
" /tmp/${var.vm_guestos}-${var.vm_name}.raw",
|
2021-06-21 07:28:22 +00:00
|
|
|
"gzip -c \\",
|
2021-06-22 07:54:45 +00:00
|
|
|
" /tmp/${var.vm_guestos}-${var.vm_name}.raw \\",
|
2021-06-21 07:28:22 +00:00
|
|
|
" > /output/Windows-Server-2019-LTSC.raw.gz"
|
|
|
|
]
|
|
|
|
}
|
2021-06-04 14:41:43 +00:00
|
|
|
}
|