• This repository has been archived on 04/Oct/2019
  • Stars
    star
    1,636
  • Rank 28,579 (Top 0.6 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Windows Packer Templates

Windows Templates for Packer

Introduction

This repository contains Windows templates that can be used to create boxes for Vagrant using Packer (Website) (Github).

This repo began by borrowing bits from the VeeWee Windows templates (https://github.com/jedi4ever/veewee/tree/master/templates). Modifications were made to work with Packer and the VMware Fusion / VirtualBox providers for Packer and Vagrant.

Packer Version

Packer 0.5.1 or greater is required.

Windows Versions

The following Windows versions are known to work (built with VMware Fusion 6.0.4 and VirtualBox 4.3.12):

  • Windows 2012 R2
  • Windows 2012 R2 Core
  • Windows 2012
  • Windows 2008 R2
  • Windows 2008 R2 Core
  • Windows 10
  • Windows 8.1
  • Windows 7

Windows Editions

All Windows Server versions are defaulted to the Server Standard edition. You can modify this by editing the Autounattend.xml file, changing the ImageInstall>OSImage>InstallFrom>MetaData>Value element (e.g. to Windows Server 2012 R2 SERVERDATACENTER).

Product Keys

The Autounattend.xml files are configured to work correctly with trial ISOs (which will be downloaded and cached for you the first time you perform a packer build). If you would like to use retail or volume license ISOs, you need to update the UserData>ProductKey element as follows:

  • Uncomment the <Key>...</Key> element
  • Insert your product key into the Key element

If you are going to configure your VM as a KMS client, you can use the product keys at http://technet.microsoft.com/en-us/library/jj612867.aspx. These are the default values used in the Key element.

Windows Updates

The scripts in this repo will install all Windows updates – by default – during Windows Setup. This is a very time consuming process, depending on the age of the OS and the quantity of updates released since the last service pack. You might want to do yourself a favor during development and disable this functionality, by commenting out the WITH WINDOWS UPDATES section and uncommenting the WITHOUT WINDOWS UPDATES section in Autounattend.xml:

<!-- WITHOUT WINDOWS UPDATES -->
<SynchronousCommand wcm:action="add">
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\openssh.ps1 -AutoStart</CommandLine>
    <Description>Install OpenSSH</Description>
    <Order>99</Order>
    <RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<!-- END WITHOUT WINDOWS UPDATES -->
<!-- WITH WINDOWS UPDATES -->
<!--
<SynchronousCommand wcm:action="add">
    <CommandLine>cmd.exe /c a:\microsoft-updates.bat</CommandLine>
    <Order>98</Order>
    <Description>Enable Microsoft Updates</Description>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\openssh.ps1</CommandLine>
    <Description>Install OpenSSH</Description>
    <Order>99</Order>
    <RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\win-updates.ps1</CommandLine>
    <Description>Install Windows Updates</Description>
    <Order>100</Order>
    <RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
-->
<!-- END WITH WINDOWS UPDATES -->

Doing so will give you hours back in your day, which is a good thing.

OpenSSH / WinRM

Currently, Packer has a single communicator that uses SSH. This means we need an SSH server installed on Windows - which is not optimal as we could use WinRM to communicate with the Windows VM. In the short term, everything works well with SSH; in the medium term, work is underway on a WinRM communicator for Packer.

If you have serious objections to OpenSSH being installed, you can always add another stage to your build pipeline:

  • Build a base box using Packer
  • Create a Vagrantfile, use the base box from Packer, connect to the VM via WinRM (using the vagrant-windows plugin) and disable the 'sshd' service or uninstall OpenSSH completely
  • Perform a Vagrant run and output a .box file

It's worth mentioning that many Chef cookbooks will not work properly through Cygwin's SSH environment on Windows. Specifically, packages that need access to environment-specific configurations such as the PATH variable, will fail. This includes packages that use the Windows installer, msiexec.exe.

It's currently recommended that you add a second step to your pipeline and use Vagrant to install your packages through Chef.

Using .box Files With Vagrant

The generated box files include a Vagrantfile template that is suitable for use with Vagrant 1.6.2+, which includes native support for Windows and uses WinRM to communicate with the box.

Getting Started

Trial versions of Windows 2008 R2 / 2012 / 2012 R2 / 2016 are used by default. These images can be used for 180 days without activation.

Alternatively – if you have access to MSDN or TechNet – you can download retail or volume license ISO images and place them in the iso directory. If you do, you should supply appropriate values for iso_url (e.g. ./iso/<path to your iso>.iso) and iso_checksum (e.g. <the md5 of your iso>) to the Packer command. For example, to use the Windows 2008 R2 (With SP1) retail ISO:

  1. Download the Windows Server 2008 R2 with Service Pack 1 (x64) - DVD (English) ISO (en_windows_server_2008_r2_with_sp1_x64_dvd_617601.iso)

  2. Verify that en_windows_server_2008_r2_with_sp1_x64_dvd_617601.iso has an MD5 hash of 8dcde01d0da526100869e2457aafb7ca (Microsoft lists a SHA1 hash of d3fd7bf85ee1d5bdd72de5b2c69a7b470733cd0a, which is equivalent)

  3. Clone this repo to a local directory

  4. Move en_windows_server_2008_r2_with_sp1_x64_dvd_617601.iso to the iso directory

  5. Run:

    packer build \
        -var iso_url=./iso/en_windows_server_2008_r2_with_sp1_x64_dvd_617601.iso \
        -var iso_checksum=8dcde01d0da526100869e2457aafb7ca windows_2008_r2.json
    

Variables

The Packer templates support the following variables:

Name Description
iso_url Path or URL to ISO file
iso_checksum Checksum (see also iso_checksum_type) of the ISO file
iso_checksum_type The checksum algorithm to use (out of those supported by Packer)
autounattend Path to the Autounattend.xml file

Contributing

Pull requests welcomed.

Acknowledgements

CloudBees is providing a hosted Jenkins master through their CloudBees FOSS program. We also use their On-Premise Executor feature to connect a physical Mac Mini Server running VMware Fusion.

Powered By CloudBeesBuilt On DEV@Cloud

More Repositories

1

go-plus

An Enhanced Go Experience For The Atom Editor
JavaScript
1,510
star
2

slack-dump

Export History For Private Groups From Slack
Go
62
star
3

inductor

Inductor Generates Packer (http://packer.io) Templates Using Inductor Templates
Go
43
star
4

autocomplete-go

An Atom autocomplete-plus provider for the Go language that uses gocode to provide suggestions.
JavaScript
29
star
5

gometalinter-linter

A Linter For Atom That Runs gometalinter
JavaScript
18
star
6

forecast

A Forecast (forecastapp.com) API Client For Go
Go
13
star
7

navigator-go

Atom Package For Navigating To The Symbol Under The Cursor Using godef
JavaScript
7
star
8

go-config

Atom Package For Detecting And Configuring Installed Go Runtime(s)
JavaScript
7
star
9

standardlog

A Go (golang) Interface For The Standard Library's log.Logger
Go
6
star
10

builder-go

Builds Go Source Code In Atom
JavaScript
6
star
11

go-get

An Atom Package For Managing Go Libraries And Executables
JavaScript
5
star
12

gofmt

Atom Package For Running gofmt / goimports / goreturns
JavaScript
5
star
13

graphql

A Go GraphQL Client
Go
4
star
14

rainbow-reporter

A spec (https://github.com/sclevine/spec) reporter that is colorized 🌈!
Go
4
star
15

tester-go

Atom Package To Run Your Go Tests And Display Test Coverage
JavaScript
4
star
16

openair

A go generator for the OpenAir XML API
Go
3
star
17

buildpack

A Collection Of Go (golang) Interfaces Representing The Contracts Required For A Buildpack
Go
2
star
18

passwordcredentials

A golang.org/x/oauth2 client for the passwordcredentials OAuth 2.0 flow.
Go
2
star
19

streamlog

A Go (golang) Logger For Standard Output Streams
Go
2
star
20

gabby

Tame the calendar beast!
Go
1
star
21

sqlce

Microsoft SQL Server (Compact Edition) Cookbook
Ruby
1
star
22

presentations

Joe's Presentations
1
star
23

joefitzgerald.github.io

joefitzgerald.io Content
1
star
24

vimfiles

.vim directory
Vim Script
1
star
25

sfdc

Go client for the Salesforce / SFDC REST API
Go
1
star