From b76a116823b41b002bd9df1744c3068486bbfd9b Mon Sep 17 00:00:00 2001 From: Jake Good Date: Thu, 12 Dec 2013 14:13:23 -0600 Subject: [PATCH] Fix Ansible-local provisioner configuration check for 'playbook_paths' as it was checking for files, not paths --- provisioner/ansible-local/provisioner.go | 2 +- provisioner/ansible-local/provisioner_test.go | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/provisioner/ansible-local/provisioner.go b/provisioner/ansible-local/provisioner.go index cde290125..860527bbb 100644 --- a/provisioner/ansible-local/provisioner.go +++ b/provisioner/ansible-local/provisioner.go @@ -72,7 +72,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { errs = packer.MultiErrorAppend(errs, err) } for _, path := range p.config.PlaybookPaths { - err := validateFileConfig(path, "playbook_paths", false) + err := validateDirConfig(path, "playbook_paths") if err != nil { errs = packer.MultiErrorAppend(errs, err) } diff --git a/provisioner/ansible-local/provisioner_test.go b/provisioner/ansible-local/provisioner_test.go index 5a4b780ef..21f83affd 100644 --- a/provisioner/ansible-local/provisioner_test.go +++ b/provisioner/ansible-local/provisioner_test.go @@ -69,3 +69,55 @@ func TestProvisionerPrepare_PlaybookFile(t *testing.T) { t.Fatalf("err: %s", err) } } + +func TestProvisionerPrepare_Dirs(t *testing.T) { + var p Provisioner + config := testConfig() + + err := p.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + config["playbook_file"] = "" + err = p.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + playbook_file, err := ioutil.TempFile("", "playbook") + if err != nil { + t.Fatalf("err: %s", err) + } + defer os.Remove(playbook_file.Name()) + + config["playbook_file"] = playbook_file.Name() + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + config["playbook_paths"] = []string{playbook_file.Name()} + err = p.Prepare(config) + if err == nil { + t.Fatal("should error if playbook paths is not a dir") + } + + config["playbook_paths"] = []string{os.TempDir()} + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + config["role_paths"] = []string{playbook_file.Name()} + err = p.Prepare(config) + if err == nil { + t.Fatal("should error if role paths is not a dir") + } + + config["role_paths"] = []string{os.TempDir()} + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } +}