diff --git a/client/consul_template.go b/client/consul_template.go index 1a656a3ea656..e3f534f7eefd 100644 --- a/client/consul_template.go +++ b/client/consul_template.go @@ -350,7 +350,7 @@ func templateRunner(tmpls []*structs.Template, config *config.Config, } // Set Nomad's environment variables - runner.Env = taskEnv.Build().EnvMap() + runner.Env = taskEnv.Build().EnvMapAll() // Build the lookup idMap := runner.TemplateConfigMapping() diff --git a/client/driver/env/env.go b/client/driver/env/env.go index c2aacd38332d..c96a724f43d4 100644 --- a/client/driver/env/env.go +++ b/client/driver/env/env.go @@ -287,6 +287,20 @@ func (t *TaskEnvironment) EnvMap() map[string]string { return m } +// EnvMapAll returns the environment variables that will be set as well as node +// meta/attrs in the map. This is appropriate for interpolation. +func (t *TaskEnvironment) EnvMapAll() map[string]string { + m := make(map[string]string, len(t.TaskEnv)) + for k, v := range t.TaskEnv { + m[k] = v + } + for k, v := range t.NodeValues { + m[k] = v + } + + return m +} + // Builder methods to build the TaskEnvironment func (t *TaskEnvironment) SetAllocDir(dir string) *TaskEnvironment { t.AllocDir = dir diff --git a/website/source/docs/job-specification/template.html.md b/website/source/docs/job-specification/template.html.md index 88fa109c70ec..0c3588a49159 100644 --- a/website/source/docs/job-specification/template.html.md +++ b/website/source/docs/job-specification/template.html.md @@ -41,8 +41,9 @@ job "docs" { ``` Nomad utilizes a tool called [Consul Template][ct]. Since Nomad v0.5.3, the -template can reference [Nomad's runtime environment variables][env]. For a full -list of the API template functions, please refer to the [Consul Template +template can reference [Nomad's runtime environment variables][env]. Since Nomad +v0.5.6, the template can reference [Node attributes and metadata][nodevars]. For +a full list of the API template functions, please refer to the [Consul Template README][ct]. ## `template` Parameters @@ -137,7 +138,24 @@ template { } ``` -### Client Configuration +### Node Variables + +As of Nomad v0.5.6 it is possible to access the Node's attributes and metadata. + +```hcl +template { + data = <