More verbose error message when ansible-playbook fails
I've spent 1 hour today debugging why packer does not want to work with ansible. It turns out `ansible-playbook` command was returning non-zero exit status because of the file system permission problem. Output before change: % packer build rabbitmq.json amazon-ebs output will be in this color. 1 error(s) occurred: * exit status 1 Output after change: amazon-ebs output will be in this color. 1 error(s) occurred: * Error running "ansible-playbook --version": exit status 1
This commit is contained in:
parent
fa0ef21b1b
commit
7548024720
|
@ -144,7 +144,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
func (p *Provisioner) getVersion() error {
|
func (p *Provisioner) getVersion() error {
|
||||||
out, err := exec.Command(p.config.Command, "--version").Output()
|
out, err := exec.Command(p.config.Command, "--version").Output()
|
||||||
if err != nil {
|
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+]*)`)
|
versionRe := regexp.MustCompile(`\w (\d+\.\d+[.\d+]*)`)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mitchellh/packer/packer"
|
"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) {
|
func TestAnsibleLongMessages(t *testing.T) {
|
||||||
if os.Getenv("PACKER_ACC") == "" {
|
if os.Getenv("PACKER_ACC") == "" {
|
||||||
t.Skip("This test is only run with PACKER_ACC=1 and it requires Ansible to be installed")
|
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