github.com/ranjib/nomad@v0.1.1-0.20160225204057-97751b02f70b/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 </tr> 69 <tr> 70 <td>${node.unique.id}</td> 71 <td>The client node identifier</td> 72 </tr> 73 <tr> 74 <td>${node.datacenter}</td> 75 <td>The client node datacenter</td> 76 </tr> 77 <tr> 78 <td>${node.unique.name}</td> 79 <td>The client node name</td> 80 </tr> 81 <tr> 82 <td>${node.class}</td> 83 <td>The client node class</td> 84 </tr> 85 <tr> 86 <td>${attr.\<key\}></td> 87 <td>The attribute given by `key` on the client node.</td> 88 </tr> 89 <tr> 90 <td>${meta.\<key\>}</td> 91 <td>The metadata value given by `key` on the client node.</td> 92 </tr> 93 </table> 94 95 Below is a table documenting common node attributes: 96 97 <table class="table table-bordered table-striped"> 98 <tr> 99 <th>Attribute</th> 100 <th>Description</th> 101 </tr> 102 <tr> 103 <td>arch</td> 104 <td>CPU architecture of the client. Examples: `amd64`, `386`</td> 105 </tr> 106 <tr> 107 <td>consul.datacenter</td> 108 <td>The Consul datacenter of the client node if Consul found</td> 109 </tr> 110 <tr> 111 <td>cpu.numcores</td> 112 <td>Number of CPU cores on the client</td> 113 </tr> 114 <tr> 115 <td>driver.\<key\></td> 116 <td>See the [task drivers](/docs/drivers/index.html) for attribute documentation</td> 117 </tr> 118 <tr> 119 <td>hostname</td> 120 <td>Hostname of the client</td> 121 </tr> 122 <tr> 123 <td>kernel.name</td> 124 <td>Kernel of the client. Examples: `linux`, `darwin`</td> 125 </tr> 126 <tr> 127 <td>kernel.version</td> 128 <td>Version of the client kernel. Examples: `3.19.0-25-generic`, `15.0.0`</td> 129 </tr> 130 <tr> 131 <td>platform.aws.ami-id</td> 132 <td>On EC2, the AMI ID of the client node</td> 133 </tr> 134 <tr> 135 <td>platform.aws.instance-type</td> 136 <td>On EC2, the instance type of the client node</td> 137 </tr> 138 <tr> 139 <td>os.name</td> 140 <td>Operating system of the client. Examples: `ubuntu`, `windows`, `darwin`</td> 141 </tr> 142 <tr> 143 <td>os.version</td> 144 <td>Version of the client OS</td> 145 </tr> 146 </table> 147 148 ## Environment Variables <a id="interpreted_env_vars"></a> 149 150 The following are runtime environment variables that describe the environment 151 the task is running in. These are only defined once the task has been placed on 152 a particular node and as such can not be used in constraints. 153 154 <table class="table table-bordered table-striped"> 155 <tr> 156 <th>Variable</th> 157 <th>Description</th> 158 </tr> 159 <tr> 160 <td>${NOMAD_ALLOC_DIR}</td> 161 <td>The path to the shared `alloc/` directory. See 162 [here](/docs/jobspec/environment.html#task_dir) for more 163 information.</td> 164 </tr> 165 <tr> 166 <td>${NOMAD_TASK_DIR}</td> 167 <td>The path to the task `local/` directory. See 168 [here](/docs/jobspec/environment.html#task_dir) for more 169 information.</td> 170 </tr> 171 <tr> 172 <td>${NOMAD_MEMORY_LIMIT}</td> 173 <td>The memory limit in MBits for the task</td> 174 </tr> 175 <tr> 176 <td>${NOMAD_CPU_LIMIT}</td> 177 <td>The CPU limit in MHz for the task</td> 178 </tr> 179 <tr> 180 <td>${NOMAD_ADDR_"label"}></td> 181 <td>The `ip:port` pair for the given port `label`. See 182 [here](/docs/jobspec/networking.html) for more information.</td> 183 </tr> 184 <tr> 185 <td>${NOMAD_HOST_PORT_"label"}</td> 186 <td>The port on the host if port forwarding is being used for the port 187 `label`. See [here](/docs/jobspec/networking.html#mapped_ports) for more 188 information.</td> 189 </tr> 190 <tr> 191 <td>${NOMAD_META_"key"}</td> 192 <td>The metadata value given by `key` on the task's metadata</td> 193 </tr> 194 <tr> 195 <td>${"env_key"}</td> 196 <td>Interpret an environment variable with key `env_key` set on the task.</td> 197 </tr> 198 </table> 199