-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacker-winserver2022.ps1
More file actions
53 lines (46 loc) · 1.48 KB
/
Packer-winserver2022.ps1
File metadata and controls
53 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Build images
# Get Start Time
$startDTM = (Get-Date)
# Variables
$OS = "winserver2022"
$machine = "Windows Server 2022 Datacenter Gen-2 Vagrant"
$template_file = ".\Templates\$OS\Template.pkr.hcl"
$var_file = ".\Templates\$OS\Variables.pkr.hcl"
$vbox = ".\VagrantBox\packer-$OS.box"
$vbox_checksum = ".\VagrantBox\packer-$OS.box.sha256"
$packer_log = 0
Write-Host "Build secondary.iso for Windows VM on Hyper-V"
.\Scripts\New-IsoFile.ps1 ".\Templates\$OS\XML\Autounattend.xml",".\Scripts\Hyper-V\bootstrap.ps1" -Path ".\Templates\$OS\secondary.iso" -Force
Write-Host "secondary.iso created."
# Packer Script
if ((Test-Path -Path "$template_file") -and (Test-Path -Path "$var_file")) {
Write-Output "Template and var file found"
Write-Output "Building: $machine"
try {
$env:PACKER_LOG=$packer_log
packer validate -var-file="$var_file" "$template_file"
}
catch {
Write-Output "Packer validation failed, exiting."
exit (-1)
}
try {
$env:PACKER_LOG=$packer_log
packer version
packer build --force -var-file="$var_file" "$template_file"
if ($?) {
Write-Output "Calculating checksums"
Get-FileHash -Algorithm SHA256 -Path "$vbox"|Out-File "$vbox_checksum" -Verbose
}
}
catch {
Write-Output "Packer build failed, exiting."
exit (-1)
}
}
else {
Write-Output "Template or Var file not found - exiting"
exit (-1)
}
$endDTM = (Get-Date)
Write-Host "[INFO] - Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds" -ForegroundColor Yellow