From c261428c4f7146247f8fc533f08507dfd90a1136 Mon Sep 17 00:00:00 2001 From: Peter Pribula Date: Thu, 25 Apr 2019 11:43:12 +0200 Subject: [PATCH] ProxMox builder ssh communicator uses ssh_host from builder config when present --- builder/proxmox/builder.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/builder/proxmox/builder.go b/builder/proxmox/builder.go index 59e271380..3e073a35e 100644 --- a/builder/proxmox/builder.go +++ b/builder/proxmox/builder.go @@ -71,7 +71,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack }, &communicator.StepConnect{ Config: &b.config.Comm, - Host: getVMIP, + Host: commHost(b.config.Comm.SSHHost), SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, @@ -98,6 +98,18 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack return artifact, nil } +// Returns ssh_host config parameter when set, otherwise gets the host IP from running VM +func commHost(sshHost string) func(state multistep.StateBag) (string, error) { + if sshHost != "" { + return func(state multistep.StateBag) (string, error) { + return sshHost, nil + } + } + return getVMIP +} + +// Reads the first non-loopback interface's IP address from the VM. +// qemu-guest-agent package must be installed on the VM func getVMIP(state multistep.StateBag) (string, error) { c := state.Get("proxmoxClient").(*proxmox.Client) vmRef := state.Get("vmRef").(*proxmox.VmRef)