Merge pull request #4694 from andreychernih/ansible-error-message
More verbose error message when ansible-playbook fails
This commit is contained in:
commit
cc4efa09b0
|
@ -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+]*)`)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
exit 1
|
Loading…
Reference in New Issue