Skip to content

Commit

Permalink
add support for the vsphere builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Jul 30, 2018
1 parent c61ddf2 commit d64ca87
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ build-libvirt: windows-2016-amd64-libvirt.box

build-virtualbox: windows-2016-amd64-virtualbox.box

build-vsphere: windows-2016-amd64-vsphere.box

build-windows-2019-virtualbox: windows-2019-amd64-virtualbox.box

build-windows-server-core-1709-libvirt: windows-server-core-1709-amd64-libvirt.box
Expand Down Expand Up @@ -33,6 +35,11 @@ windows-2016-amd64-virtualbox.box: windows-2016.json autounattend.xml Vagrantfil
@echo to add to local vagrant install do:
@echo vagrant box add -f windows-2016-amd64 $@

windows-2016-amd64-vsphere.box: windows-2016.json autounattend.xml Vagrantfile.template *.ps1
rm -f $@
CHECKPOINT_DISABLE=1 packer build -on-error=abort windows-2016-vsphere.json
@echo BOX successfully built!

windows-2019-amd64-virtualbox.box: windows-2019.json autounattend.xml Vagrantfile.template *.ps1
rm -f $@
CHECKPOINT_DISABLE=1 packer build -only=windows-2019-amd64-virtualbox -on-error=abort windows-2019.json
Expand Down
20 changes: 20 additions & 0 deletions README-vsphere.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Download the latest `packer-builder-vsphere-iso.exe` release from [jetbrains-infra/packer-builder-vsphere](https://github.com/jetbrains-infra/packer-builder-vsphere/releases) and place it inside your `%APPDATA%\packer.d\plugins` directory.

Download the Windows Evaluation iso (you can find the full iso URL in the [windows-2016.json](windows-2016.json) file) and place it inside the datastore as defined by the `vsphere_iso_url` user variable that is inside the [packer template](windows-2016-vsphere.json).

Download the VMware Tools zip and extract the `windows.iso` file into the datastore defined by the `vsphere_tools_iso_url` user variable that is inside the [packer template](windows-2016-vsphere.json).

Build the base box with:

```bash
make build-vsphere
```

**NB** the generated template will include a reference to the extra iso images that were used to create the template, which is a bummer.

**NB** these errors are expected (should be fixed when https://github.com/jetbrains-infra/packer-builder-vsphere/pull/82 is release):
```
==> windows-2016-amd64-vsphere: error removing floppy: The operation is not supported on the object.
==> windows-2016-amd64-vsphere: error removing cdroms: The operation is not supported on the object.
```

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ spicy --uri 'spice+unix:///tmp/packer-windows-2016-amd64-libvirt-spice.socket'
**NB** the packer template file defines `qemuargs` (which overrides the default packer qemu arguments), if you modify it, verify if you also need include the default packer qemu arguments (see [builder/qemu/step_run.go](https://github.com/hashicorp/packer/blob/master/builder/qemu/step_run.go) or start packer without `qemuargs` defined to see how it starts qemu).


## vSphere

See [README-vsphere.md](README-vsphere.md).


## WinRM access

You can connect to this machine through WinRM to run a remote command, e.g.:
Expand Down
9 changes: 8 additions & 1 deletion autounattend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DriverPaths>
<PathAndCredentials wcm:action="add" wcm:keyValue="1">
<Path>a:\</Path>
<Path>A:\</Path>
</PathAndCredentials>
<PathAndCredentials wcm:action="add" wcm:keyValue="2">
<Path>E:\</Path>
</PathAndCredentials>
</DriverPaths>
</component>
Expand Down Expand Up @@ -116,6 +119,10 @@
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>3</Order>
<CommandLine>PowerShell -File a:\vmtools.ps1</CommandLine>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>4</Order>
<CommandLine>PowerShell -File a:\winrm.ps1</CommandLine>
</SynchronousCommand>
</FirstLogonCommands>
Expand Down
2 changes: 2 additions & 0 deletions provision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ if ($systemVendor -eq 'QEMU') {
if ($p.ExitCode) {
throw "failed to install with exit code $($p.ExitCode). Check the logs at C:\Program Files\Oracle\VirtualBox Guest Additions\install.log."
}
} elseif ($systemVendor -eq 'VMware, Inc.') {
# do nothing. VMware Tools were already installed by vmtools.ps1 (executed from autounattend.xml).
} else {
throw "Cannot install Guest Additions: Unsupported system ($systemVendor)."
}
Expand Down
19 changes: 19 additions & 0 deletions vmtools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Set-StrictMode -Version Latest
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
trap {
Write-Host
Write-Output "ERROR: $_"
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
Write-Host 'Sleeping for 60m to give you time to look around the virtual machine before self-destruction...'
Start-Sleep -Seconds (60*60)
Exit 1
}

$systemVendor = (Get-WmiObject Win32_ComputerSystemProduct Vendor).Vendor
if ($systemVendor -eq 'VMware, Inc.') {
Write-Output 'Installing VMware Tools...'
# silent install without rebooting.
E:\setup64.exe /s /v '/qn reboot=r' `
| Out-String -Stream
}
104 changes: 104 additions & 0 deletions windows-2016-vsphere.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"variables": {
"vsphere_disk_size": "60",
"vsphere_iso_url": "[Datastore] iso/14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO",
"vsphere_tools_iso_url": "[Datastore] iso/vmware-tools-10.2.5/windows.iso",
"vsphere_host": "vcenter.local",
"vsphere_username": "[email protected]",
"vsphere_password": "password",
"vsphere_esxi_host": "esxi.local",
"vsphere_datacenter": "Datacenter",
"vsphere_cluster": "Cluster",
"vsphere_datastore": "Datastore",
"vsphere_folder": "test",
"vsphere_network": "packer"
},
"builders": [
{
"name": "windows-2016-amd64-vsphere",
"vm_name": "windows-2016-amd64-vsphere",
"type": "vsphere-iso",
"guest_os_type": "windows9Server64Guest",
"disk_size": "{{user `vsphere_disk_size`}}",
"disk_thin_provisioned": true,
"disk_controller_type": "pvscsi",
"vcenter_server": "{{user `vsphere_host`}}",
"username": "{{user `vsphere_username`}}",
"password": "{{user `vsphere_password`}}",
"insecure_connection": "true",
"datacenter": "{{user `vsphere_datacenter`}}",
"cluster": "{{user `vsphere_cluster`}}",
"host": "{{user `vsphere_esxi_host`}}",
"folder": "{{user `vsphere_folder`}}",
"datastore": "{{user `vsphere_datastore`}}",
"network_card": "vmxnet3",
"network": "{{user `vsphere_network`}}",
"convert_to_template": true,
"RAM": 2048,
"CPUs": 4,
"iso_paths": [
"{{user `vsphere_iso_url`}}",
"{{user `vsphere_tools_iso_url`}}"
],
"floppy_files": [
"autounattend.xml",
"vmtools.ps1",
"winrm.ps1"
],
"boot_order": "disk,cdrom",
"communicator": "winrm",
"winrm_username": "vagrant",
"winrm_password": "vagrant",
"winrm_timeout": "4h",
"shutdown_command": "shutdown /s /t 0 /f /d p:4:1 /c \"Packer Shutdown\""
}
],
"provisioners": [
{
"type": "powershell",
"script": "disable-windows-updates.ps1"
},
{
"type": "powershell",
"inline": "Uninstall-WindowsFeature Windows-Defender-Features"
},
{
"type": "powershell",
"inline": "Uninstall-WindowsFeature FS-SMB1"
},
{
"type": "powershell",
"script": "virtualbox-prevent-vboxsrv-resolution-delay.ps1"
},
{
"type": "windows-restart"
},
{
"type": "windows-update",
"filters": [
"exclude:$_.Title -like '*Preview*'",
"include:$_.Title -like '*Cumulative Update for Windows*'",
"include:$_.AutoSelectOnWebSites"
]
},
{
"type": "powershell",
"script": "provision.ps1"
},
{
"type": "powershell",
"script": "provision-openssh.ps1"
},
{
"type": "windows-restart"
},
{
"type": "powershell",
"script": "eject-media.ps1"
},
{
"type": "powershell",
"script": "optimize.ps1"
}
]
}

0 comments on commit d64ca87

Please sign in to comment.