github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/website/source/docs/jobspec/interpreted.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Interpreted Variables" 4 sidebar_current: "docs-jobspec-interpreted" 5 description: |- 6 Learn about the Nomad's interpreted variables. 7 --- 8 # Interpreted Variables 9 10 Nomad support interpreting two classes of variables, node attributes and runtime 11 environment variables. Node attributes are interpretable in constraints, task 12 environment variables and certain driver fields. Runtime environment variables 13 are not interpretable in constraints because they are only defined once the 14 scheduler has placed them on a particular node. 15 16 The syntax for interpreting variables is `${variable}`. An example and a 17 comprehensive list of interpretable fields can be seen below: 18 19 ``` 20 task "demo" { 21 driver = "docker" 22 23 # Drivers support interpreting node attributes and runtime environment 24 # variables 25 config { 26 image = "my-app" 27 28 # Interpret runtime variables to inject the address to bind to and the 29 # location to write logs to. 30 args = ["--bind=${NOMAD_ADDR_RPC}", "--logs=${NOMAD_ALLOC_DIR}/logs"] 31 32 port_map { 33 RPC = 6379 34 } 35 } 36 37 # Constraints only support node attributes as runtime environment variables 38 # are only defined after the task is placed on a node. 39 constraint { 40 attribute = "${attr.kernel.name}" 41 value = "linux" 42 } 43 44 # Environment variables are interpreted and can contain both runtime and 45 # node attributes. 46 env { 47 "DC" = "Running on datacenter ${node.datacenter}" 48 "VERSION" = "Version ${NOMAD_META_VERSION}" 49 } 50 51 # Meta keys are also interpretable. 52 meta { 53 VERSION = "v0.3" 54 } 55 } 56 ``` 57 58 ## Node Variables <a id="interpreted_node_vars"></a> 59 60 Below is a full listing of node attributes that are interpretable. These 61 attributes are Interpreted by __both__ constraints and within the task and 62 driver. 63 64 <table class="table table-bordered table-striped"> 65 <tr> 66 <th>Variable</th> 67 <th>Description</th> 68 <th>Example</th> 69 </tr> 70 <tr> 71 <td>${node.unique.id}</td> 72 <td>The 36 character unique client node identifier</td> 73 <td>9afa5da1-8f39-25a2-48dc-ba31fd7c0023</td> 74 </tr> 75 <tr> 76 <td>${node.datacenter}</td> 77 <td>The client node's datacenter</td> 78 <td>dc1</td> 79 </tr> 80 <tr> 81 <td>${node.unique.name}</td> 82 <td>The client node's name</td> 83 <td>nomad-client-10-1-2-4</td> 84 </tr> 85 <tr> 86 <td>${node.class}</td> 87 <td>The client node's class</td> 88 <td>linux-64bit</td> 89 </tr> 90 <tr> 91 <td>${attr."key"}</td> 92 <td>The attribute given by `key` on the client node.</td> 93 <td>platform.aws.instance-type:r3.large</td> 94 </tr> 95 <tr> 96 <td>${meta."key"}</td> 97 <td>The metadata value given by `key` on the client node.</td> 98 <td></td> 99 </tr> 100 </table> 101 102 Below is a table documenting common node attributes: 103 104 <table class="table table-bordered table-striped"> 105 <tr> 106 <th>Attribute</th> 107 <th>Description</th> 108 </tr> 109 <tr> 110 <td>arch</td> 111 <td>CPU architecture of the client. Examples: `amd64`, `386`</td> 112 </tr> 113 <tr> 114 <td>consul.datacenter</td> 115 <td>The Consul datacenter of the client node if Consul found</td> 116 </tr> 117 <tr> 118 <td>cpu.numcores</td> 119 <td>Number of CPU cores on the client</td> 120 </tr> 121 <tr> 122 <td>driver."key"</td> 123 <td>See the [task drivers](/docs/drivers/index.html) for attribute documentation</td> 124 </tr> 125 <tr> 126 <td>hostname</td> 127 <td>Hostname of the client</td> 128 </tr> 129 <tr> 130 <td>kernel.name</td> 131 <td>Kernel of the client. Examples: `linux`, `darwin`</td> 132 </tr> 133 <tr> 134 <td>kernel.version</td> 135 <td>Version of the client kernel. Examples: `3.19.0-25-generic`, `15.0.0`</td> 136 </tr> 137 <tr> 138 <td>platform.aws.ami-id</td> 139 <td>On EC2, the AMI ID of the client node</td> 140 </tr> 141 <tr> 142 <td>platform.aws.instance-type</td> 143 <td>On EC2, the instance type of the client node</td> 144 </tr> 145 <tr> 146 <td>os.name</td> 147 <td>Operating system of the client. Examples: `ubuntu`, `windows`, `darwin`</td> 148 </tr> 149 <tr> 150 <td>os.version</td> 151 <td>Version of the client OS</td> 152 </tr> 153 </table> 154 155 ## Environment Variables <a id="interpreted_env_vars"></a> 156 157 The following are runtime environment variables that describe the environment 158 the task is running in. These are only defined once the task has been placed on 159 a particular node and as such can not be used in constraints. 160 161 <table class="table table-bordered table-striped"> 162 <tr> 163 <th>Variable</th> 164 <th>Description</th> 165 </tr> 166 <tr> 167 <td>${NOMAD_ALLOC_DIR}</td> 168 <td>The path to the shared `alloc/` directory. See 169 [here](/docs/jobspec/environment.html#task_dir) for more 170 information.</td> 171 </tr> 172 <tr> 173 <td>${NOMAD_TASK_DIR}</td> 174 <td>The path to the task `local/` directory. See 175 [here](/docs/jobspec/environment.html#task_dir) for more 176 information.</td> 177 </tr> 178 <tr> 179 <td>${NOMAD_MEMORY_LIMIT}</td> 180 <td>The memory limit in MBits for the task</td> 181 </tr> 182 <tr> 183 <td>${NOMAD_CPU_LIMIT}</td> 184 <td>The CPU limit in MHz for the task</td> 185 </tr> 186 <tr> 187 <td>${NOMAD_ALLOC_ID}</td> 188 <td>The allocation ID of the task</td> 189 </tr> 190 <tr> 191 <td>${NOMAD_ALLOC_NAME}</td> 192 <td>The allocation name of the task</td> 193 </tr> 194 <tr> 195 <td>${NOMAD_ALLOC_INDEX}</td> 196 <td>The allocation index; useful to distinguish instances of task groups</td> 197 </tr> 198 <tr> 199 <td>${NOMAD_TASK_NAME}</td> 200 <td>The task's name</td> 201 </tr> 202 <tr> 203 <td>${NOMAD_IP_"label"}</td> 204 <td>The IP for the given port `label`. See 205 [here](/docs/jobspec/networking.html) for more information.</td> 206 </tr> 207 <tr> 208 <td>${NOMAD_PORT_"label"}</td> 209 <td>The port for the port `label`. See [here](/docs/jobspec/networking.html) 210 for more information.</td> 211 </tr> 212 <tr> 213 <td>${NOMAD_ADDR_"label"}</td> 214 <td>The `ip:port` pair for the given port `label`. See 215 [here](/docs/jobspec/networking.html) for more information.</td> 216 </tr> 217 <tr> 218 <td>${NOMAD_HOST_PORT_"label"}</td> 219 <td>The port on the host if port forwarding is being used for the port 220 `label`. See [here](/docs/jobspec/networking.html#mapped_ports) for more 221 information.</td> 222 </tr> 223 <tr> 224 <td>${NOMAD_META_"key"}</td> 225 <td>The metadata value given by `key` on the task's metadata</td> 226 </tr> 227 <tr> 228 <td>${"env_key"}</td> 229 <td>Interpret an environment variable with key `env_key` set on the task.</td> 230 </tr> 231 </table> 232