github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/website/source/docs/job-specification/job.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "job Stanza - Job Specification" 4 sidebar_current: "docs-job-specification-job" 5 description: |- 6 The "job" stanza is the top-most configuration option in the job 7 specification. A job is a declarative specification of tasks that Nomad 8 should run. 9 --- 10 11 # `job` Stanza 12 13 <table class="table table-bordered table-striped"> 14 <tr> 15 <th width="120">Placement</th> 16 <td> 17 <code>**job**</code> 18 </td> 19 </tr> 20 </table> 21 22 The `job` stanza is the top-most configuration option in the job specification. 23 A job is a declarative specification of tasks that Nomad should run. Jobs have a 24 globally unique name, one or many task groups, which are themselves collections 25 of one or many tasks. 26 27 ```hcl 28 job "docs" { 29 all_at_once = true 30 31 constraint { 32 # ... 33 } 34 35 datacenters = ["us-east-1"] 36 37 group "example" { 38 # ... 39 } 40 41 meta { 42 "my-key" = "my-value" 43 } 44 45 parameterized { 46 # ... 47 } 48 49 periodic { 50 # ... 51 } 52 53 priority = 100 54 55 region = "north-america" 56 57 task "docs" { 58 # ... 59 } 60 61 update { 62 # ... 63 } 64 } 65 ``` 66 67 ## `job` Parameters 68 69 - `all_at_once` `(bool: false)` - Controls if the entire set of tasks in the job 70 must be placed atomically or if they can be scheduled incrementally. This 71 should only be used for special circumstances. 72 73 - `constraint` <code>([Constraint][constraint]: nil)</code> - 74 This can be provided multiple times to define additional constraints. See the 75 [Nomad constraint reference](/docs/job-specification/constraint.html) for more 76 details. 77 78 - `datacenters` `(array<string>: <required>)` - A list of datacenters in the region which are eligible 79 for task placement. This must be provided, and does not have a default. 80 81 - `group` <code>([Group][group]: \<required\>)</code> - Specifies the start of a 82 group of tasks. This can be provided multiple times to define additional 83 groups. Group names must be unique within the job file. 84 85 - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates 86 with user-defined metadata. 87 88 - `parameterized` <code>([Parameterized][parameterized]: nil)</code> - Specifies 89 the job as a paramterized job such that it can be dispatched against. 90 91 - `periodic` <code>([Periodic][]: nil)</code> - Allows the job to be scheduled 92 at fixed times, dates or intervals. 93 94 - `priority` `(int: 50)` - Specifies the job priority which is used to 95 prioritize scheduling and access to resources. Must be between 1 and 100 96 inclusively, with a larger value corresponding to a higher priority. 97 98 - `region` `(string: "global")` - The region in which to execute the job. 99 100 - `type` `(string: "service")` - Specifies the [Nomad scheduler][scheduler] to 101 use. Nomad provides the `service`, `system` and `batch` schedulers. 102 103 - `update` <code>([Update][update]: nil)</code> - Specifies the task's update 104 strategy. When omitted, rolling updates are disabled. 105 106 - `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies 107 required by all tasks in this job. 108 109 - `vault_token` `(string: "")` - Specifies the Vault token that proves the 110 submitter of the job has access to the specified policies in the 111 [`vault`][vault] stanza. This field is only used to transfer the token and is 112 not stored after job submission. 113 114 !> It is **strongly discouraged** to place the token as a configuration 115 parameter like this, since the token could be checked into source control 116 accidentally. Users should set the `VAULT_TOKEN` environment variable when 117 running the job instead. 118 119 ## `job` Examples 120 121 The following examples only show the `job` stanzas. Remember that the 122 `job` stanza is only valid in the placements listed above. 123 124 ### Docker Container 125 126 This example job starts a Docker container which runs as a service. Even though 127 the type is not specified as "service", that is the default job type. 128 129 ```hcl 130 job "docs" { 131 datacenters = ["default"] 132 133 group "example" { 134 task "server" { 135 driver = "docker" 136 config { 137 image = "hashicorp/http-echo" 138 args = ["-text", "hello"] 139 } 140 141 resources { 142 memory = 128 143 } 144 } 145 } 146 } 147 ``` 148 149 ### Batch Job 150 151 This example job executes the `uptime` command across all Nomad clients in the 152 fleet, as long as those machines are running Linux. 153 154 ```hcl 155 job "docs" { 156 datacenters = ["default"] 157 158 type = "batch" 159 160 constraint { 161 attribute = "${attr.kernel.name}" 162 value = "linux" 163 } 164 165 group "example" { 166 task "uptime" { 167 driver = "exec" 168 config { 169 command = "uptime" 170 } 171 172 resources { 173 cpu = 20 174 } 175 } 176 } 177 } 178 ``` 179 180 ### Consuming Secrets 181 182 This example shows a job which retrieves secrets from Vault and writes those 183 secrets to a file on disk, which the application then consumes. Nomad handles 184 all interactions with Vault. 185 186 ```hcl 187 job "docs" { 188 datacenters = ["default"] 189 190 group "example" { 191 task "cat" { 192 driver = "exec" 193 194 config { 195 command = "cat" 196 args = ["local/secrets.txt"] 197 } 198 199 template { 200 data = "{{ secret \"secret/data\" }}" 201 destination = "local/secrets.txt" 202 } 203 204 vault { 205 policies = ["secret-readonly"] 206 } 207 208 resources { 209 cpu = 20 210 } 211 } 212 } 213 } 214 ``` 215 216 When submitting this job, you would run: 217 218 ``` 219 $ VAULT_TOKEN="..." nomad run example.nomad 220 ``` 221 222 [constraint]: /docs/job-specification/constraint.html "Nomad constraint Job Specification" 223 [group]: /docs/job-specification/group.html "Nomad group Job Specification" 224 [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification" 225 [parameterized]: /docs/job-specification/parameterized.html "Nomad parameterized Job Specification" 226 [periodic]: /docs/job-specification/periodic.html "Nomad periodic Job Specification" 227 [task]: /docs/job-specification/task.html "Nomad task Job Specification" 228 [update]: /docs/job-specification/update.html "Nomad update Job Specification" 229 [vault]: /docs/job-specification/vault.html "Nomad vault Job Specification" 230 [scheduler]: /docs/runtime/schedulers.html "Nomad Scheduler Types"