diff --git a/api/tasks.go b/api/tasks.go index d64bc7bb247..cb6cdd667f2 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -181,6 +181,8 @@ type Template struct { ChangeSignal string Splay time.Duration Perms string + LeftDelim *string + RightDelim *string } type Vault struct { diff --git a/client/consul_template.go b/client/consul_template.go index 0b00a070d7b..1a656a3ea65 100644 --- a/client/consul_template.go +++ b/client/consul_template.go @@ -394,6 +394,8 @@ func parseTemplateConfigs(tmpls []*structs.Template, taskDir string, ct.Source = &src ct.Destination = &dest ct.Contents = &tmpl.EmbeddedTmpl + ct.LeftDelim = &tmpl.LeftDelim + ct.RightDelim = &tmpl.RightDelim // Set the permissions if tmpl.Perms != "" { diff --git a/jobspec/parse.go b/jobspec/parse.go index 628e177873b..a35900dfbf2 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -859,7 +859,9 @@ func parseTemplates(result *[]*structs.Template, list *ast.ObjectList) error { "change_signal", "data", "destination", + "left_delimiter", "perms", + "right_delimiter", "source", "splay", } diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 068618d9657..acf53b45eb0 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -179,6 +179,8 @@ func TestParse(t *testing.T) { ChangeSignal: "", Splay: 5 * time.Second, Perms: "777", + LeftDelim: "--", + RightDelim: "__", }, }, Leader: true, diff --git a/jobspec/test-fixtures/basic.hcl b/jobspec/test-fixtures/basic.hcl index 72870620f9f..fe2617f5178 100644 --- a/jobspec/test-fixtures/basic.hcl +++ b/jobspec/test-fixtures/basic.hcl @@ -147,6 +147,8 @@ job "binstore-storagelocker" { source = "bar" destination = "bar" perms = "777" + left_delimiter = "--" + right_delimiter = "__" } } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index c75246a09d4..7433f4302f8 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2611,6 +2611,11 @@ type Template struct { // Perms is the permission the file should be written out with. Perms string `mapstructure:"perms"` + + // LeftDelim and RightDelim are optional configurations to control what + // delimiter is utilized when parsing the template. + LeftDelim string `mapstructure:"left_delimiter"` + RightDelim string `mapstructure:"right_delimiter"` } // DefaultTemplate returns a default template. diff --git a/website/source/docs/http/json-jobs.html.md b/website/source/docs/http/json-jobs.html.md index 48f600925b9..6364f4b76ec 100644 --- a/website/source/docs/http/json-jobs.html.md +++ b/website/source/docs/http/json-jobs.html.md @@ -661,19 +661,6 @@ README][ct]. `Template` object supports following attributes: -* `SourcePath` - Specifies the path to the template to be rendered. `SourcePath` - is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched - using an [`Artifact`](#artifact) resource. The template must exist on the - machine prior to starting the task; it is not possible to reference a template - inside of a Docker container, for example. - -* `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath` - or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller - templates, but we recommend using `SourcePath` for larger templates. - -* `DestPath` - Specifies the location where the resulting template should be - rendered, relative to the task directory. - - `ChangeMode` - Specifies the behavior Nomad should take if the rendered template changes. The default value is `"restart"`. The possible values are: @@ -685,9 +672,30 @@ README][ct]. "SIGUSR1" or "SIGINT". This option is required if the `ChangeMode` is `signal`. -* `perms` - Specifies the rendered template's permissions. File permissions are +* `DestPath` - Specifies the location where the resulting template should be + rendered, relative to the task directory. + +* `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath` + or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller + templates, but we recommend using `SourcePath` for larger templates. + +* `LeftDelim` - Specifies the left delimiter to use in the template. The default + is "{{" for some templates, it may be easier to use a different delimiter that + does not conflict with the output file itself. + +* `Perms` - Specifies the rendered template's permissions. File permissions are given as octal of the unix file permissions rwxrwxrwx. +* `RightDelim` - Specifies the right delimiter to use in the template. The default + is "}}" for some templates, it may be easier to use a different delimiter that + does not conflict with the output file itself. + +* `SourcePath` - Specifies the path to the template to be rendered. `SourcePath` + is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched + using an [`Artifact`](#artifact) resource. The template must exist on the + machine prior to starting the task; it is not possible to reference a template + inside of a Docker container, for example. + * `Splay` - Specifies a random amount of time to wait between 0ms and the given splay value before invoking the change mode. Should be specified in nanoseconds. diff --git a/website/source/docs/job-specification/template.html.md b/website/source/docs/job-specification/template.html.md index ee567d36773..b2a41ae1ce5 100644 --- a/website/source/docs/job-specification/template.html.md +++ b/website/source/docs/job-specification/template.html.md @@ -65,9 +65,17 @@ README][ct]. - `destination` `(string: )` - Specifies the location where the resulting template should be rendered, relative to the task directory. +* `left_delimiter` `(string: "{{")` - Specifies the left delimiter to use in the + template. The default is "{{" for some templates, it may be easier to use a + different delimiter that does not conflict with the output file itself. + - `perms` `(string: "666")` - Specifies the rendered template's permissions. File permissions are given as octal of the unix file permissions rwxrwxrwx. +* `right_delimiter` `(string: "}}")` - Specifies the right delimiter to use in the + template. The default is "}}" for some templates, it may be easier to use a + different delimiter that does not conflict with the output file itself. + - `source` `(string: "")` - Specifies the path to the template to be rendered. One of `source` or `data` must be specified, but not both. This source can optionally be fetched using an [`artifact`][artifact] resource. This template