Code Monkey home page Code Monkey logo

packertemplates's Introduction

Windows Packer Templates

Introduction

This repository contains build scripts to golden images using Packer.

Interested in some best practices when using Packer with Windows? Check out my blog post on the topic.

Supported Builders

The supported builds are:

  • VirtualBox
  • Hyper-V

Supported Operating Systems

The build.supported_os.yaml file contains the list of Operating Systems that are supported and their settings.

The supported Operating Systems to build are:

  • Windows2012R2Core
  • Windows2012R2
  • Windows2016StdCore
  • Windows2016Std

Pre-build Images

If you just want to download the pre-build Vagrant images, download them from Vagrant Cloud.

Prepare your system to run Packer

Before you can run the build scripts, you need to prepare your system.

Ubuntu

โœ… Tested on Ubuntu 16.04

Mono is required to run the build script.

# Install Mono
sudo apt-get install mono-complete -y

# Give the script execute permission
chmod +x build.sh

Additionally you will need to install:

  • Packer
  • VirtualBox

Windows

โœ… Tested on Windows 10 Pro

# Set PowerShell Execution Policy
Set-ExecutionPolicy RemoteSigned -Force

# Install Chocolatey
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

# Install Packer
choco install packer -y

# Install Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

# Create an external Hyper-V Switch
# Commands may vary depending on your system.
Get-NetAdapter

# Find the name of the network adapter (make sure its status is also not disconnected)

# Create a new VM Switch using the name of the network adapter
New-VMSwitch -Name "External VM Switch" -AllowManagementOS $true -NetAdapterName "<Your Adapter Name Here>"

Running the Build Script

Depending on your platform, you either need to run:

  • build.ps1 on Windows
  • build.sh on Linux / MacOS.

Building Vagrant Cloud Images

If you are building images for Vagrant Cloud, you need to set the following environment variables:

# Windows

$env:ATLAS_TOKEN = "ABC123XYZ"

$env:ATLAS_USERNAME = "MattHodge" # Username to upload the boxes under

$env:ATLAS_VERSION = "1.0.1" # Version of the box being uploaded
# MacOS / Linux

export ATLAS_TOKEN="ABC123XYZ"

export ATLAS_USERNAME="MattHodge" # Username to upload the boxes under

export ATLAS_VERSION="1.0.1" # Version of the box being uploaded

Building Hyper-V Images

The following commands will build you Hyper-V Images

# Builds Windows 2016 Standard Core and runs the Vagrant post processor (local).
.\build.ps1 -Target "hyperv-local" -os="Windows2016StdCore"

# Builds Windows 2012 R2 Core and runs the Atlas post processor.
.\build.ps1 -Target "hyperv-vagrant-cloud" --os="Win2012R2Core"

Building VirtualBox Images

The following commands will build you VirtualBox Images

# Builds Windows 2016 Standard Core and runs the Vagrant post processor (local).
./build.sh --target "virtualbox-local" -os="Windows2016StdCore"

# Builds Windows 2012 R2 Core and runs the Atlas post processor.
./build.sh --target "virtualbox-vagrant-cloud" -os="Win2012R2Core"

Using the Vagrant Images

If you aren't pushing your boxes to Atlas, you can import the *.box files for use in Vagrant:

vagrant box add .\win2016stdcore-wmf5-nocm-hyperv.box --name Windows2016StdCore

You can also find all the boxes ready to be used with vagrant up over at my VagrantBoxes Repository.

packertemplates's People

Contributors

matthodge avatar solidoceantrust avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

packertemplates's Issues

Your yaml is invalid

System.IO.FileNotFoundException: Could not load file or assembly 'YamlDotNet, Version=4.2.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'YamlDotNet, Version=4.2.1.0, Culture=neutral, PublicKeyToken=null'
  at Submission#0.DeserializeYamlFromFile[T] (Cake.Core.IO.FilePath filename) [0x0000c] in <cb8a275aead04fb8b7e8455004212668>:0 
  at Submission#0.LoadYAMLConfig (System.String yaml_path, System.String os) [0x00016] in <cb8a275aead04fb8b7e8455004212668>:0 
Error: One or more errors occurred.
	Your yaml is invalid.

install_oracle_guest_additions.ps1 file name not found

When I cloned the repo and tried to get the virtualbox guest additions installed, the script (packer) said that it could not find the file E:\cert\oracle-vbox.cer.
I am using Virtual Box version 5.1.143112924.

I fixed the script to add the correct certs by their new names and will be submitting a pull request to that effect.

Thank you Matt for this is AWESOME repo/project.

VRam for virtualbox?

Why do you configure video memory for virtualbox? Does this speed up provisioning?

Error: hyperv-iso: Error shutting down VM: PowerShell error: Hyper-V\Stop-VM : Failed to stop.

I am trying to generate the Hyper-V vhdx file, however getting the below error message, Would you please check and advise.

Environment:- Windows 2016 Datacentre Server, installed with Hyper-V
Packer Version:- tried with 1.3.2-dev, & 1.2.5
ISO: Windows 2012R2

Error: ==> hyperv-iso: Provisioning with Powershell...
==> hyperv-iso: Provisioning with powershell script: scripts/install_windows_updates.ps1
==> hyperv-iso: Disconnecting from vmconnect...
==> hyperv-iso: Error shutting down VM: PowerShell error: Hyper-V\Stop-VM : Failed to stop.
==> hyperv-iso: At C:\Users\Administrator\AppData\Local\Temp\2\ps015687669.ps1:5 char:5
==> hyperv-iso: + Hyper-V\Stop-VM -VM $vm -Force -Confirm:$false
==> hyperv-iso: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> hyperv-iso: + CategoryInfo : NotSpecified: (:) [Stop-VM], VirtualizationException
==> hyperv-iso: + FullyQualifiedErrorId : OperationFailed,Microsoft.HyperV.PowerShell.Commands.StopVM

Windows 2016 Dataceneter Core

Is there a way I can build Windows 2016 Datacenter Core instances. I am guessing I just need to add the extra condition for Datacenter but i am not sure where you are pulling the os_name value from.

Taking PRs?

I forked, and would like to contribute back:

  • output directories as variables - I build to an external drive where I have more space
  • some moving of things around so attributes are all ordered the same way and things like that, to make edits easier to place
  • a different way of doing windows updates, because the current one relies on a binary in a dropbox that now 404s

What do you think?

Also - I like the build chain of templates - is there a way to get cake to realise that it doesn't need to rebuild a dependency, but instead build incrementally? I'm unfamiliar.

Ability to Selectively apply updates

Right now you are not to be able to build an identical image to what was created at any point in the past. For example. If on January first Microsoft had released patch1, patch2 and patch3 and you build a Windows 2016 image, which applies those updates, and then on February first you try to rebuild that image you will end up with an image that has all of the updates that were originally applied but all of the subsequent updates as well.

It would be great to be able to easily support this so we can build repeatable images at any point in time.

cake dependencies need updating - build.ps1 doesn't run

First of all, thanks for all this great work - your packer templates are the cleanest I've seen!

I get the below error when running build.ps1. I'm running Windows 10 Pro.

PS C:\Users\tblack\src\PackerTemplates> .\build.ps1
Preparing to run build script...
Running build script...
Analyzing build script...
Processing build script...
Installing addins...
Error: The assembly 'Cake.Yaml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'
is referencing an older version of Cake.Core (0.22.0).
This assembly need to reference at least Cake.Core version 0.26.0.
Another option is to downgrade Cake to an earlier version.
It's not recommended, but you can explicitly opt-out of assembly verification
by configuring the Skip Verification setting to true
(i.e. command line parameter "--settings_skipverification=true",
environment variable "CAKE_SETTINGS_SKIPVERIFICATION=true",
read more about configuration at https://cakebuild.net/docs/fundamentals/configuration)

I tried changing the version from 22 to 26 in tools/Addins/Cake.Yaml.2.0.0/cake.yaml.nuspec, but that didn't help. (This is my first time using cake. I'm clueless)

I am able to get past the error with the suggested build.ps1 --settings_skipverification=true, but just wanted to make a note of this on your repo. Thanks again for all this good work!

Windows Updates insecure

Hi, thanks for this project. I noticed there is an unverified windows update exe being used

https://www.dropbox.com/s/bk1dodl4fb7znj3/WUInstallAMD64.exe?dl=1

Is there any reason for this?

Add exit code 11 to valid_exit_codes in windows update builder

I've modified your answer xml file to work with my Windows10 Pro iso, and have been able to complete the first builder phase "virtualbox-01-windows-base", but the second phase "virtualbox-02-win_updates-wmf5" fails because WUInstallAMD64.exe fails with various errors*, causing powershell to exit with 11 meaning "at least one error occurred, reboot required".

I noticed you run scripts/install_windows_updates.ps1 several times in a loop, with windows restarts each time. Any reason why you shouldn't add exit code 11 to "valid_exit_codes" in the win_updates builder, so this builder will make a best effort at applying updates? I have done this in my fork of your (wonderful!**) repo. What I have found is that any of the various windows update errors that occur are all eliminated by the 2nd or 3rd reboot/WUInstall cycle.

  • WUInstall errors I've seen so far are:
    1. "0x80240017 - WU_E_NOT_APPLICABLE - Operation was not performed because there are no applicable updates.
    2. Download failed

** I applaud your use of chaining phases to facilitate resumption of failed packer builds. :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.