diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index b57edd829..642d99bd8 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -144,7 +144,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { func (p *Provisioner) getVersion() error { out, err := exec.Command(p.config.Command, "--version").Output() if err != nil { - return err + return fmt.Errorf( + "Error running \"%s --version\": %s", p.config.Command, err.Error()) } versionRe := regexp.MustCompile(`\w (\d+\.\d+[.\d+]*)`) diff --git a/provisioner/ansible/provisioner_test.go b/provisioner/ansible/provisioner_test.go index 12a0f4e9b..13042c5e1 100644 --- a/provisioner/ansible/provisioner_test.go +++ b/provisioner/ansible/provisioner_test.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "path" + "strings" "testing" "github.com/mitchellh/packer/packer" @@ -258,6 +259,18 @@ func TestAnsibleGetVersion(t *testing.T) { } } +func TestAnsibleGetVersionError(t *testing.T) { + var p Provisioner + p.config.Command = "./test-fixtures/exit1" + err := p.getVersion() + if err == nil { + t.Fatal("Should return error") + } + if !strings.Contains(err.Error(), "./test-fixtures/exit1 --version") { + t.Fatal("Error message should include command name") + } +} + func TestAnsibleLongMessages(t *testing.T) { if os.Getenv("PACKER_ACC") == "" { t.Skip("This test is only run with PACKER_ACC=1 and it requires Ansible to be installed") diff --git a/provisioner/ansible/test-fixtures/exit1 b/provisioner/ansible/test-fixtures/exit1 new file mode 100755 index 000000000..2bb8d868b --- /dev/null +++ b/provisioner/ansible/test-fixtures/exit1 @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 1