Coder Social home page Coder Social logo

packer-hyperv's Introduction

packer-hyperv

Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration. For an introduction to Packer, check out documentation at http://www.packer.io/intro/index.html.

This is a Hyperv plugin for Packer.io to enable windows users to build custom images given an ISO.

ISO's can be downloaded off technet or MSDN (if you have a subscription for the latter). http://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2012-r2

The hyper-v plugin enables you to build a Windows Server Vagrant box for the hyper-v provider only.

The bin folder has an example JSON to help specify the new hyperv configuration. "type": "hyperv-iso", "guest_os_type":"WindowsServer2012R2Datacenter", "product_key" : "{{user product_key}}", "iso_url":"d:/Hyper-V/ISO/Windows_Server_2012_R2-EN-US-x64.ISO",

Additionally, as indicated above, if you obtain a windows license, you can specify the product key within your .json configuration and the plugin will register your copy of windows.

Note: The plugin has to be run on a Windows workstation 8.1 or higher and must have hyper-v enabled.

packer-hyperv's People

Contributors

paulmey avatar snesha avatar vladimir-shcherbakov 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

Watchers

 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

packer-hyperv's Issues

build breaks ... missing definition of *package.ConfigTemplate

The build mostly works after I changed in the imports for "code.google.com/p/go-uuid/uuid" to "github.com/pborman/uuid" (because code.google.com is going away).

But then I get this error from 'go get' and 'go build' when trying to build 'packer-builder-hyperv-iso'.

# github.com/MSOpenTech/packer-hyperv/packer/builder/hyperv/common
..\..\builder\hyperv\common\output_config.go:18: undefined: packer.ConfigTemplate

I think that type, ConfigTemplate, no longer exists in Packer ... It looks like it got removed in 0.8.0 hashicorp/packer@1d3a4d6
... but I'm not sure what to do about it.

(I'm trying to get this building so I can then extend it to add Gen 2 support and "standard" edition support for 2012R2 servers.)

Vagrant up throws exception for the box file created through Packer

Repo Steps:

  1. Execute packer build for following template
    {
    "variables":
    {
    "installers_destination_folder": "C:/PackerDistr",
    "product_key": "",
    "example_dir": "C:/packer-example/V3/example"
    },
"builders": 
[
    {
        "type": "hyperv-iso",
        "guest_os_type":"WindowsServer2012R2Datacenter",
        "product_key" : "{{user `product_key`}}",
        "iso_url":"D:/Windows2012R2/Windows Server 2012 R2/Windows_Server_2012_R2-Datacenter_Edition–EN-US-X64.ISO",
        "disk_size_gb":40,
        "ram_size_mb":512,
        "wait_time_minutes": "10"
    }
],

"provisioners": 
[
    {
        "type": "powershell",
        "distr_src_path": "{{user `example_dir`}}/srcFolder",
        "distr_dst_dir_path": "{{user `installers_destination_folder`}}",
        "inline": 
        [
            "Write-Host 'Starting inline script...'", 
            "Write-Host 'Installing notepad...'", 
            "Start-Process '{{user `installers_destination_folder`}}/npp.6.6.3.Installer.exe' -NoNewWindow -Wait -Argument '/S'",
            "Write-Host 'Installing Mozilla Firefox...'",
            "Start-Process '{{user `installers_destination_folder`}}/Firefox Setup 30.0.exe' -NoNewWindow -Wait -Argument '/S'",
            "Write-Host 'Add Role...'", 
            "Start-Process Add-WindowsFeature Application-Server,Hyper-V,WAS '/S'",
            "Write-Host 'Inline script finished!'" 
        ],
        "script_path": "{{user `example_dir`}}/probe.ps1"
    }
],
"post-processors": 
[
    {
        "type": "vagrant",
        "compression_level": 1
    }
]

}

Expected Result:

  1. Should create a box file
  2. Using this box file in Vagrantfile and doing a vagrant up command should create a new vm in hyper-v.

Actual Result:

  1. Box file creation is successful.
  2. Using the same box file in vagrant to manage vm with Vagrant throws exception.
    image

Possible license change for inclusion of builder into Packer

hashicorp/packer#2576

We have almost got Hyper-V builder included into Packer. It is based off this builder.

But there are some stumbling blocks around copyright. I think Hashicorp wants a slight change to license header so that it can be included in Packer. Is there someone who we can talk to about the issue.

I know they have also included other Microsoft copyright files for the Azure builder (MIT license). So I dont think its impossible.

Hoping to come up with a solution that everyone is happy with.

Current Packer license:
https://github.com/mitchellh/packer/blob/master/LICENSE

Post-processors "only" parameter throws exception

  1. Include only: ["hyperv"] in post-proccessors section.
  2. build the packer template

Expected:

  1. Should build the template and create artifacts for hyperv as "only" parameter runs only on specified provider and in this case its hyperv.
  2. Else should display a message prior to execution telling "parameter only is not supported"

Actual:
Execution is successful till post-processors and then throws the exception.
image

Unable to validate my template

I'm having issue validating my temple. Getting error:

fork/exec C:\HashiCorp\packer\packer-builder-hyperv-iso.exe: This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

Below is my OS version:

OS Name Microsoft Windows 8.1 Enterprise
Version 6.3.9600 Build 9600

The ISO i'm using for my builder: SW_DVD5_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_Core_MLF_X19-05182.ISO (which is a windows 2012 server bundled with standard and DataCenter)

Issue in mapping virtual switch to the vm

  1. Create an Internal Switch in Hyper-V Manager named”Test_Switch”.
  2. Execute Packer build packer-hyperv.json with parameter "switch_name":"Test_Switch"

Expected:
Should display message "Test_Switch already exists hence using the same switch" and execution should proceed.

Actual:
Displays a message “Creating internal Switch” and maps to the existing switch.
image

It will be good if we have a message here on existing switch.

Issue in mapping virtual switch

  1. Create an external Switch “Virtual_Switch” in Hyper-V Manager
  2. Create an internal Switch “Virtual_Switch” in Hyper-V Manager.
  3. Mention “switch_name”:”Virtual_Switch” in json
  4. Build the template.

Expected:

  1. Should display a message differnent type of "Virtual_Switch" exist and give an option to user in selecting the switch. Based on selection execution should proceed and create the artifacts .

Actual:

  1. Execution begins.
  2. Displays "Creating Internal Switch"
  3. Throws exception and deleted both the switches named "Virtual_Switch"
    image

Max value for wait_time_minutes parameter

  1. Mention "wait_time_minutes": "20000" (Any higher value)
  2. execute packer build packer_hyperv.json

Expected:

  1. Should display an error message max wait time should be x minutes.

Actual:
Waits till the specified time
image

Packer build fails with reference of external .ps1 file

Repo Steps:

  1. Create template.json with mandatory builder parameters.
  2. Include provisioners as shown below
    image
  3. execute packer validate template.json. This is successful
  4. execute packer build template.json

Expected Result:

  1. Build should get successful and the build artifacts should get created.

Actual Result:

  1. Executin packer build template.json mounts a new vm in hyper-v, installs the OS, Enables the guest services, fetches the ip, executes inline provisioning commands.
  2. Prompts for a message to execute external .ps1 “Do you want to run ‘C:...\probe.ps1’? With option [Do not run]D, [Run Once]R, [Suspend]S [?]Help (default is “D”): “
  3. For any input D/R/S, the execution stops and doesn’t show any message.

image

Source for modified version of packer-post-processor-vagrant.exe ?

The Readme.md file in the bin folder indicates:

The file packer-post-processor-vagrant.exe is an extention of the original file with the same name to create a vagrant box from a Hyper-V atrifact.

Have you included the source code for this extension somewhere? It does not look like it is included in in hyperv.go in MSOpenTech's fork of packer.

I have created an issue on Packer's project. It would be great if we could submit a pull request to get the changes included in the core packer product.

Max value for Disk and Ram Size

  1. Provide any higher value for Disk and Ram Size.
  2. build the template.

Expected:

  1. Should display max RAM supported is 2802 MB and max Disk size supported is 64TB which are the max values supported by Hyper-V.
    This has to be checked while validating the template.

Actual:
Execution begins and throws exception in middle.
image

packer hyperv-iso refuses to see that I have hyper-v ps commands available

It always complains that PS Hyper-V module is not loaded, but it is.

C:\0source\vagrant [master ↑1 +2 ~1 -0 !]> packer build packer.json
hyperv-iso output will be in this color.

Build 'hyperv-iso' errored: Failed creating Hyper-V driver: PS Hyper-V module is not loaded. Make sure Hyper-V feature is on.

==> Some builds didn't complete successfully and had errors:
--> hyperv-iso: Failed creating Hyper-V driver: PS Hyper-V module is not loaded. Make sure Hyper-V feature is on.

==> Builds finished but no artifacts were created.
C:\0source\vagrant [master ↑1 +2 ~1 -0 !]> get-command get-vm

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-VM                                             2.0.0.0    Hyper-V

Update to new API version?

When I try to use this with Packer v0.7.1 I'm getting:

Failed to create build 'hyperv-iso':
Incompatible API version with plugin. Plugin version: 3, Ours: 4

packer build fails to create box file due to unhandled exception occured due to provision error

Packer build fails to create box file due to an exception occured while trying to provision ps1 file. In this case, ps1 was blocked due to file copy as shown in the screenshot and due to this an exception occured.

image

Unblocking this file would fix the problem. But irrespective of this provisioning step failures, plugin should still create box file but in this case it did not create box file and command execution stopped with below exception skipping the box file preparation step.

image

Exception when compression_level value is more than 9

  1. Mention "compression_level" value as 10 in json file.
    "compression_level" :10
  2. execute packer validate packer_hyperv.json. This is successful.

Expected:

  1. Should display a error message "compression_level value should be between 0 and 9" while validating the json template.

Actual:

  1. Template validation is successful.
  2. packer build packer_hyperv.json is executed successfully till post-processors and finally throws exception.
    image

How to provide answer file?

Is there a way to reference an answer file in the json so that it will be mounted/used at install time? If not, that'd be nice.

[Feature Request] Bootcommand to eject the packer ISO

In the Hyper V Generation 2 builder, if the OS installer doesn't eject the DVD when done, the builder will keep rebooting from the ISO.

This behavior is quite different from every other packer builder and Generation 1 where when the VM is rebooted, the ISO is automatically removed/ejected and the OS is booted off the disk as expected.

A lot of OS installers do not support this, especially older and obscure platforms. A simple provision to eject the DVD from a boot command or provisioner would be perfect for this.

As is, it does seem to be able to quite easily eject a drive from powershell : https://goodworkaround.com/2012/11/08/eject-dvd-iso-from-hyper-v-2012-using-powershell/

Weird Restrictions

I have a few questions about the limitations of this, particularly since it's an MSOpenTech project, but feels like it has so far only reached tech demo stage.

  1. Will you be continuing development?
  2. Would you accept pull requests?
  3. Is there a plan to support other SKUs?
  4. Why is it limiting me to max about 6GB of RAM (this seems like a rounding error, "6538" should have been "65536" maybe? 🎱 I was going to create a VM for SharePoint, and I needed more like 16GB (or even 32GB).

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.