Packer.Images/packer/windowsserver2019.pkr.hcl

308 lines
9.4 KiB
HCL
Raw Normal View History

packer {
required_plugins {
windows-update = {
2021-06-04 20:39:31 +00:00
version = ">= 0.12.0"
source = "github.com/rgl/windows-update"
}
}
}
source "vsphere-iso" "srv2019-template" {
vcenter_server = var.vcenter_server
username = var.vsphere_username
password = var.vsphere_password
insecure_connection = "true"
vm_name = "${var.vm_guestos}-${var.vm_name}-template"
datacenter = var.vsphere_datacenter
host = var.vsphere_host
folder = var.vsphere_folder
datastore = var.vsphere_datastore
guest_os_type = "windows9Server64Guest"
boot_order = "disk,cdrom"
2021-06-04 17:20:25 +00:00
boot_command = [""]
boot_wait = "5m"
communicator = "winrm"
winrm_username = "administrator"
winrm_password = var.winrm_password
winrm_timeout = "10m"
2021-06-22 17:40:08 +00:00
RAM = 4096
2021-06-04 17:20:25 +00:00
CPUs = 2
network_adapters {
network = var.vsphere_network
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"]
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"
]
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"
2021-06-04 17:20:25 +00:00
export {
images = false
output_directory = "/scratch/srv2019-template"
}
remove_cdrom = true
}
source "vsphere-iso" "srv2019-virtual" {
vcenter_server = var.vcenter_server
username = var.vsphere_username
password = var.vsphere_password
insecure_connection = "true"
vm_name = "${var.vm_guestos}-${var.vm_name}-virtual"
datacenter = var.vsphere_datacenter
host = var.vsphere_host
folder = var.vsphere_folder
datastore = var.vsphere_datastore
guest_os_type = "windows9Server64Guest"
boot_order = "disk,cdrom"
2021-06-04 17:20:25 +00:00
boot_command = [""]
boot_wait = "5m"
communicator = "winrm"
winrm_password = var.winrm_password
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
network_adapters {
network = var.vsphere_network
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"]
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"
]
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
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"]
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"
]
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"
2021-06-04 17:20:25 +00:00
export {
images = false
output_directory = "/scratch/srv2019-baremetal"
}
remove_cdrom = true
}
build {
sources = [
"source.vsphere-iso.srv2019-template",
"source.vsphere-iso.srv2019-virtual",
"source.vsphere-iso.srv2019-baremetal"
]
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]
}
provisioner "windows-update" {
}
provisioner "powershell" {
only = ["vsphere-iso.srv2019-virtual"]
inline = [
"New-Item -Path 'C:\\Payload\\Scripts' -ItemType 'Directory' -Force:$True -Confirm:$False"
]
}
provisioner "file" {
only = ["vsphere-iso.srv2019-virtual"]
destination = "C:\\Payload\\"
source = "scripts/Server2019/payload/"
}
provisioner "powershell" {
only = ["vsphere-iso.srv2019-virtual"]
scripts = [
"scripts/Server2019/Register-ScheduledTask.ps1"
]
}
post-processors {
post-processor "vsphere" {
only = ["vsphere-iso.srv2019-template"]
host = var.vcenter_server
username = var.vsphere_username
password = var.vsphere_password
insecure = true
vm_name = "Windows-Server-2019-LTSC"
datacenter = var.vsphere_datacenter
cluster = var.vsphere_host
vm_folder = var.vsphere_templatefolder
vm_network = var.vsphere_network
datastore = var.vsphere_datastore
disk_mode = "thin"
keep_input_artifact = true
overwrite = true
}
post-processor "vsphere-template" {
only = ["vsphere-iso.srv2019-template"]
host = var.vcenter_server
username = var.vsphere_username
password = var.vsphere_password
insecure = true
datacenter = var.vsphere_datacenter
folder = var.vsphere_templatefolder
reregister_vm = false
}
}
post-processor "shell-local" {
only = ["vsphere-iso.srv2019-virtual"]
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' \\",
" -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'",
"ovftool --acceptAllEulas --allowExtraConfig --overwrite \\",
2021-06-21 14:33:11 +00:00
" '/scratch/srv2019-virtual/${var.vm_guestos}-${var.vm_name}-virtual.ovf' \\",
" /output/Windows-Server-2019-LTSC.ova"
]
}
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",
"gzip -c \\",
2021-06-22 07:54:45 +00:00
" /tmp/${var.vm_guestos}-${var.vm_name}.raw \\",
" > /output/Windows-Server-2019-LTSC.raw.gz"
]
}
}