From 6563eb213c2338ba8919d04ab3a6dd1e1004319b Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 17 Jan 2017 17:07:36 -0800 Subject: [PATCH] Document. add to windows-shell and powershell --- provisioner/powershell/provisioner.go | 7 +----- provisioner/windows-shell/provisioner.go | 8 +------ .../docs/provisioners/powershell.html.md | 22 +++++++++++++++++++ .../source/docs/provisioners/shell.html.md | 7 ++++++ .../docs/provisioners/windows-shell.html.md | 22 +++++++++++++++++++ 5 files changed, 53 insertions(+), 13 deletions(-) diff --git a/provisioner/powershell/provisioner.go b/provisioner/powershell/provisioner.go index 3f0f0b9dd..b9901c62e 100644 --- a/provisioner/powershell/provisioner.go +++ b/provisioner/powershell/provisioner.go @@ -234,12 +234,6 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { scripts := make([]string, len(p.config.Scripts)) copy(scripts, p.config.Scripts) - // Build our variables up by adding in the build name and builder type - envVars := make([]string, len(p.config.Vars)+2) - envVars[0] = "PACKER_BUILD_NAME=" + p.config.PackerBuildName - envVars[1] = "PACKER_BUILDER_TYPE=" + p.config.PackerBuilderType - copy(envVars, p.config.Vars) - if p.config.Inline != nil { temp, err := extractScript(p) if err != nil { @@ -344,6 +338,7 @@ func (p *Provisioner) createFlattenedEnvVars(elevated bool) (flattened string, e // Always available Packer provided env vars envVars["PACKER_BUILD_NAME"] = p.config.PackerBuildName envVars["PACKER_BUILDER_TYPE"] = p.config.PackerBuilderType + envVars["PACKER_HTTP_ADDR"] = common.GetHTTPAddr() // Split vars into key/value components for _, envVar := range p.config.Vars { diff --git a/provisioner/windows-shell/provisioner.go b/provisioner/windows-shell/provisioner.go index 6f58bcb9e..673fb0a2b 100644 --- a/provisioner/windows-shell/provisioner.go +++ b/provisioner/windows-shell/provisioner.go @@ -188,13 +188,6 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { scripts := make([]string, len(p.config.Scripts)) copy(scripts, p.config.Scripts) - // Build our variables up by adding in the build name and builder type - envVars := make([]string, len(p.config.Vars)+2) - envVars[0] = "PACKER_BUILD_NAME=" + p.config.PackerBuildName - envVars[1] = "PACKER_BUILDER_TYPE=" + p.config.PackerBuilderType - - copy(envVars, p.config.Vars) - if p.config.Inline != nil { temp, err := extractScript(p) if err != nil { @@ -301,6 +294,7 @@ func (p *Provisioner) createFlattenedEnvVars() (flattened string, err error) { // Always available Packer provided env vars envVars["PACKER_BUILD_NAME"] = p.config.PackerBuildName envVars["PACKER_BUILDER_TYPE"] = p.config.PackerBuilderType + envVars["PACKER_HTTP_ADDR"] = common.GetHTTPAddr() // Split vars into key/value components for _, envVar := range p.config.Vars { diff --git a/website/source/docs/provisioners/powershell.html.md b/website/source/docs/provisioners/powershell.html.md index 245b78e76..95f63b9de 100644 --- a/website/source/docs/provisioners/powershell.html.md +++ b/website/source/docs/provisioners/powershell.html.md @@ -82,3 +82,25 @@ Optional parameters: - `valid_exit_codes` (list of ints) - Valid exit codes for the script. By default this is just 0. + + +## Default Environmental Variables + +In addition to being able to specify custom environmental variables using the +`environment_vars` configuration, the provisioner automatically defines certain +commonly useful environmental variables: + +- `PACKER_BUILD_NAME` is set to the name of the build that Packer is running. + This is most useful when Packer is making multiple builds and you want to + distinguish them slightly from a common provisioning script. + +- `PACKER_BUILDER_TYPE` is the type of the builder that was used to create the + machine that the script is running on. This is useful if you want to run + only certain parts of the script on systems built with certain builders. + +- `PACKER_HTTP_ADDR` If using a builder that provides an http server for file + transfer (such as hyperv, parallels, qemu, virtualbox, and vmware), this + will be set to the address. You can use this address in your provisioner to + download large files over http. This may be useful if you're experiencing + slower speeds using the default file provisioner. A file provisioner using + the `winrm` communicator may experience these types of difficulties. diff --git a/website/source/docs/provisioners/shell.html.md b/website/source/docs/provisioners/shell.html.md index 4d1699342..8012e62fb 100644 --- a/website/source/docs/provisioners/shell.html.md +++ b/website/source/docs/provisioners/shell.html.md @@ -149,6 +149,13 @@ commonly useful environmental variables: machine that the script is running on. This is useful if you want to run only certain parts of the script on systems built with certain builders. +- `PACKER_HTTP_ADDR` If using a builder that provides an http server for file + transfer (such as hyperv, parallels, qemu, virtualbox, and vmware), this + will be set to the address. You can use this address in your provisioner to + download large files over http. This may be useful if you're experiencing + slower speeds using the default file provisioner. A file provisioner using + the `winrm` communicator may experience these types of difficulties. + ## Handling Reboots Provisioning sometimes involves restarts, usually when updating the operating diff --git a/website/source/docs/provisioners/windows-shell.html.md b/website/source/docs/provisioners/windows-shell.html.md index a3d80a63a..295fcfba0 100644 --- a/website/source/docs/provisioners/windows-shell.html.md +++ b/website/source/docs/provisioners/windows-shell.html.md @@ -73,3 +73,25 @@ Optional parameters: exists in order to deal with times when SSH may restart, such as a system reboot. Set this to a higher value if reboots take a longer amount of time. + + +## Default Environmental Variables + +In addition to being able to specify custom environmental variables using the +`environment_vars` configuration, the provisioner automatically defines certain +commonly useful environmental variables: + +- `PACKER_BUILD_NAME` is set to the name of the build that Packer is running. + This is most useful when Packer is making multiple builds and you want to + distinguish them slightly from a common provisioning script. + +- `PACKER_BUILDER_TYPE` is the type of the builder that was used to create the + machine that the script is running on. This is useful if you want to run + only certain parts of the script on systems built with certain builders. + +- `PACKER_HTTP_ADDR` If using a builder that provides an http server for file + transfer (such as hyperv, parallels, qemu, virtualbox, and vmware), this + will be set to the address. You can use this address in your provisioner to + download large files over http. This may be useful if you're experiencing + slower speeds using the default file provisioner. A file provisioner using + the `winrm` communicator may experience these types of difficulties.