only set PACKER_HTTP_ADDR if a server is listening

This commit is contained in:
Matthew Hooker 2017-01-17 17:17:36 -08:00
parent 6563eb213c
commit 480398c3d2
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 13 additions and 4 deletions

View File

@ -338,7 +338,10 @@ 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()
httpAddr := common.GetHTTPAddr()
if httpAddr != "" {
envVars["PACKER_HTTP_ADDR"] = httpAddr
}
// Split vars into key/value components
for _, envVar := range p.config.Vars {

View File

@ -232,9 +232,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
envVars := make([]string, len(p.config.Vars)+3)
envVars[0] = fmt.Sprintf("PACKER_BUILD_NAME='%s'", p.config.PackerBuildName)
envVars[1] = fmt.Sprintf("PACKER_BUILDER_TYPE='%s'", p.config.PackerBuilderType)
envVars[2] = fmt.Sprintf("PACKER_HTTP_ADDR=%s", common.GetHTTPAddr())
copy(envVars[3:], p.config.Vars)
copy(envVars[2:], p.config.Vars)
httpAddr := common.GetHTTPAddr()
if httpAddr != "" {
envVars = append(envVars, fmt.Sprintf("PACKER_HTTP_ADDR=%s", common.GetHTTPAddr()))
}
for _, path := range scripts {
ui.Say(fmt.Sprintf("Provisioning with shell script: %s", path))

View File

@ -294,7 +294,10 @@ 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()
httpAddr := common.GetHTTPAddr()
if httpAddr != "" {
envVars["PACKER_HTTP_ADDR"] = httpAddr
}
// Split vars into key/value components
for _, envVar := range p.config.Vars {