-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
32 lines (25 loc) · 1.29 KB
/
deploy.ps1
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
param(
[pscredential]$credential,
[switch]$all
)
$buildVarFile = "../vars/vsphere-iso.pkrvars.hcl"
if (!(test-path $buildVarFile)) { $buildVarFile = "variables/build/vsphere-iso.pkrvars.hcl" }
if (!$credential) { $credential = get-credential }
$templates = (Get-ChildItem .\variables\os\).name
$menu = @{}
for ($i = 1; $i -le $templates.count; $i++) {
Write-Host "$i. $($templates[$i-1])"
$menu.Add($i, ($templates[$i - 1], $($templates[$i - 1].split(".")[0] + "." + $templates[$i - 1].split(".")[1])))
}
if (!$all.IsPresent) {
[int]$option = Read-Host 'Enter selection (enter 0 to deploy all templates)'
}
packer init .
if ($option -eq 0 -or $all.IsPresent) {
for ($option = 1; $option -le $menu.count; $option++) {
packer build -force --only=$($menu.item($option)[1]) --var-file=$buildVarFile --var-file="variables/os/$($menu.item($option)[0])" -var "vcenter_username=$($Credential.username)" -var "vcenter_password=$($Credential.GetNetworkCredential().Password)" .
}
}
else {
packer build -force --only=$($menu.item($option)[1]) --var-file=$buildVarFile --var-file="variables/os/$($menu.item($option)[0])" -var "vcenter_username=$($Credential.username)" -var "vcenter_password=$($Credential.GetNetworkCredential().Password)" .
}