mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-21 17:01:06 -05:00
Merge remote-tracking branch 'upstream/master' into prestine
This commit is contained in:
commit
42610a35d5
17 changed files with 610 additions and 510 deletions
|
|
@ -24,7 +24,7 @@ from a single source configuration.
|
|||
Packer is lightweight, runs on every major operating system, and is highly
|
||||
performant, creating machine images for multiple platforms in parallel. Packer
|
||||
comes out of the box with support for many platforms, the full list of which can
|
||||
be found at https://www.packer.io/docs/builders/index.html.
|
||||
be found at https://www.packer.io/docs/builders/index.html.
|
||||
|
||||
Support for other platforms can be added via plugins.
|
||||
|
||||
|
|
@ -32,10 +32,6 @@ The images that Packer creates can easily be turned into
|
|||
[Vagrant](http://www.vagrantup.com) boxes.
|
||||
|
||||
## Quick Start
|
||||
Download and install packages and dependencies
|
||||
```
|
||||
go get github.com/hashicorp/packer
|
||||
```
|
||||
|
||||
**Note:** There is a great
|
||||
[introduction and getting started guide](https://www.packer.io/intro)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
&stepCheckAlicloudSourceImage{
|
||||
SourceECSImageId: b.config.AlicloudSourceImage,
|
||||
},
|
||||
&StepConfigAlicloudKeyPair{
|
||||
&stepConfigAlicloudKeyPair{
|
||||
Debug: b.config.PackerDebug,
|
||||
KeyPairName: b.config.SSHKeyPairName,
|
||||
PrivateKeyFile: b.config.Comm.SSHPrivateKey,
|
||||
|
|
@ -136,7 +136,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
ZoneId: b.config.ZoneId,
|
||||
})
|
||||
if b.chooseNetworkType() == VpcNet {
|
||||
steps = append(steps, &setpConfigAlicloudEIP{
|
||||
steps = append(steps, &stepConfigAlicloudEIP{
|
||||
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
|
||||
RegionId: b.config.AlicloudRegion,
|
||||
InternetChargeType: b.config.InternetChargeType,
|
||||
|
|
@ -147,7 +147,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
})
|
||||
}
|
||||
steps = append(steps,
|
||||
&stepAttachKeyPar{},
|
||||
&stepAttachKeyPair{},
|
||||
&stepRunAlicloudInstance{},
|
||||
&stepMountAlicloudDisk{},
|
||||
&communicator.StepConnect{
|
||||
|
|
@ -170,12 +170,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
AlicloudImageName: b.config.AlicloudImageName,
|
||||
},
|
||||
&stepCreateAlicloudImage{},
|
||||
&setpRegionCopyAlicloudImage{
|
||||
&stepRegionCopyAlicloudImage{
|
||||
AlicloudImageDestinationRegions: b.config.AlicloudImageDestinationRegions,
|
||||
AlicloudImageDestinationNames: b.config.AlicloudImageDestinationNames,
|
||||
RegionId: b.config.AlicloudRegion,
|
||||
},
|
||||
&setpShareAlicloudImage{
|
||||
&stepShareAlicloudImage{
|
||||
AlicloudImageShareAccounts: b.config.AlicloudImageShareAccounts,
|
||||
AlicloudImageUNShareAccounts: b.config.AlicloudImageUNShareAccounts,
|
||||
RegionId: b.config.AlicloudRegion,
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type stepAttachKeyPar struct {
|
||||
type stepAttachKeyPair struct {
|
||||
}
|
||||
|
||||
func (s *stepAttachKeyPar) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
func (s *stepAttachKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
keyPairName := state.Get("keyPair").(string)
|
||||
if keyPairName == "" {
|
||||
return multistep.ActionContinue
|
||||
|
|
@ -50,7 +50,7 @@ func (s *stepAttachKeyPar) Run(_ context.Context, state multistep.StateBag) mult
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepAttachKeyPar) Cleanup(state multistep.StateBag) {
|
||||
func (s *stepAttachKeyPair) Cleanup(state multistep.StateBag) {
|
||||
keyPairName := state.Get("keyPair").(string)
|
||||
if keyPairName == "" {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type setpConfigAlicloudEIP struct {
|
||||
type stepConfigAlicloudEIP struct {
|
||||
AssociatePublicIpAddress bool
|
||||
RegionId string
|
||||
InternetChargeType string
|
||||
allocatedId string
|
||||
}
|
||||
|
||||
func (s *setpConfigAlicloudEIP) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
func (s *stepConfigAlicloudEIP) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
client := state.Get("client").(*ecs.Client)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
instance := state.Get("instance").(*ecs.InstanceAttributesType)
|
||||
|
|
@ -55,7 +55,7 @@ func (s *setpConfigAlicloudEIP) Run(_ context.Context, state multistep.StateBag)
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *setpConfigAlicloudEIP) Cleanup(state multistep.StateBag) {
|
||||
func (s *stepConfigAlicloudEIP) Cleanup(state multistep.StateBag) {
|
||||
if len(s.allocatedId) == 0 {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type StepConfigAlicloudKeyPair struct {
|
||||
type stepConfigAlicloudKeyPair struct {
|
||||
Debug bool
|
||||
SSHAgentAuth bool
|
||||
DebugKeyPath string
|
||||
|
|
@ -25,7 +25,7 @@ type StepConfigAlicloudKeyPair struct {
|
|||
keyName string
|
||||
}
|
||||
|
||||
func (s *StepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
func (s *stepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
if s.PrivateKeyFile != "" {
|
||||
|
|
@ -108,7 +108,7 @@ func (s *StepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.State
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepConfigAlicloudKeyPair) Cleanup(state multistep.StateBag) {
|
||||
func (s *stepConfigAlicloudKeyPair) Cleanup(state multistep.StateBag) {
|
||||
// If no key name is set, then we never created it, so just return
|
||||
// If we used an SSH private key file, do not go about deleting
|
||||
// keypairs
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type setpRegionCopyAlicloudImage struct {
|
||||
type stepRegionCopyAlicloudImage struct {
|
||||
AlicloudImageDestinationRegions []string
|
||||
AlicloudImageDestinationNames []string
|
||||
RegionId string
|
||||
}
|
||||
|
||||
func (s *setpRegionCopyAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
func (s *stepRegionCopyAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
if len(s.AlicloudImageDestinationRegions) == 0 {
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ func (s *setpRegionCopyAlicloudImage) Run(_ context.Context, state multistep.Sta
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *setpRegionCopyAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||
func (s *stepRegionCopyAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
if cancelled || halted {
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type setpShareAlicloudImage struct {
|
||||
type stepShareAlicloudImage struct {
|
||||
AlicloudImageShareAccounts []string
|
||||
AlicloudImageUNShareAccounts []string
|
||||
RegionId string
|
||||
}
|
||||
|
||||
func (s *setpShareAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
func (s *stepShareAlicloudImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
client := state.Get("client").(*ecs.Client)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
alicloudImages := state.Get("alicloudimages").(map[string]string)
|
||||
|
|
@ -37,7 +37,7 @@ func (s *setpShareAlicloudImage) Run(_ context.Context, state multistep.StateBag
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *setpShareAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||
func (s *stepShareAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
if cancelled || halted {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ func listEC2Regions() []string {
|
|||
return []string{
|
||||
"ap-northeast-1",
|
||||
"ap-northeast-2",
|
||||
"ap-northeast-3",
|
||||
"ap-south-1",
|
||||
"ap-southeast-1",
|
||||
"ap-southeast-2",
|
||||
|
|
|
|||
|
|
@ -278,20 +278,24 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
|
|||
}
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err == nil && (resp.StatusCode >= 200 && resp.StatusCode < 300) {
|
||||
// If the HEAD request succeeded, then attempt to set the range
|
||||
// query if we can.
|
||||
if resp.Header.Get("Accept-Ranges") == "bytes" {
|
||||
if fi, err := dst.Stat(); err == nil {
|
||||
if _, err = dst.Seek(0, os.SEEK_END); err == nil {
|
||||
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", fi.Size()))
|
||||
if err != nil {
|
||||
log.Printf("[DEBUG] (download) Error making HTTP HEAD request: %s", err.Error())
|
||||
} else {
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
// If the HEAD request succeeded, then attempt to set the range
|
||||
// query if we can.
|
||||
if resp.Header.Get("Accept-Ranges") == "bytes" {
|
||||
if fi, err := dst.Stat(); err == nil {
|
||||
if _, err = dst.Seek(0, os.SEEK_END); err == nil {
|
||||
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", fi.Size()))
|
||||
|
||||
d.current = uint64(fi.Size())
|
||||
d.current = uint64(fi.Size())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Printf("[DEBUG] (download) Unexpected HTTP response during HEAD request: %s", resp.Status)
|
||||
}
|
||||
} else if err != nil || (resp.StatusCode >= 400 && resp.StatusCode < 600) {
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
}
|
||||
|
||||
// Set the request to GET now, and redo the query to download
|
||||
|
|
@ -300,8 +304,10 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
|
|||
resp, err = httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if err != nil || (resp.StatusCode >= 400 && resp.StatusCode < 600) {
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
} else {
|
||||
if resp.StatusCode >= 400 && resp.StatusCode < 600 {
|
||||
return fmt.Errorf("Error making HTTP GET request: %s", resp.Status)
|
||||
}
|
||||
}
|
||||
|
||||
d.total = d.current + uint64(resp.ContentLength)
|
||||
|
|
|
|||
|
|
@ -1009,7 +1009,11 @@ param([string]$mac, [int]$addressIndex)
|
|||
try {
|
||||
$vm = Hyper-V\Get-VM | ?{$_.NetworkAdapters.MacAddress -eq $mac}
|
||||
if ($vm.NetworkAdapters.IpAddresses) {
|
||||
$ip = $vm.NetworkAdapters.IpAddresses[$addressIndex]
|
||||
$ipAddresses = $vm.NetworkAdapters.IPAddresses
|
||||
if ($ipAddresses -isnot [array]) {
|
||||
$ipAddresses = @($ipAddresses)
|
||||
}
|
||||
$ip = $ipAddresses[$addressIndex]
|
||||
} else {
|
||||
$vm_info = Get-CimInstance -ClassName Msvm_ComputerSystem -Namespace root\virtualization\v2 -Filter "ElementName='$($vm.Name)'"
|
||||
$ip_details = (Get-CimAssociatedInstance -InputObject $vm_info -ResultClassName Msvm_KvpExchangeComponent).GuestIntrinsicExchangeItems | %{ [xml]$_ } | ?{ $_.SelectSingleNode("/INSTANCE/PROPERTY[@NAME='Name']/VALUE[child::text()='NetworkAddressIPv4']") }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This package implements a provisioner for Packer that executes
|
||||
// powershell scripts within the remote machine.
|
||||
// This package implements a provisioner for Packer that executes powershell
|
||||
// scripts within the remote machine.
|
||||
package powershell
|
||||
|
||||
import (
|
||||
|
|
@ -39,8 +39,8 @@ type Config struct {
|
|||
// converted from Windows to Unix-style.
|
||||
Binary bool
|
||||
|
||||
// An inline script to execute. Multiple strings are all executed
|
||||
// in the context of a single shell.
|
||||
// An inline script to execute. Multiple strings are all executed in the
|
||||
// context of a single shell.
|
||||
Inline []string
|
||||
|
||||
// The local path of the powershell script to upload and execute.
|
||||
|
|
@ -49,32 +49,33 @@ type Config struct {
|
|||
// An array of multiple scripts to run.
|
||||
Scripts []string
|
||||
|
||||
// An array of environment variables that will be injected before
|
||||
// your command(s) are executed.
|
||||
// An array of environment variables that will be injected before your
|
||||
// command(s) are executed.
|
||||
Vars []string `mapstructure:"environment_vars"`
|
||||
|
||||
// The remote path where the local powershell script will be uploaded to.
|
||||
// This should be set to a writable file that is in a pre-existing directory.
|
||||
// This should be set to a writable file that is in a pre-existing
|
||||
// directory.
|
||||
RemotePath string `mapstructure:"remote_path"`
|
||||
|
||||
// The remote path where the file containing the environment variables
|
||||
// will be uploaded to. This should be set to a writable file that is
|
||||
// in a pre-existing directory.
|
||||
// will be uploaded to. This should be set to a writable file that is in a
|
||||
// pre-existing directory.
|
||||
RemoteEnvVarPath string `mapstructure:"remote_env_var_path"`
|
||||
|
||||
// The command used to execute the script. The '{{ .Path }}' variable
|
||||
// should be used to specify where the script goes, {{ .Vars }}
|
||||
// can be used to inject the environment_vars into the environment.
|
||||
// should be used to specify where the script goes, {{ .Vars }} can be
|
||||
// used to inject the environment_vars into the environment.
|
||||
ExecuteCommand string `mapstructure:"execute_command"`
|
||||
|
||||
// The command used to execute the elevated script. The '{{ .Path }}' variable
|
||||
// should be used to specify where the script goes, {{ .Vars }}
|
||||
// The command used to execute the elevated script. The '{{ .Path }}'
|
||||
// variable should be used to specify where the script goes, {{ .Vars }}
|
||||
// can be used to inject the environment_vars into the environment.
|
||||
ElevatedExecuteCommand string `mapstructure:"elevated_execute_command"`
|
||||
|
||||
// The timeout for retrying to start the process. Until this timeout
|
||||
// is reached, if the provisioner can't start a process, it retries.
|
||||
// This can be set high to allow for reboots.
|
||||
// The timeout for retrying to start the process. Until this timeout is
|
||||
// reached, if the provisioner can't start a process, it retries. This
|
||||
// can be set high to allow for reboots.
|
||||
StartRetryTimeout time.Duration `mapstructure:"start_retry_timeout"`
|
||||
|
||||
// This is used in the template generation to format environment variables
|
||||
|
|
@ -85,15 +86,16 @@ type Config struct {
|
|||
// inside the `ElevatedExecuteCommand` template.
|
||||
ElevatedEnvVarFormat string `mapstructure:"elevated_env_var_format"`
|
||||
|
||||
// Instructs the communicator to run the remote script as a
|
||||
// Windows scheduled task, effectively elevating the remote
|
||||
// user by impersonating a logged-in user
|
||||
// Instructs the communicator to run the remote script as a Windows
|
||||
// scheduled task, effectively elevating the remote user by impersonating
|
||||
// a logged-in user
|
||||
ElevatedUser string `mapstructure:"elevated_user"`
|
||||
ElevatedPassword string `mapstructure:"elevated_password"`
|
||||
|
||||
// Valid Exit Codes - 0 is not always the only valid error code!
|
||||
// See http://www.symantec.com/connect/articles/windows-system-error-codes-exit-codes-description for examples
|
||||
// such as 3010 - "The requested operation is successful. Changes will not be effective until the system is rebooted."
|
||||
// Valid Exit Codes - 0 is not always the only valid error code! See
|
||||
// http://www.symantec.com/connect/articles/windows-system-error-codes-exit-codes-description
|
||||
// for examples such as 3010 - "The requested operation is successful.
|
||||
// Changes will not be effective until the system is rebooted."
|
||||
ValidExitCodes []int `mapstructure:"valid_exit_codes"`
|
||||
|
||||
ctx interpolate.Context
|
||||
|
|
@ -115,7 +117,8 @@ type EnvVarsTemplate struct {
|
|||
}
|
||||
|
||||
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||
//Create passthrough for winrm password so we can fill it in once we know it
|
||||
// Create passthrough for winrm password so we can fill it in once we know
|
||||
// it
|
||||
p.config.ctx.Data = &EnvVarsTemplate{
|
||||
WinRMPassword: `{{.WinRMPassword}}`,
|
||||
}
|
||||
|
|
@ -232,9 +235,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Takes the inline scripts, concatenates them
|
||||
// into a temporary file and returns a string containing the location
|
||||
// of said file.
|
||||
// Takes the inline scripts, concatenates them into a temporary file and
|
||||
// returns a string containing the location of said file.
|
||||
func extractScript(p *Provisioner) (string, error) {
|
||||
temp, err := ioutil.TempFile(os.TempDir(), "packer-powershell-provisioner")
|
||||
if err != nil {
|
||||
|
|
@ -288,11 +290,10 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
return fmt.Errorf("Error processing command: %s", err)
|
||||
}
|
||||
|
||||
// Upload the file and run the command. Do this in the context of
|
||||
// a single retryable function so that we don't end up with
|
||||
// the case that the upload succeeded, a restart is initiated,
|
||||
// and then the command is executed but the file doesn't exist
|
||||
// any longer.
|
||||
// Upload the file and run the command. Do this in the context of a
|
||||
// single retryable function so that we don't end up with the case
|
||||
// that the upload succeeded, a restart is initiated, and then the
|
||||
// command is executed but the file doesn't exist any longer.
|
||||
var cmd *packer.RemoteCmd
|
||||
err = p.retryable(func() error {
|
||||
if _, err := f.Seek(0, 0); err != nil {
|
||||
|
|
@ -330,13 +331,13 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
}
|
||||
|
||||
func (p *Provisioner) Cancel() {
|
||||
// Just hard quit. It isn't a big deal if what we're doing keeps
|
||||
// running on the other side.
|
||||
// Just hard quit. It isn't a big deal if what we're doing keeps running
|
||||
// on the other side.
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// retryable will retry the given function over and over until a
|
||||
// non-error is returned.
|
||||
// retryable will retry the given function over and over until a non-error is
|
||||
// returned.
|
||||
func (p *Provisioner) retryable(f func() error) error {
|
||||
startTimeout := time.After(p.config.StartRetryTimeout)
|
||||
for {
|
||||
|
|
@ -349,9 +350,8 @@ func (p *Provisioner) retryable(f func() error) error {
|
|||
err = fmt.Errorf("Retryable error: %s", err)
|
||||
log.Print(err.Error())
|
||||
|
||||
// Check if we timed out, otherwise we retry. It is safe to
|
||||
// retry since the only error case above is if the command
|
||||
// failed to START.
|
||||
// Check if we timed out, otherwise we retry. It is safe to retry
|
||||
// since the only error case above is if the command failed to START.
|
||||
select {
|
||||
case <-startTimeout:
|
||||
return err
|
||||
|
|
@ -361,12 +361,15 @@ func (p *Provisioner) retryable(f func() error) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Environment variables required within the remote environment are uploaded within a PS script and
|
||||
// then enabled by 'dot sourcing' the script immediately prior to execution of the main command
|
||||
// Environment variables required within the remote environment are uploaded
|
||||
// within a PS script and then enabled by 'dot sourcing' the script
|
||||
// immediately prior to execution of the main command
|
||||
func (p *Provisioner) prepareEnvVars(elevated bool) (err error) {
|
||||
// Collate all required env vars into a plain string with required formatting applied
|
||||
// Collate all required env vars into a plain string with required
|
||||
// formatting applied
|
||||
flattenedEnvVars := p.createFlattenedEnvVars(elevated)
|
||||
// Create a powershell script on the target build fs containing the flattened env vars
|
||||
// Create a powershell script on the target build fs containing the
|
||||
// flattened env vars
|
||||
err = p.uploadEnvVars(flattenedEnvVars)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -426,12 +429,20 @@ func (p *Provisioner) createFlattenedEnvVars(elevated bool) (flattened string) {
|
|||
}
|
||||
|
||||
func (p *Provisioner) uploadEnvVars(flattenedEnvVars string) (err error) {
|
||||
// Upload all env vars to a powershell script on the target build file system
|
||||
// Upload all env vars to a powershell script on the target build file
|
||||
// system. Do this in the context of a single retryable function so that
|
||||
// we gracefully handle any errors created by transient conditions such as
|
||||
// a system restart
|
||||
envVarReader := strings.NewReader(flattenedEnvVars)
|
||||
log.Printf("Uploading env vars to %s", p.config.RemoteEnvVarPath)
|
||||
err = p.communicator.Upload(p.config.RemoteEnvVarPath, envVarReader, nil)
|
||||
err = p.retryable(func() error {
|
||||
if err := p.communicator.Upload(p.config.RemoteEnvVarPath, envVarReader, nil); err != nil {
|
||||
return fmt.Errorf("Error uploading ps script containing env vars: %s", err)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error uploading ps script containing env vars: %s", err)
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -446,7 +457,8 @@ func (p *Provisioner) createCommandText() (command string, err error) {
|
|||
}
|
||||
|
||||
func (p *Provisioner) createCommandTextNonPrivileged() (command string, err error) {
|
||||
// Prepare everything needed to enable the required env vars within the remote environment
|
||||
// Prepare everything needed to enable the required env vars within the
|
||||
// remote environment
|
||||
err = p.prepareEnvVars(false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -473,7 +485,8 @@ func getWinRMPassword(buildName string) string {
|
|||
}
|
||||
|
||||
func (p *Provisioner) createCommandTextPrivileged() (command string, err error) {
|
||||
// Prepare everything needed to enable the required env vars within the remote environment
|
||||
// Prepare everything needed to enable the required env vars within the
|
||||
// remote environment
|
||||
err = p.prepareEnvVars(true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -489,8 +502,9 @@ func (p *Provisioner) createCommandTextPrivileged() (command string, err error)
|
|||
return "", fmt.Errorf("Error processing command: %s", err)
|
||||
}
|
||||
|
||||
// OK so we need an elevated shell runner to wrap our command, this is going to have its own path
|
||||
// generate the script and update the command runner in the process
|
||||
// OK so we need an elevated shell runner to wrap our command, this is
|
||||
// going to have its own path generate the script and update the command
|
||||
// runner in the process
|
||||
path, err := p.generateElevatedRunner(command)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error generating elevated runner: %s", err)
|
||||
|
|
@ -507,23 +521,23 @@ func (p *Provisioner) generateElevatedRunner(command string) (uploadedPath strin
|
|||
|
||||
var buffer bytes.Buffer
|
||||
|
||||
// Output from the elevated command cannot be returned directly to
|
||||
// the Packer console. In order to be able to view output from elevated
|
||||
// commands and scripts an indirect approach is used by which the
|
||||
// commands output is first redirected to file. The output file is then
|
||||
// 'watched' by Packer while the elevated command is running and any
|
||||
// content appearing in the file is written out to the console.
|
||||
// Below the portion of command required to redirect output from the
|
||||
// command to file is built and appended to the existing command string
|
||||
// Output from the elevated command cannot be returned directly to the
|
||||
// Packer console. In order to be able to view output from elevated
|
||||
// commands and scripts an indirect approach is used by which the commands
|
||||
// output is first redirected to file. The output file is then 'watched'
|
||||
// by Packer while the elevated command is running and any content
|
||||
// appearing in the file is written out to the console. Below the portion
|
||||
// of command required to redirect output from the command to file is
|
||||
// built and appended to the existing command string
|
||||
taskName := fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
|
||||
// Only use %ENVVAR% format for environment variables when setting
|
||||
// the log file path; Do NOT use $env:ENVVAR format as it won't be
|
||||
// expanded correctly in the elevatedTemplate
|
||||
// Only use %ENVVAR% format for environment variables when setting the log
|
||||
// file path; Do NOT use $env:ENVVAR format as it won't be expanded
|
||||
// correctly in the elevatedTemplate
|
||||
logFile := `%SYSTEMROOT%/Temp/` + taskName + ".out"
|
||||
command += fmt.Sprintf(" > %s 2>&1", logFile)
|
||||
|
||||
// elevatedTemplate wraps the command in a single quoted XML text
|
||||
// string so we need to escape characters considered 'special' in XML.
|
||||
// elevatedTemplate wraps the command in a single quoted XML text string
|
||||
// so we need to escape characters considered 'special' in XML.
|
||||
err = xml.EscapeText(&buffer, []byte(command))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error escaping characters special to XML in command %s: %s", command, err)
|
||||
|
|
|
|||
|
|
@ -102,6 +102,14 @@ credentials inline, or in the environment, Packer will check this location. You
|
|||
can optionally specify a different location in the configuration by setting the
|
||||
environment with the `AWS_SHARED_CREDENTIALS_FILE` variable.
|
||||
|
||||
The format for the credentials file is like so
|
||||
|
||||
```
|
||||
[default]
|
||||
aws_access_key_id=<your access key id>
|
||||
aws_secret_access_key=<your secret access key>
|
||||
```
|
||||
|
||||
You may also configure the profile to use by setting the `profile`
|
||||
configuration option, or setting the `AWS_PROFILE` environment variable:
|
||||
|
||||
|
|
|
|||
|
|
@ -13,19 +13,21 @@ sidebar_current: 'docs-builders-hyperv-iso'
|
|||
|
||||
Type: `hyperv-iso`
|
||||
|
||||
The Hyper-V Packer builder is able to create [Hyper-V](https://www.microsoft.com/en-us/server-cloud/solutions/virtualization.aspx)
|
||||
The Hyper-V Packer builder is able to create
|
||||
[Hyper-V](https://www.microsoft.com/en-us/server-cloud/solutions/virtualization.aspx)
|
||||
virtual machines and export them, starting from an ISO image.
|
||||
|
||||
The builder builds a virtual machine by creating a new virtual machine
|
||||
from scratch, booting it, installing an OS, provisioning software within
|
||||
the OS, then shutting it down. The result of the Hyper-V builder is a directory
|
||||
containing all the files necessary to run the virtual machine portably.
|
||||
The builder builds a virtual machine by creating a new virtual machine from
|
||||
scratch. Typically, the VM is booted, an OS is installed, and software is
|
||||
provisioned within the OS. Finally the VM is shut down. The result of the
|
||||
Hyper-V builder is a directory containing all the files necessary to run
|
||||
the virtual machine portably.
|
||||
|
||||
## Basic Example
|
||||
|
||||
Here is a basic example. This example is not functional. It will start the
|
||||
OS installer but then fail because we don't provide the preseed file for
|
||||
Ubuntu to self-install. Still, the example serves to show the basic configuration:
|
||||
Here is a basic example. This example is not functional. It will start the OS
|
||||
installer but then fail because we don't provide the preseed file for Ubuntu
|
||||
to self-install. Still, the example serves to show the basic configuration:
|
||||
|
||||
``` json
|
||||
{
|
||||
|
|
@ -39,234 +41,262 @@ Ubuntu to self-install. Still, the example serves to show the basic configuratio
|
|||
}
|
||||
```
|
||||
|
||||
It is important to add a `shutdown_command`. By default Packer halts the
|
||||
virtual machine and the file system may not be sync'd. Thus, changes made in a
|
||||
provisioner might not be saved.
|
||||
By default Packer will perform a hard power off of a virtual machine.
|
||||
However, when a machine is powered off this way, it is possible that
|
||||
changes made to the VMs file system may not be fully synced, possibly
|
||||
leading to corruption of files or lost changes. As such, it is important to
|
||||
add a `shutdown_command`. This tells Packer how to safely shutdown and
|
||||
power off the VM.
|
||||
|
||||
## Configuration Reference
|
||||
|
||||
There are many configuration options available for the Hyper-V builder.
|
||||
They are organized below into two categories: required and optional. Within
|
||||
each category, the available options are alphabetized and described.
|
||||
There are many configuration options available for the Hyper-V builder. They
|
||||
are organized below into two categories: required and optional. Within each
|
||||
category, the available options are alphabetized and described.
|
||||
|
||||
In addition to the options listed here, a
|
||||
[communicator](/docs/templates/communicator.html)
|
||||
can be configured for this builder.
|
||||
[communicator](/docs/templates/communicator.html) can be configured for this
|
||||
builder.
|
||||
|
||||
### Required:
|
||||
|
||||
- `iso_checksum` (string) - The checksum for the OS ISO file or virtual
|
||||
harddrive file. Because these files are so large, this is required and
|
||||
Packer will verify it prior to booting a virtual machine with the ISO or
|
||||
virtual harddrive attached. The type of the checksum is specified with
|
||||
`iso_checksum_type`, documented below.
|
||||
- `iso_checksum` (string) - The checksum for the ISO file or virtual
|
||||
hard drive file. The algorithm to use when computing the checksum is
|
||||
specified with `iso_checksum_type`.
|
||||
|
||||
- `iso_checksum_type` (string) - The type of the checksum specified in
|
||||
`iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or
|
||||
"sha512" currently. While "none" will skip checksumming, this is not
|
||||
recommended since ISO files and virtual harddrive files are generally large
|
||||
and corruption does happen from time to time.
|
||||
- `iso_checksum_type` (string) - The algorithm to be used when computing
|
||||
the checksum of the file specified in `iso_checksum`. Currently, valid
|
||||
values are "none", "md5", "sha1", "sha256", or "sha512". Since the
|
||||
validity of ISO and virtual disk files are typically crucial to a
|
||||
successful build, Packer performs a check of any supplied media by
|
||||
default. While setting "none" will cause Packer to skip this check,
|
||||
corruption of large files such as ISOs and virtual hard drives can
|
||||
occur from time to time. As such, skipping this check is not
|
||||
recommended.
|
||||
|
||||
- `iso_url` (string) - A URL to the ISO containing the installation image or
|
||||
virtual harddrive vhd or vhdx file to clone. This URL can be either an HTTP
|
||||
URL or a file URL (or path to a file). If this is an HTTP URL, Packer will
|
||||
download the file and cache it between runs.
|
||||
virtual hard drive (VHD or VHDX) file to clone. This URL can be either an
|
||||
HTTP URL or a file URL (or path to a file). If this is an HTTP URL, Packer
|
||||
will download the file and cache it between runs.
|
||||
|
||||
### Optional:
|
||||
|
||||
- `boot_command` (array of strings) - This is an array of commands to type
|
||||
when the virtual machine is first booted. The goal of these commands should
|
||||
be to type just enough to initialize the operating system installer. Special
|
||||
keys can be typed as well, and are covered in the section below on the boot
|
||||
command. If this is not specified, it is assumed the installer will start
|
||||
itself.
|
||||
when the virtual machine is first booted. The goal of these commands
|
||||
should be to type just enough to initialize the operating system
|
||||
installer. Special keys can be typed as well, and are covered in the
|
||||
section below on the boot command. If this is not specified, it is assumed
|
||||
the installer will start itself.
|
||||
|
||||
- `boot_wait` (string) - The time to wait after booting the initial virtual
|
||||
machine before typing the `boot_command`. The value of this should be
|
||||
a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
|
||||
five seconds and one minute 30 seconds, respectively. If this isn't specified,
|
||||
the default is 10 seconds.
|
||||
machine before typing the `boot_command`. The value specified should be
|
||||
a duration. For example, setting a duration of "1m30s" would cause
|
||||
Packer to wait for 1 minute 30 seconds before typing the boot command.
|
||||
The default duration is "10s" (10 seconds).
|
||||
|
||||
- `cpu` (number) - The number of cpus the virtual machine should use. If this isn't specified,
|
||||
the default is 1 cpu.
|
||||
- `cpu` (number) - The number of CPUs the virtual machine should use. If
|
||||
this isn't specified, the default is 1 CPU.
|
||||
|
||||
- `disk_additional_size` (array of integers) - The size(s) of any additional
|
||||
hard disks for the VM in megabytes. If this is not specified then the VM
|
||||
will only contain a primary hard disk. Additional drives will be attached to the SCSI
|
||||
interface only. The builder uses expandable, not fixed-size virtual hard disks,
|
||||
so the actual file representing the disk will not use the full size unless it is full.
|
||||
- `differencing_disk` (boolean) - If true enables differencing disks. Only
|
||||
the changes will be written to the new disk. This is especially useful if
|
||||
your source is a VHD/VHDX. This defaults to `false`.
|
||||
|
||||
- `disk_additional_size` (array of integers) - The size or sizes of any
|
||||
additional hard disks for the VM in megabytes. If this is not specified
|
||||
then the VM will only contain a primary hard disk. Additional drives
|
||||
will be attached to the SCSI interface only. The builder uses
|
||||
expandable rather than fixed-size virtual hard disks, so the actual
|
||||
file representing the disk will not use the full size unless it is
|
||||
full.
|
||||
|
||||
- `disk_block_size` (string) - The block size of the VHD to be created.
|
||||
Recommended disk block size for Linux hyper-v guests is 1 MiB. This
|
||||
defaults to "32 MiB".
|
||||
|
||||
- `disk_size` (number) - The size, in megabytes, of the hard disk to create
|
||||
for the VM. By default, this is 40 GB.
|
||||
|
||||
- `differencing_disk` (boolean) - If true enables differencing disks. Only the changes will be written to the new disk. This is especially useful if your
|
||||
source is a vhd/vhdx. This defaults to false.
|
||||
- `enable_dynamic_memory` (boolean) - If `true` enable dynamic memory for
|
||||
the virtual machine. This defaults to `false`.
|
||||
|
||||
- `headless` (boolean) - Packer defaults to building Hyper-V virtual
|
||||
machines by launching a GUI that shows the console of the machine
|
||||
being built. When this value is set to true, the machine will start without
|
||||
a console.
|
||||
- `enable_mac_spoofing` (boolean) - If `true` enable MAC address spoofing
|
||||
for the virtual machine. This defaults to `false`.
|
||||
|
||||
- `skip_export` (boolean) - If true skips VM export. If you are interested only in the vhd/vhdx files, you can enable this option. This will create
|
||||
inline disks which improves the build performance. There will not be any copying of source vhds to temp directory. This defaults to false.
|
||||
- `enable_secure_boot` (boolean) - If `true` enable secure boot for the
|
||||
virtual machine. This defaults to `false`. See `secure_boot_template`
|
||||
below for additional settings.
|
||||
|
||||
- `enable_dynamic_memory` (boolean) - If true enable dynamic memory for virtual machine.
|
||||
This defaults to false.
|
||||
|
||||
- `enable_mac_spoofing` (boolean) - If true enable mac spoofing for virtual machine.
|
||||
This defaults to false.
|
||||
|
||||
- `enable_secure_boot` (boolean) - If true enable secure boot for virtual machine. This defaults to false.
|
||||
|
||||
- `secure_boot_template` (string) - The secure boot template to be configured. Valid values are "MicrosoftWindows" (Windows) or
|
||||
"MicrosoftUEFICertificateAuthority" (Linux). This only takes effect if enable_secure_boot is set to "true". This defaults to "MicrosoftWindows".
|
||||
|
||||
|
||||
- `enable_virtualization_extensions` (boolean) - If true enable virtualization extensions for virtual machine.
|
||||
This defaults to false. For nested virtualization you need to enable mac spoofing, disable dynamic memory
|
||||
and have at least 4GB of RAM for virtual machine.
|
||||
|
||||
- `floppy_files` (array of strings) - A list of files to place onto a floppy
|
||||
disk that is attached when the VM is booted. This is most useful
|
||||
for unattended Windows installs, which look for an `Autounattend.xml` file
|
||||
on removable media. By default, no floppy will be attached. All files
|
||||
listed in this setting get placed into the root directory of the floppy
|
||||
and the floppy is attached as the first floppy device. Currently, no
|
||||
support exists for creating sub-directories on the floppy. Wildcard
|
||||
characters (`*`, `?`, and `[]`) are allowed. Directory names are also allowed,
|
||||
which will add all the files found in the directory to the floppy.
|
||||
- `enable_virtualization_extensions` (boolean) - If `true` enable
|
||||
virtualization extensions for the virtual machine. This defaults to
|
||||
`false`. For nested virtualization you need to enable MAC spoofing,
|
||||
disable dynamic memory and have at least 4GB of RAM assigned to the
|
||||
virtual machine.
|
||||
|
||||
- `floppy_dirs` (array of strings) - A list of directories to place onto
|
||||
the floppy disk recursively. This is similar to the `floppy_files` option
|
||||
except that the directory structure is preserved. This is useful for when
|
||||
your floppy disk includes drivers or if you just want to organize it's
|
||||
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
|
||||
The maximum summary size of all files in the listed directories are the
|
||||
same as in `floppy_files`.
|
||||
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are
|
||||
allowed. The maximum summary size of all files in the listed directories
|
||||
are the same as in `floppy_files`.
|
||||
|
||||
- `floppy_files` (array of strings) - A list of files to place onto a floppy
|
||||
disk that is attached when the VM is booted. This is most useful for
|
||||
unattended Windows installs, which look for an `Autounattend.xml` file on
|
||||
removable media. By default, no floppy will be attached. All files listed
|
||||
in this setting get placed into the root directory of the floppy and the
|
||||
floppy is attached as the first floppy device. Currently, no support
|
||||
exists for creating sub-directories on the floppy. Wildcard characters
|
||||
(`*`, `?`, and `[]`) are allowed. Directory names are also allowed, which
|
||||
will add all the files found in the directory to the floppy.
|
||||
|
||||
- `generation` (number) - The Hyper-V generation for the virtual machine. By
|
||||
default, this is 1. Generation 2 Hyper-V virtual machines do not support
|
||||
floppy drives. In this scenario use `secondary_iso_images` instead. Hard
|
||||
drives and dvd drives will also be scsi and not ide.
|
||||
drives and DVD drives will also be SCSI and not IDE.
|
||||
|
||||
- `guest_additions_mode` (string) - How should guest additions be installed.
|
||||
If value `attach` then attach iso image with by specified by `guest_additions_path`.
|
||||
Otherwise guest additions is not installed.
|
||||
- `guest_additions_mode` (string) - If set to `attach` then attach and
|
||||
mount the ISO image specified in `guest_additions_path`. If set to
|
||||
`none` then guest additions are not attached and mounted; This is the
|
||||
default.
|
||||
|
||||
- `guest_additions_path` (string) - The path to the iso image for guest additions.
|
||||
- `guest_additions_path` (string) - The path to the ISO image for guest
|
||||
additions.
|
||||
|
||||
- `http_directory` (string) - Path to a directory to serve using an HTTP
|
||||
server. The files in this directory will be available over HTTP that will
|
||||
be requestable from the virtual machine. This is useful for hosting
|
||||
kickstart files and so on. By default this is "", which means no HTTP
|
||||
server will be started. The address and port of the HTTP server will be
|
||||
available as variables in `boot_command`. This is covered in more detail
|
||||
below.
|
||||
- `headless` (boolean) - Packer defaults to building Hyper-V virtual
|
||||
machines by launching a GUI that shows the console of the machine being
|
||||
built. When this value is set to true, the machine will start without a
|
||||
console.
|
||||
|
||||
- `http_directory` (string) - Path to a directory to serve using Packers
|
||||
inbuilt HTTP server. The files in this directory will be available
|
||||
over HTTP to the virtual machine. This is useful for hosting kickstart
|
||||
files and so on. By default this value is unset and the HTTP server is
|
||||
not started. The address and port of the HTTP server will be available
|
||||
as variables in `boot_command`. This is covered in more detail below.
|
||||
|
||||
- `http_port_min` and `http_port_max` (number) - These are the minimum and
|
||||
maximum port to use for the HTTP server started to serve the `http_directory`.
|
||||
Because Packer often runs in parallel, Packer will choose a randomly available
|
||||
port in this range to run the HTTP server. If you want to force the HTTP
|
||||
server to be on one port, make this minimum and maximum port the same.
|
||||
maximum port to use for the HTTP server started to serve the
|
||||
`http_directory`. Since Packer often runs in parallel, a randomly
|
||||
available port in this range will be repeatedly chosen until an
|
||||
available port is found. To force the HTTP server to use a specific
|
||||
port, set an identical value for `http_port_min` and `http_port_max`.
|
||||
By default the values are 8000 and 9000, respectively.
|
||||
|
||||
- `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
|
||||
Packer will try these in order. If anything goes wrong attempting to download
|
||||
or while downloading a single URL, it will move on to the next. All URLs
|
||||
must point to the same file (same checksum). By default this is empty
|
||||
and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
|
||||
|
||||
- `iso_target_extension` (string) - The extension of the iso file after
|
||||
- `iso_target_extension` (string) - The extension of the ISO file after
|
||||
download. This defaults to "iso".
|
||||
|
||||
- `iso_target_path` (string) - The path where the iso should be saved after
|
||||
download. By default will go in the packer cache, with a hash of the
|
||||
original filename as its name.
|
||||
- `iso_target_path` (string) - The path where the ISO should be saved after
|
||||
download. By default the ISO will be saved in the Packer cache
|
||||
directory with a hash of the original filename as its name.
|
||||
|
||||
- `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
|
||||
Packer will try these in order. If anything goes wrong attempting to
|
||||
download or while downloading a single URL, it will move on to the next.
|
||||
All URLs must point to the same file (same checksum). By default this is
|
||||
empty and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be
|
||||
specified.
|
||||
|
||||
- `mac_address` (string) - This allows a specific MAC address to be used on
|
||||
the default virtual network card. The MAC address must be a string with
|
||||
no delimiters, for example "0000deadbeef".
|
||||
|
||||
- `output_directory` (string) - This is the path to the directory where the
|
||||
resulting virtual machine will be created. This may be relative or absolute.
|
||||
If relative, the path is relative to the working directory when `packer`
|
||||
is executed. This directory must not exist or be empty prior to running the builder.
|
||||
By default this is "output-BUILDNAME" where "BUILDNAME" is the name
|
||||
of the build.
|
||||
resulting virtual machine will be created. This may be relative or
|
||||
absolute. If relative, the path is relative to the working directory when
|
||||
`packer` is executed. This directory must not exist or be empty prior to
|
||||
running the builder. By default this is "output-BUILDNAME" where
|
||||
"BUILDNAME" is the name of the build.
|
||||
|
||||
- `ram_size` (number) - The size, in megabytes, of the ram to create
|
||||
for the VM. By default, this is 1 GB.
|
||||
- `ram_size` (number) - The amount, in megabytes, of RAM to assign to the
|
||||
VM. By default, this is 1 GB.
|
||||
|
||||
- `secondary_iso_images` (array of strings) - A list of iso paths to attached to a
|
||||
VM when it is booted. This is most useful for unattended Windows installs, which
|
||||
look for an `Autounattend.xml` file on removable media. By default, no
|
||||
secondary iso will be attached.
|
||||
- `secondary_iso_images` (array of strings) - A list of ISO paths to
|
||||
attach to a VM when it is booted. This is most useful for unattended
|
||||
Windows installs, which look for an `Autounattend.xml` file on removable
|
||||
media. By default, no secondary ISO will be attached.
|
||||
|
||||
- `shutdown_command` (string) - The command to use to gracefully shut down the machine once all
|
||||
the provisioning is done. By default this is an empty string, which tells Packer to just
|
||||
forcefully shut down the machine unless a shutdown command takes place inside script so this may
|
||||
safely be omitted. If one or more scripts require a reboot it is suggested to leave this blank
|
||||
since reboots may fail and specify the final shutdown command in your last script.
|
||||
- `secure_boot_template` (string) - The secure boot template to be
|
||||
configured. Valid values are "MicrosoftWindows" (Windows) or
|
||||
"MicrosoftUEFICertificateAuthority" (Linux). This only takes effect if
|
||||
`enable_secure_boot` is set to "true". This defaults to "MicrosoftWindows".
|
||||
|
||||
- `shutdown_command` (string) - The command to use to gracefully shut down
|
||||
the machine once all provisioning is complete. By default this is an
|
||||
empty string, which tells Packer to just forcefully shut down the
|
||||
machine. This setting can be safely omitted if for example, a shutdown
|
||||
command to gracefully halt the machine is configured inside a
|
||||
provisioning script. If one or more scripts require a reboot it is
|
||||
suggested to leave this blank (since reboots may fail) and instead
|
||||
specify the final shutdown command in your last script.
|
||||
|
||||
- `shutdown_timeout` (string) - The amount of time to wait after executing
|
||||
the `shutdown_command` for the virtual machine to actually shut down.
|
||||
If it doesn't shut down in this time, it is an error. By default, the timeout
|
||||
is "5m", or five minutes.
|
||||
If the machine doesn't shut down in this time it is considered an
|
||||
error. By default, the time out is "5m" (five minutes).
|
||||
|
||||
- `skip_compaction` (boolean) - If true skip compacting the hard disk for virtual machine when
|
||||
exporting. This defaults to false.
|
||||
- `skip_compaction` (boolean) - If `true` skip compacting the hard disk for
|
||||
the virtual machine when exporting. This defaults to `false`.
|
||||
|
||||
- `switch_name` (string) - The name of the switch to connect the virtual machine to. Be defaulting
|
||||
this to an empty string, Packer will try to determine the switch to use by looking for
|
||||
external switch that is up and running.
|
||||
- `skip_export` (boolean) - If `true` Packer will skip the export of the
|
||||
VM. If you are interested only in the VHD/VHDX files, you can enable
|
||||
this option. This will create inline disks which improves the build
|
||||
performance. There will not be any copying of source VHDs to the temp
|
||||
directory. This defaults to `false`.
|
||||
|
||||
- `switch_vlan_id` (string) - This is the vlan of the virtual switch's network card.
|
||||
By default none is set. If none is set then a vlan is not set on the switch's network card.
|
||||
If this value is set it should match the vlan specified in by `vlan_id`.
|
||||
- `switch_name` (string) - The name of the switch to connect the virtual
|
||||
machine to. By default, leaving this value unset will cause Packer to
|
||||
try and determine the switch to use by looking for an external switch
|
||||
that is up and running.
|
||||
|
||||
- `use_fixed_vhd_format` (boolean) - If true, creates the boot disk on the virtual machine as
|
||||
a fixed VHD format disk. The default is false, which creates a dynamic VHDX format disk. This
|
||||
option requires setting `generation` to 1, `skip_compaction` to true, and `differencing_disk` to false.
|
||||
Additionally, any value entered for `disk_block_size` will be ignored. The most likely use case for this
|
||||
option is outputing a disk that is in the format required for upload to Azure.
|
||||
- `switch_vlan_id` (string) - This is the VLAN of the virtual switch's
|
||||
network card. By default none is set. If none is set then a VLAN is not
|
||||
set on the switch's network card. If this value is set it should match
|
||||
the VLAN specified in by `vlan_id`.
|
||||
|
||||
- `temp_path` (string) - This is the temporary path in which Packer will
|
||||
create the virtual machine. By default the value is the system `%temp%`.
|
||||
|
||||
- `use_fixed_vhd_format` (boolean) - If true, creates the boot disk on the
|
||||
virtual machine as a fixed VHD format disk. The default is `false`, which
|
||||
creates a dynamic VHDX format disk. This option requires setting
|
||||
`generation` to `1`, `skip_compaction` to `true`, and
|
||||
`differencing_disk` to `false`. Additionally, any value entered for
|
||||
`disk_block_size` will be ignored. The most likely use case for this
|
||||
option is outputing a disk that is in the format required for upload to
|
||||
Azure.
|
||||
|
||||
- `vhd_temp_path` (string) - A separate path to be used for storing the VM's
|
||||
disk image. The purpose is to enable reading and writing to take place on
|
||||
different physical disks (read from VHD temp path, write to regular temp
|
||||
path while exporting the VM) to eliminate a single-disk bottleneck.
|
||||
|
||||
- `vlan_id` (string) - This is the vlan of the virtual machine's network card
|
||||
for the new virtual machine. By default none is set. If none is set then
|
||||
vlans are not set on the virtual machine's network card.
|
||||
- `vlan_id` (string) - This is the VLAN of the virtual machine's network
|
||||
card for the new virtual machine. By default none is set. If none is set
|
||||
then VLANs are not set on the virtual machine's network card.
|
||||
|
||||
- `mac_address` (string) - This allows a specific MAC address to be used on the
|
||||
default virtual network card. The MAC address must be a string with no
|
||||
delimiters, for example "0000deadbeef".
|
||||
|
||||
- `vm_name` (string) - This is the name of the virtual machine for the new virtual
|
||||
machine, without the file extension. By default this is "packer-BUILDNAME",
|
||||
- `vm_name` (string) - This is the name of the new virtual machine,
|
||||
without the file extension. By default this is "packer-BUILDNAME",
|
||||
where "BUILDNAME" is the name of the build.
|
||||
|
||||
- `temp_path` (string) - This is the temporary path in which Packer will create the virtual
|
||||
machine. Default value is system `%temp%`
|
||||
|
||||
- `disk_block_size` (string) - The block size of the VHD to be created.
|
||||
Recommended disk block size for Linux hyper-v guests is 1 MiB. This defaults to "32 MiB".
|
||||
|
||||
## Boot Command
|
||||
|
||||
The `boot_command` configuration is very important: it specifies the keys
|
||||
to type when the virtual machine is first booted in order to start the
|
||||
OS installer. This command is typed after `boot_wait`, which gives the
|
||||
virtual machine some time to actually load the ISO.
|
||||
The `boot_command` configuration is very important: it specifies the keys to
|
||||
type when the virtual machine is first booted in order to start the OS
|
||||
installer. This command is typed after `boot_wait`, which gives the virtual
|
||||
machine some time to actually load the ISO.
|
||||
|
||||
As documented above, the `boot_command` is an array of strings. The
|
||||
strings are all typed in sequence. It is an array only to improve readability
|
||||
within the template.
|
||||
As documented above, the `boot_command` is an array of strings. The strings
|
||||
are all typed in sequence. It is an array only to improve readability within
|
||||
the template.
|
||||
|
||||
The boot command is "typed" character for character over the virtual keyboard
|
||||
to the machine, simulating a human actually typing the keyboard.
|
||||
|
||||
<%= partial "partials/builders/boot-command" %>
|
||||
|
||||
Example boot command. This is actually a working boot command used to start
|
||||
an Ubuntu 12.04 installer:
|
||||
The example shown below is a working boot command used to start an Ubuntu
|
||||
12.04 installer:
|
||||
|
||||
``` json
|
||||
[
|
||||
|
|
@ -287,23 +317,27 @@ For more examples of various boot commands, see the sample projects from our
|
|||
|
||||
## Integration Services
|
||||
|
||||
Packer will automatically attach the integration services iso as a dvd drive
|
||||
Packer will automatically attach the integration services ISO as a DVD drive
|
||||
for the version of Hyper-V that is running.
|
||||
|
||||
## Generation 1 vs Generation 2
|
||||
|
||||
Floppy drives are no longer supported by generation 2 machines. This requires you to
|
||||
take another approach when dealing with preseed or answer files. Two possible options
|
||||
are using virtual dvd drives or using the built in web server.
|
||||
Floppy drives are no longer supported by generation 2 machines. This requires
|
||||
you to take another approach when dealing with preseed or answer files. Two
|
||||
possible options are using virtual DVD drives or using Packers built in web
|
||||
server.
|
||||
|
||||
When dealing with Windows you need to enable UEFI drives for generation 2 virtual machines.
|
||||
When dealing with Windows you need to enable UEFI drives for generation 2
|
||||
virtual machines.
|
||||
|
||||
## Creating iso from directory
|
||||
## Creating an ISO From a Directory
|
||||
|
||||
Programs like mkisofs can be used to create an iso from a directory.
|
||||
There is a [windows version of mkisofs](http://opensourcepack.blogspot.co.uk/p/cdrtools.html).
|
||||
Programs like mkisofs can be used to create an ISO from a directory. There is
|
||||
a [windows version of
|
||||
mkisofs](http://opensourcepack.blogspot.co.uk/p/cdrtools.html) available.
|
||||
|
||||
Example powershell script. This is an actually working powershell script used to create a Windows answer iso:
|
||||
Below is a working PowerShell script that can be used to create a Windows
|
||||
answer ISO:
|
||||
|
||||
``` powershell
|
||||
$isoFolder = "answer-iso"
|
||||
|
|
@ -802,7 +836,7 @@ Finish Setup cache proxy during installation -->
|
|||
|
||||
sysprep-unattend.xml:
|
||||
|
||||
``` text
|
||||
``` xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<unattend xmlns="urn:schemas-microsoft-com:unattend">
|
||||
<settings pass="generalize">
|
||||
|
|
@ -866,8 +900,8 @@ Finish proxy after sysprep -->
|
|||
|
||||
## Example For Ubuntu Vivid Generation 2
|
||||
|
||||
If you are running Windows under virtualization, you may need to create
|
||||
a virtual switch with an `External` connection type.
|
||||
If you are running Windows under virtualization, you may need to create a
|
||||
virtual switch with an `External` connection type.
|
||||
|
||||
### Packer config:
|
||||
|
||||
|
|
@ -916,7 +950,7 @@ a virtual switch with an `External` connection type.
|
|||
"generation": 2,
|
||||
"enable_secure_boot": false
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -5,31 +5,32 @@ description: |-
|
|||
The Hyper-V Packer builder is able to clone an existing Hyper-V virtual machine and export them.
|
||||
layout: "docs"
|
||||
sidebar_current: 'docs-builders-hyperv-vmcx'
|
||||
page_title: "Hyper-V Builder (from an vmcx)"
|
||||
page_title: "Hyper-V Builder (from a vmcx)"
|
||||
---
|
||||
|
||||
# Hyper-V Builder (from a vmcx)
|
||||
|
||||
Type: `hyperv-vmcx`
|
||||
|
||||
The Hyper-V Packer builder is able to use exported virtual machines or clone existing
|
||||
The Hyper-V Packer builder is able to use exported virtual machines or clone
|
||||
existing
|
||||
[Hyper-V](https://www.microsoft.com/en-us/server-cloud/solutions/virtualization.aspx)
|
||||
virtual machines.
|
||||
|
||||
The builder imports a virtual machine or clones an existing virtual machine boots it,
|
||||
and provisioning software within the OS, then shutting it down. The result of the
|
||||
Hyper-V builder is a directory containing all the files necessary to run the virtual
|
||||
machine portably.
|
||||
Typically, the builder imports or clones an existing virtual machine,
|
||||
boots it, provisions software within the OS, and then shuts it down. The
|
||||
result of the Hyper-V builder is a directory containing all the files
|
||||
necessary to run the virtual machine portably.
|
||||
|
||||
## Basic Example
|
||||
|
||||
Here is a basic example. This example is not functional. It will start the
|
||||
OS installer but then fail because we don't provide the preseed file for
|
||||
Ubuntu to self-install. Still, the example serves to show the basic configuration:
|
||||
Here is a basic example. This example is not functional. It will start the OS
|
||||
installer but then fail because we don't provide the preseed file for Ubuntu
|
||||
to self-install. Still, the example serves to show the basic configuration:
|
||||
|
||||
Import from folder:
|
||||
|
||||
```json
|
||||
``` json
|
||||
{
|
||||
"type": "hyperv-vmcx",
|
||||
"clone_from_vmxc_path": "c:\\virtual machines\\ubuntu-12.04.5-server-amd64",
|
||||
|
|
@ -41,7 +42,7 @@ Import from folder:
|
|||
|
||||
Clone from existing virtual machine:
|
||||
|
||||
```json
|
||||
``` json
|
||||
{
|
||||
"clone_from_vm_name": "ubuntu-12.04.5-server-amd64",
|
||||
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
|
||||
|
|
@ -51,19 +52,22 @@ Clone from existing virtual machine:
|
|||
}
|
||||
```
|
||||
|
||||
It is important to add a `shutdown_command`. By default Packer halts the
|
||||
virtual machine and the file system may not be sync'd. Thus, changes made in a
|
||||
provisioner might not be saved.
|
||||
By default Packer will perform a hard power off of a virtual machine.
|
||||
However, when a machine is powered off this way, it is possible that
|
||||
changes made to the VMs file system may not be fully synced, possibly
|
||||
leading to corruption of files or lost changes. As such, it is important to
|
||||
add a `shutdown_command`. This tells Packer how to safely shutdown and
|
||||
power off the VM.
|
||||
|
||||
## Configuration Reference
|
||||
|
||||
There are many configuration options available for the Hyper-V builder.
|
||||
They are organized below into two categories: required and optional. Within
|
||||
each category, the available options are alphabetized and described.
|
||||
There are many configuration options available for the Hyper-V builder. They
|
||||
are organized below into two categories: required and optional. Within each
|
||||
category, the available options are alphabetized and described.
|
||||
|
||||
In addition to the options listed here, a
|
||||
[communicator](/docs/templates/communicator.html)
|
||||
can be configured for this builder.
|
||||
[communicator](/docs/templates/communicator.html) can be configured for this
|
||||
builder.
|
||||
|
||||
### Required for virtual machine import:
|
||||
|
||||
|
|
@ -77,117 +81,126 @@ can be configured for this builder.
|
|||
|
||||
### Optional:
|
||||
|
||||
- `clone_from_snapshot_name` (string) - The name of the snapshot
|
||||
|
||||
- `clone_all_snapshots` (boolean) - Should all snapshots be cloned when the
|
||||
machine is cloned.
|
||||
|
||||
- `boot_command` (array of strings) - This is an array of commands to type
|
||||
when the virtual machine is first booted. The goal of these commands should
|
||||
be to type just enough to initialize the operating system installer.
|
||||
Special keys can be typed as well, and are covered in the section below on
|
||||
the boot command. If this is not specified, it is assumed the installer
|
||||
will start itself.
|
||||
when the virtual machine is first booted. The goal of these commands
|
||||
should be to type just enough to initialize the operating system
|
||||
installer. Special keys can be typed as well, and are covered in the
|
||||
section below on the boot command. If this is not specified, it is assumed
|
||||
the installer will start itself.
|
||||
|
||||
- `boot_wait` (string) - The time to wait after booting the initial virtual
|
||||
machine before typing the `boot_command`. The value of this should be
|
||||
a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
|
||||
five seconds and one minute 30 seconds, respectively. If this isn't
|
||||
specified, the default is 10 seconds.
|
||||
machine before typing the `boot_command`. The value specified should be
|
||||
a duration. For example, setting a duration of "1m30s" would cause
|
||||
Packer to wait for 1 minute 30 seconds before typing the boot command.
|
||||
The default duration is "10s" (10 seconds).
|
||||
|
||||
- `cpu` (number) - The number of cpus the virtual machine should use. If
|
||||
this isn't specified, the default is 1 cpu.
|
||||
- `clone_all_snapshots` (boolean) - If set to `true` all snapshots will be
|
||||
cloned when the machine is cloned.
|
||||
|
||||
- `enable_dynamic_memory` (boolean) - If true enable dynamic memory for virtual
|
||||
machine. This defaults to false.
|
||||
- `clone_from_snapshot_name` (string) - The name of the snapshot to clone
|
||||
from.
|
||||
|
||||
- `enable_mac_spoofing` (boolean) - If true enable mac spoofing for virtual
|
||||
machine. This defaults to false.
|
||||
- `cpu` (number) - The number of CPUs the virtual machine should use. If
|
||||
this isn't specified, the default is 1 CPU.
|
||||
|
||||
- `enable_secure_boot` (boolean) - If true enable secure boot for virtual machine. This defaults to false.
|
||||
- `enable_dynamic_memory` (boolean) - If `true` enable dynamic memory for
|
||||
the virtual machine. This defaults to `false`.
|
||||
|
||||
- `secure_boot_template` (string) - The secure boot template to be configured. Valid values are "MicrosoftWindows" (Windows) or
|
||||
"MicrosoftUEFICertificateAuthority" (Linux). This only takes effect if enable_secure_boot is set to "true". This defaults to "MicrosoftWindows".
|
||||
- `enable_mac_spoofing` (boolean) - If `true` enable MAC address spoofing
|
||||
for the virtual machine. This defaults to `false`.
|
||||
|
||||
- `enable_virtualization_extensions` (boolean) - If true enable virtualization
|
||||
extensions for virtual machine. This defaults to false. For nested
|
||||
virtualization you need to enable mac spoofing, disable dynamic memory and
|
||||
have at least 4GB of RAM for virtual machine.
|
||||
- `enable_secure_boot` (boolean) - If `true` enable secure boot for the
|
||||
virtual machine. This defaults to `false`. See `secure_boot_template`
|
||||
below for additional settings.
|
||||
|
||||
- `enable_virtualization_extensions` (boolean) - If `true` enable
|
||||
virtualization extensions for the virtual machine. This defaults to
|
||||
`false`. For nested virtualization you need to enable MAC spoofing,
|
||||
disable dynamic memory and have at least 4GB of RAM assigned to the
|
||||
virtual machine.
|
||||
|
||||
- `floppy_dirs` (array of strings) - A list of directories to place onto
|
||||
the floppy disk recursively. This is similar to the `floppy_files` option
|
||||
except that the directory structure is preserved. This is useful for when
|
||||
your floppy disk includes drivers or if you just want to organize it's
|
||||
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are
|
||||
allowed. The maximum summary size of all files in the listed directories
|
||||
are the same as in `floppy_files`.
|
||||
|
||||
- `floppy_files` (array of strings) - A list of files to place onto a floppy
|
||||
disk that is attached when the VM is booted. This is most useful for
|
||||
unattended Windows installs, which look for an `Autounattend.xml` file on
|
||||
removable media. By default, no floppy will be attached. All files listed
|
||||
in this setting get placed into the root directory of the floppy and the
|
||||
floppy is attached as the first floppy device. Currently, no support exists
|
||||
for creating sub-directories on the floppy. Wildcard characters (*, ?, and
|
||||
[]) are allowed. Directory names are also allowed, which will add all the
|
||||
files found in the directory to the floppy.
|
||||
floppy is attached as the first floppy device. Currently, no support
|
||||
exists for creating sub-directories on the floppy. Wildcard characters
|
||||
(`*`, `?`, and `[]`) are allowed. Directory names are also allowed, which
|
||||
will add all the files found in the directory to the floppy.
|
||||
|
||||
- `floppy_dirs` (array of strings) - A list of directories to place onto the
|
||||
floppy disk recursively. This is similar to the `floppy_files` option
|
||||
except that the directory structure is preserved. This is useful for when
|
||||
your floppy disk includes drivers or if you just want to organize it's
|
||||
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
|
||||
The maximum summary size of all files in the listed directories are the
|
||||
same as in `floppy_files`.
|
||||
- `guest_additions_mode` (string) - If set to `attach` then attach and
|
||||
mount the ISO image specified in `guest_additions_path`. If set to
|
||||
`none` then guest additions are not attached and mounted; This is the
|
||||
default.
|
||||
|
||||
- `guest_additions_mode` (string) - How should guest additions be installed.
|
||||
If value `attach` then attach iso image with by specified by
|
||||
`guest_additions_path`. Otherwise guest additions is not installed.
|
||||
|
||||
- `guest_additions_path` (string) - The path to the iso image for guest
|
||||
- `guest_additions_path` (string) - The path to the ISO image for guest
|
||||
additions.
|
||||
|
||||
- `headless` (boolean) - Packer defaults to building Hyper-V virtual
|
||||
machines by launching a GUI that shows the console of the machine
|
||||
being built. When this value is set to true, the machine will start without
|
||||
a console.
|
||||
machines by launching a GUI that shows the console of the machine being
|
||||
built. When this value is set to true, the machine will start without a
|
||||
console.
|
||||
|
||||
- `http_directory` (string) - Path to a directory to serve using an HTTP
|
||||
server. The files in this directory will be available over HTTP that will
|
||||
be requestable from the virtual machine. This is useful for hosting
|
||||
kickstart files and so on. By default this is "", which means no HTTP
|
||||
server will be started. The address and port of the HTTP server will be
|
||||
available as variables in `boot_command`. This is covered in more detail
|
||||
below.
|
||||
- `http_directory` (string) - Path to a directory to serve using Packers
|
||||
inbuilt HTTP server. The files in this directory will be available
|
||||
over HTTP to the virtual machine. This is useful for hosting kickstart
|
||||
files and so on. By default this value is unset and the HTTP server is
|
||||
not started. The address and port of the HTTP server will be available
|
||||
as variables in `boot_command`. This is covered in more detail below.
|
||||
|
||||
- `http_port_min` and `http_port_max` (number) - These are the minimum and
|
||||
maximum port to use for the HTTP server started to serve the
|
||||
`http_directory`. Because Packer often runs in parallel, Packer will choose
|
||||
a randomly available port in this range to run the HTTP server. If you want
|
||||
to force the HTTP server to be on one port, make this minimum and maximum
|
||||
port the same. By default the values are 8000 and 9000, respectively.
|
||||
`http_directory`. Since Packer often runs in parallel, a randomly
|
||||
available port in this range will be repeatedly chosen until an
|
||||
available port is found. To force the HTTP server to use a specific
|
||||
port, set an identical value for `http_port_min` and `http_port_max`.
|
||||
By default the values are 8000 and 9000, respectively.
|
||||
|
||||
- `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO
|
||||
files are so large, this is required and Packer will verify it prior to
|
||||
booting a virtual machine with the ISO attached. The type of the checksum
|
||||
is specified with `iso_checksum_type`, documented below.
|
||||
- `iso_checksum_type` (string) - The algorithm to be used when computing
|
||||
the checksum of the file specified in `iso_checksum`. Currently, valid
|
||||
values are "none", "md5", "sha1", "sha256", or "sha512". Since the
|
||||
validity of ISO and virtual disk files are typically crucial to a
|
||||
successful build, Packer performs a check of any supplied media by
|
||||
default. While setting "none" will cause Packer to skip this check,
|
||||
corruption of large files such as ISOs and virtual hard drives can
|
||||
occur from time to time. As such, skipping this check is not
|
||||
recommended.
|
||||
|
||||
- `iso_checksum_type` (string) - The type of the checksum specified in
|
||||
`iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or
|
||||
"sha512" currently. While "none" will skip checksumming, this is not
|
||||
recommended since ISO files are generally large and corruption does happen
|
||||
from time to time.
|
||||
- `iso_checksum` (string) - The checksum for the ISO file or virtual
|
||||
hard drive file. The algorithm to use when computing the checksum is
|
||||
specified with `iso_checksum_type`.
|
||||
|
||||
- `iso_target_extension` (string) - The extension of the ISO file after
|
||||
download. This defaults to "iso".
|
||||
|
||||
- `iso_target_path` (string) - The path where the ISO should be saved after
|
||||
download. By default the ISO will be saved in the Packer cache
|
||||
directory with a hash of the original filename as its name.
|
||||
|
||||
- `iso_url` (string) - A URL to the ISO or VHD containing the installation
|
||||
image. This URL can be either an HTTP URL or a file URL (or path to
|
||||
a file). If this is an HTTP URL, Packer will download iso and cache it
|
||||
image. This URL can be either an HTTP URL or a file URL (or path to a
|
||||
file). If this is an HTTP URL, Packer will download iso and cache it
|
||||
between runs.
|
||||
|
||||
- `iso_urls` (array of strings) - Multiple URLs for the ISO or VHD to
|
||||
download. Packer will try these in order. If anything goes wrong attempting
|
||||
to download or while downloading a single URL, it will move on to the next.
|
||||
All URLs must point to the same file (same checksum). By default this is
|
||||
empty and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be
|
||||
specified.
|
||||
download. Packer will try these in order. If anything goes wrong
|
||||
attempting to download or while downloading a single URL, it will move on
|
||||
to the next. All URLs must point to the same file (same checksum). By
|
||||
default this is empty and `iso_url` is used. Only one of `iso_url` or
|
||||
`iso_urls` can be specified.
|
||||
|
||||
- `iso_target_extension` (string) - The extension of the iso file after
|
||||
download. This defaults to "iso".
|
||||
|
||||
- `iso_target_path` (string) - The path where the iso should be saved after
|
||||
download. By default will go in the packer cache, with a hash of the
|
||||
original filename as its name.
|
||||
- `mac_address` (string) - This allows a specific MAC address to be used on
|
||||
the default virtual network card. The MAC address must be a string with
|
||||
no delimiters, for example "0000deadbeef".
|
||||
|
||||
- `output_directory` (string) - This is the path to the directory where the
|
||||
resulting virtual machine will be created. This may be relative or
|
||||
|
|
@ -196,72 +209,80 @@ can be configured for this builder.
|
|||
running the builder. By default this is "output-BUILDNAME" where
|
||||
"BUILDNAME" is the name of the build.
|
||||
|
||||
- `ram_size` (number) - The size, in megabytes, of the ram to create for the
|
||||
- `ram_size` (number) - The amount, in megabytes, of RAM to assign to the
|
||||
VM. By default, this is 1 GB.
|
||||
|
||||
* `secondary_iso_images` (array of strings) - A list of iso paths to attached
|
||||
to a VM when it is booted. This is most useful for unattended Windows
|
||||
installs, which look for an `Autounattend.xml` file on removable media. By
|
||||
default, no secondary iso will be attached.
|
||||
- `secondary_iso_images` (array of strings) - A list of ISO paths to
|
||||
attach to a VM when it is booted. This is most useful for unattended
|
||||
Windows installs, which look for an `Autounattend.xml` file on removable
|
||||
media. By default, no secondary ISO will be attached.
|
||||
|
||||
- `secure_boot_template` (string) - The secure boot template to be
|
||||
configured. Valid values are "MicrosoftWindows" (Windows) or
|
||||
"MicrosoftUEFICertificateAuthority" (Linux). This only takes effect if
|
||||
`enable_secure_boot` is set to "true". This defaults to "MicrosoftWindows".
|
||||
|
||||
- `shutdown_command` (string) - The command to use to gracefully shut down
|
||||
the machine once all the provisioning is done. By default this is an empty
|
||||
string, which tells Packer to just forcefully shut down the machine unless
|
||||
a shutdown command takes place inside script so this may safely be omitted.
|
||||
If one or more scripts require a reboot it is suggested to leave this blank
|
||||
since reboots may fail and specify the final shutdown command in your last
|
||||
script.
|
||||
the machine once all provisioning is complete. By default this is an
|
||||
empty string, which tells Packer to just forcefully shut down the
|
||||
machine. This setting can be safely omitted if for example, a shutdown
|
||||
command to gracefully halt the machine is configured inside a
|
||||
provisioning script. If one or more scripts require a reboot it is
|
||||
suggested to leave this blank (since reboots may fail) and instead
|
||||
specify the final shutdown command in your last script.
|
||||
|
||||
- `shutdown_timeout` (string) - The amount of time to wait after executing
|
||||
the `shutdown_command` for the virtual machine to actually shut down. If it
|
||||
doesn't shut down in this time, it is an error. By default, the timeout is
|
||||
"5m", or five minutes.
|
||||
the `shutdown_command` for the virtual machine to actually shut down.
|
||||
If the machine doesn't shut down in this time it is considered an
|
||||
error. By default, the time out is "5m" (five minutes).
|
||||
|
||||
- `skip_compaction` (boolean) - If true skip compacting the hard disk for
|
||||
virtual machine when exporting. This defaults to false.
|
||||
- `skip_compaction` (boolean) - If `true` skip compacting the hard disk for
|
||||
the virtual machine when exporting. This defaults to `false`.
|
||||
|
||||
- `skip_export` (boolean) - If `true` Packer will skip the export of the
|
||||
VM. If you are interested only in the VHD/VHDX files, you can enable
|
||||
this option. This will create inline disks which improves the build
|
||||
performance. There will not be any copying of source VHDs to the temp
|
||||
directory. This defaults to `false`.
|
||||
|
||||
- `switch_name` (string) - The name of the switch to connect the virtual
|
||||
machine to. Be defaulting this to an empty string, Packer will try to
|
||||
determine the switch to use by looking for external switch that is up and
|
||||
running.
|
||||
machine to. By default, leaving this value unset will cause Packer to
|
||||
try and determine the switch to use by looking for an external switch
|
||||
that is up and running.
|
||||
|
||||
- `switch_vlan_id` (string) - This is the vlan of the virtual switch's
|
||||
network card. By default none is set. If none is set then a vlan is not set
|
||||
on the switch's network card. If this value is set it should match the vlan
|
||||
specified in by `vlan_id`.
|
||||
- `switch_vlan_id` (string) - This is the VLAN of the virtual switch's
|
||||
network card. By default none is set. If none is set then a VLAN is not
|
||||
set on the switch's network card. If this value is set it should match
|
||||
the VLAN specified in by `vlan_id`.
|
||||
|
||||
- `vlan_id` (string) - This is the vlan of the virtual machine's network card
|
||||
for the new virtual machine. By default none is set. If none is set then
|
||||
vlans are not set on the virtual machine's network card.
|
||||
- `vlan_id` (string) - This is the VLAN of the virtual machine's network
|
||||
card for the new virtual machine. By default none is set. If none is set
|
||||
then VLANs are not set on the virtual machine's network card.
|
||||
|
||||
- `mac_address` (string) - This allows a specific MAC address to be used on the
|
||||
default virtual network card. The MAC address must be a string with no
|
||||
delimiters, for example "0000deadbeef".
|
||||
|
||||
- `vm_name` (string) - This is the name of the virtual machine for the new
|
||||
virtual machine, without the file extension. By default this is
|
||||
"packer-BUILDNAME", where "BUILDNAME" is the name of the build.
|
||||
- `vm_name` (string) - This is the name of the new virtual machine,
|
||||
without the file extension. By default this is "packer-BUILDNAME",
|
||||
where "BUILDNAME" is the name of the build.
|
||||
|
||||
## Boot Command
|
||||
|
||||
The `boot_command` configuration is very important: it specifies the keys
|
||||
to type when the virtual machine is first booted in order to start the
|
||||
OS installer. This command is typed after `boot_wait`, which gives the
|
||||
virtual machine some time to actually load the ISO.
|
||||
The `boot_command` configuration is very important: it specifies the keys to
|
||||
type when the virtual machine is first booted in order to start the OS
|
||||
installer. This command is typed after `boot_wait`, which gives the virtual
|
||||
machine some time to actually load the ISO.
|
||||
|
||||
As documented above, the `boot_command` is an array of strings. The
|
||||
strings are all typed in sequence. It is an array only to improve readability
|
||||
within the template.
|
||||
As documented above, the `boot_command` is an array of strings. The strings
|
||||
are all typed in sequence. It is an array only to improve readability within
|
||||
the template.
|
||||
|
||||
The boot command is "typed" character for character over the virtual keyboard
|
||||
to the machine, simulating a human actually typing the keyboard.
|
||||
|
||||
<%= partial "partials/builders/boot-command" %>
|
||||
|
||||
Example boot command. This is actually a working boot command used to start
|
||||
an Ubuntu 12.04 installer:
|
||||
The example shown below is a working boot command used to start an Ubuntu
|
||||
12.04 installer:
|
||||
|
||||
```text
|
||||
``` json
|
||||
[
|
||||
"<esc><esc><enter><wait>",
|
||||
"/install/vmlinuz noapic ",
|
||||
|
|
@ -275,27 +296,34 @@ an Ubuntu 12.04 installer:
|
|||
]
|
||||
```
|
||||
|
||||
For more examples of various boot commands, see the sample projects from our
|
||||
[community templates page](/community-tools.html#templates).
|
||||
|
||||
## Integration Services
|
||||
|
||||
Packer will automatically attach the integration services iso as a dvd drive
|
||||
Packer will automatically attach the integration services ISO as a DVD drive
|
||||
for the version of Hyper-V that is running.
|
||||
|
||||
## Generation 1 vs Generation 2
|
||||
|
||||
Floppy drives are no longer supported by generation 2 machines. This requires you to
|
||||
take another approach when dealing with preseed or answer files. Two possible options
|
||||
are using virtual dvd drives or using the built in web server.
|
||||
Floppy drives are no longer supported by generation 2 machines. This requires
|
||||
you to take another approach when dealing with preseed or answer files. Two
|
||||
possible options are using virtual DVD drives or using Packers built in web
|
||||
server.
|
||||
|
||||
When dealing with Windows you need to enable UEFI drives for generation 2 virtual machines.
|
||||
When dealing with Windows you need to enable UEFI drives for generation 2
|
||||
virtual machines.
|
||||
|
||||
## Creating iso from directory
|
||||
## Creating an ISO From a Directory
|
||||
|
||||
Programs like mkisofs can be used to create an iso from a directory.
|
||||
There is a [windows version of mkisofs](http://opensourcepack.blogspot.co.uk/p/cdrtools.html).
|
||||
Programs like mkisofs can be used to create an ISO from a directory. There is
|
||||
a [windows version of
|
||||
mkisofs](http://opensourcepack.blogspot.co.uk/p/cdrtools.html) available.
|
||||
|
||||
Example powershell script. This is an actually working powershell script used to create a Windows answer iso:
|
||||
Below is a working PowerShell script that can be used to create a Windows
|
||||
answer ISO:
|
||||
|
||||
```text
|
||||
``` powershell
|
||||
$isoFolder = "answer-iso"
|
||||
if (test-path $isoFolder){
|
||||
remove-item $isoFolder -Force -Recurse
|
||||
|
|
@ -329,54 +357,56 @@ if (test-path $isoFolder){
|
|||
}
|
||||
```
|
||||
|
||||
|
||||
## Example For Windows Server 2012 R2 Generation 2
|
||||
|
||||
Packer config:
|
||||
|
||||
```javascript
|
||||
``` json
|
||||
{
|
||||
"builders": [
|
||||
{
|
||||
"vm_name":"windows2012r2",
|
||||
"type": "hyperv-iso",
|
||||
"disk_size": 61440,
|
||||
"floppy_files": [],
|
||||
"secondary_iso_images": [
|
||||
"./windows/windows-2012R2-serverdatacenter-amd64/answer.iso"
|
||||
],
|
||||
"http_directory": "./windows/common/http/",
|
||||
"boot_wait": "0s",
|
||||
"boot_command": [
|
||||
"a<wait>a<wait>a"
|
||||
],
|
||||
"iso_url": "http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO",
|
||||
"iso_checksum_type": "md5",
|
||||
"iso_checksum": "458ff91f8abc21b75cb544744bf92e6a",
|
||||
"communicator":"winrm",
|
||||
"winrm_username": "vagrant",
|
||||
"winrm_password": "vagrant",
|
||||
"winrm_timeout" : "4h",
|
||||
"shutdown_command": "f:\\run-sysprep.cmd",
|
||||
"ram_size": 4096,
|
||||
"cpu": 4,
|
||||
"generation": 2,
|
||||
"switch_name":"LAN",
|
||||
"enable_secure_boot":true
|
||||
}],
|
||||
"provisioners": [{
|
||||
"type": "powershell",
|
||||
"elevated_user":"vagrant",
|
||||
"elevated_password":"vagrant",
|
||||
"scripts": [
|
||||
"./windows/common/install-7zip.ps1",
|
||||
"./windows/common/install-chef.ps1",
|
||||
"./windows/common/compile-dotnet-assemblies.ps1",
|
||||
"./windows/common/cleanup.ps1",
|
||||
"./windows/common/ultradefrag.ps1",
|
||||
"./windows/common/sdelete.ps1"
|
||||
]
|
||||
}],
|
||||
{
|
||||
"vm_name":"windows2012r2",
|
||||
"type": "hyperv-iso",
|
||||
"disk_size": 61440,
|
||||
"floppy_files": [],
|
||||
"secondary_iso_images": [
|
||||
"./windows/windows-2012R2-serverdatacenter-amd64/answer.iso"
|
||||
],
|
||||
"http_directory": "./windows/common/http/",
|
||||
"boot_wait": "0s",
|
||||
"boot_command": [
|
||||
"a<wait>a<wait>a"
|
||||
],
|
||||
"iso_url": "http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO",
|
||||
"iso_checksum_type": "md5",
|
||||
"iso_checksum": "458ff91f8abc21b75cb544744bf92e6a",
|
||||
"communicator":"winrm",
|
||||
"winrm_username": "vagrant",
|
||||
"winrm_password": "vagrant",
|
||||
"winrm_timeout" : "4h",
|
||||
"shutdown_command": "f:\\run-sysprep.cmd",
|
||||
"ram_size": 4096,
|
||||
"cpu": 4,
|
||||
"generation": 2,
|
||||
"switch_name":"LAN",
|
||||
"enable_secure_boot":true
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "powershell",
|
||||
"elevated_user":"vagrant",
|
||||
"elevated_password":"vagrant",
|
||||
"scripts": [
|
||||
"./windows/common/install-7zip.ps1",
|
||||
"./windows/common/install-chef.ps1",
|
||||
"./windows/common/compile-dotnet-assemblies.ps1",
|
||||
"./windows/common/cleanup.ps1",
|
||||
"./windows/common/ultradefrag.ps1",
|
||||
"./windows/common/sdelete.ps1"
|
||||
]
|
||||
}
|
||||
],
|
||||
"post-processors": [
|
||||
{
|
||||
"type": "vagrant",
|
||||
|
|
@ -389,7 +419,7 @@ Packer config:
|
|||
|
||||
autounattend.xml:
|
||||
|
||||
```xml
|
||||
``` xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<unattend xmlns="urn:schemas-microsoft-com:unattend">
|
||||
<settings pass="windowsPE">
|
||||
|
|
@ -786,12 +816,11 @@ Finish Setup cache proxy during installation -->
|
|||
</settings>
|
||||
<cpi:offlineImage cpi:source="wim:c:/projects/baseboxes/9600.16384.winblue_rtm.130821-1623_x64fre_server_eval_en-us-irm_sss_x64free_en-us_dv5_slipstream/sources/install.wim#Windows Server 2012 R2 SERVERDATACENTER" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
|
||||
</unattend>
|
||||
|
||||
```
|
||||
|
||||
sysprep-unattend.xml:
|
||||
|
||||
```text
|
||||
``` xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<unattend xmlns="urn:schemas-microsoft-com:unattend">
|
||||
<settings pass="generalize">
|
||||
|
|
@ -855,12 +884,12 @@ Finish proxy after sysprep -->
|
|||
|
||||
## Example For Ubuntu Vivid Generation 2
|
||||
|
||||
If you are running Windows under virtualization, you may need to create
|
||||
a virtual switch with an `External` connection type.
|
||||
If you are running Windows under virtualization, you may need to create a
|
||||
virtual switch with an `External` connection type.
|
||||
|
||||
### Packer config:
|
||||
|
||||
```javascript
|
||||
``` json
|
||||
{
|
||||
"variables": {
|
||||
"vm_name": "ubuntu-xenial",
|
||||
|
|
@ -872,45 +901,46 @@ a virtual switch with an `External` connection type.
|
|||
"iso_checksum": "DE5EE8665048F009577763EFBF4A6F0558833E59"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"vm_name":"{{user `vm_name`}}",
|
||||
"type": "hyperv-iso",
|
||||
"disk_size": "{{user `disk_size`}}",
|
||||
"guest_additions_mode": "disable",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
"iso_checksum_type": "{{user `iso_checksum_type`}}",
|
||||
"iso_checksum": "{{user `iso_checksum`}}",
|
||||
"communicator":"ssh",
|
||||
"ssh_username": "packer",
|
||||
"ssh_password": "packer",
|
||||
"ssh_timeout" : "4h",
|
||||
"http_directory": "./",
|
||||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<esc><wait10><esc><esc><enter><wait>",
|
||||
"set gfxpayload=1024x768<enter>",
|
||||
"linux /install/vmlinuz ",
|
||||
"preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/hyperv-taliesins.cfg ",
|
||||
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
|
||||
"hostname={{.Name}} ",
|
||||
"fb=false debconf/frontend=noninteractive ",
|
||||
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
|
||||
"keyboard-configuration/variant=USA console-setup/ask_detect=false <enter>",
|
||||
"initrd /install/initrd.gz<enter>",
|
||||
"boot<enter>"
|
||||
],
|
||||
"shutdown_command": "echo 'packer' | sudo -S -E shutdown -P now",
|
||||
"ram_size": "{{user `ram_size`}}",
|
||||
"cpu": "{{user `cpu`}}",
|
||||
"generation": 2,
|
||||
"enable_secure_boot": false
|
||||
}]
|
||||
{
|
||||
"vm_name":"{{user `vm_name`}}",
|
||||
"type": "hyperv-iso",
|
||||
"disk_size": "{{user `disk_size`}}",
|
||||
"guest_additions_mode": "disable",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
"iso_checksum_type": "{{user `iso_checksum_type`}}",
|
||||
"iso_checksum": "{{user `iso_checksum`}}",
|
||||
"communicator":"ssh",
|
||||
"ssh_username": "packer",
|
||||
"ssh_password": "packer",
|
||||
"ssh_timeout" : "4h",
|
||||
"http_directory": "./",
|
||||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<esc><wait10><esc><esc><enter><wait>",
|
||||
"set gfxpayload=1024x768<enter>",
|
||||
"linux /install/vmlinuz ",
|
||||
"preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/hyperv-taliesins.cfg ",
|
||||
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
|
||||
"hostname={{.Name}} ",
|
||||
"fb=false debconf/frontend=noninteractive ",
|
||||
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
|
||||
"keyboard-configuration/variant=USA console-setup/ask_detect=false <enter>",
|
||||
"initrd /install/initrd.gz<enter>",
|
||||
"boot<enter>"
|
||||
],
|
||||
"shutdown_command": "echo 'packer' | sudo -S -E shutdown -P now",
|
||||
"ram_size": "{{user `ram_size`}}",
|
||||
"cpu": "{{user `cpu`}}",
|
||||
"generation": 2,
|
||||
"enable_secure_boot": false
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### preseed.cfg:
|
||||
|
||||
```text
|
||||
``` text
|
||||
## Options to set on the command line
|
||||
d-i debian-installer/locale string en_US.utf8
|
||||
d-i console-setup/ask_detect boolean false
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ The file provisioner can upload both single files and complete directories.
|
|||
|
||||
## Configuration Reference
|
||||
|
||||
The available configuration options are listed below. All elements are required.
|
||||
The available configuration options are listed below.
|
||||
|
||||
### Required
|
||||
|
||||
- `source` (string) - The path to a local file or directory to upload to
|
||||
the machine. The path can be absolute or relative. If it is relative, it is
|
||||
|
|
@ -48,6 +50,8 @@ The available configuration options are listed below. All elements are required.
|
|||
"upload". If it is set to "download" then the file "source" in the machine
|
||||
will be downloaded locally to "destination"
|
||||
|
||||
### Optional
|
||||
|
||||
- `generated` (boolean) - For advanced users only. If true, check the file
|
||||
existence only before uploading, rather than upon pre-build validation.
|
||||
This allows to upload files created on-the-fly. This defaults to false. We
|
||||
|
|
|
|||
|
|
@ -176,7 +176,10 @@ variable values. Assuming this file is in `variables.json`, we can build our
|
|||
template using the following command:
|
||||
|
||||
``` text
|
||||
On Linux :
|
||||
$ packer build -var-file=variables.json template.json
|
||||
On Windows :
|
||||
packer build -var-file variables.json template.json
|
||||
```
|
||||
|
||||
The `-var-file` flag can be specified multiple times and variables from multiple
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ in your `PATH`.
|
|||
1. Clone the Packer repository from GitHub into your `GOPATH`:
|
||||
|
||||
``` shell
|
||||
$ mkdir -p $(go enc GOPATH)/src/github.com/hashicorp && cd $_
|
||||
$ mkdir -p $(go env GOPATH)/src/github.com/hashicorp && cd $_
|
||||
$ git clone https://github.com/hashicorp/packer.git
|
||||
$ cd packer
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in a new issue