diff --git a/packer/config_template_test.go b/packer/config_template_test.go index 4c4864cda..817868bbf 100644 --- a/packer/config_template_test.go +++ b/packer/config_template_test.go @@ -5,6 +5,7 @@ import ( "strconv" "testing" "time" + "encoding/json" ) func TestConfigTemplateProcess_timestamp(t *testing.T) { @@ -47,6 +48,39 @@ func TestConfigTemplateProcess_user(t *testing.T) { } } +func TestJsonTemplateProcess_user(t *testing.T) { + tpl, err := NewConfigTemplate() + if err != nil { + t.Fatalf("err: %s", err) + } + + tpl.UserVars["foo"] = "bar" + jsonData := make(map[string]interface{}) + jsonData["key"] = map[string]string{ + "key1": "{{user `foo`}}", + } + jsonBytes, err := json.MarshalIndent(jsonData, "", " ") + if err != nil { + t.Fatalf("err: %s", err) + } + var jsonString = string(jsonBytes) + + result, err := tpl.Process(jsonString, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + var dat map[string]map[string]interface{} + if err := json.Unmarshal([]byte(result), &dat); err != nil { + t.Fatalf("err: %s", err) + } + + if dat["key"]["key1"] != "bar" { + t.Fatalf("found %s instead", dat["key"]["key1"]) + } + +} + + func TestConfigTemplateValidate(t *testing.T) { tpl, err := NewConfigTemplate() if err != nil { diff --git a/provisioner/chef-solo/provisioner.go b/provisioner/chef-solo/provisioner.go index e8bf05e25..05c1836a2 100644 --- a/provisioner/chef-solo/provisioner.go +++ b/provisioner/chef-solo/provisioner.go @@ -95,7 +95,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { sliceTemplates := map[string][]string{ "cookbook_paths": p.config.CookbookPaths, "remote_cookbook_paths": p.config.RemoteCookbookPaths, - "run_list": p.config.RunList, } for n, slice := range sliceTemplates { @@ -236,10 +235,17 @@ func (p *Provisioner) createJson(ui packer.Ui, comm packer.Communicator) (string if err != nil { return "", err } + var jsonString = string(jsonBytes) + println(jsonString) + + result, err := p.config.tpl.Process(jsonString, nil) + if err != nil { + return "", err + } // Upload the bytes remotePath := filepath.Join(p.config.StagingDir, "node.json") - if err := comm.Upload(remotePath, bytes.NewReader(jsonBytes)); err != nil { + if err := comm.Upload(remotePath, bytes.NewReader([]byte(result))); err != nil { return "", err }