github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/commands/job/plan.mdx (about) 1 --- 2 layout: docs 3 page_title: 'Commands: job plan' 4 description: | 5 The job plan command is used to dry-run a job update to determine its effects. 6 --- 7 8 # Command: job plan 9 10 **Alias: `nomad plan`** 11 12 The `job plan` command can be used to invoke the scheduler in a dry-run mode 13 with new jobs or when updating existing jobs to determine what would happen if 14 the job is submitted. Job files must conform to the [job specification] format. 15 16 ## Usage 17 18 ```plaintext 19 nomad job plan [options] <path> 20 ``` 21 22 The `job plan` command requires a single argument, specifying the path to a file 23 containing an HCL [job specification]. This file will be read and the resulting 24 parsed job will be validated. If the supplied path is "-", the job file is read 25 from STDIN. Otherwise it is read from the file at the supplied path or 26 downloaded and read from URL specified. Nomad downloads the job file using 27 [`go-getter`] and supports `go-getter` syntax. 28 29 Plan invokes a dry-run of the scheduler to determine the effects of submitting 30 either a new or updated version of a job. The plan will not result in any 31 changes to the cluster but gives insight into whether the job could be run 32 successfully and how it would affect existing allocations. 33 34 A job modify index is returned with the plan. This value can be used when 35 submitting the job using [`nomad job run -check-index`], which will check that 36 the job was not modified between the plan and run command before invoking the 37 scheduler. This ensures the job has not been modified since the plan. 38 39 A structured diff between the local and remote job is displayed to 40 give insight into what the scheduler will attempt to do and why. 41 42 If the job has specified the region, the `-region` flag and `NOMAD_REGION` 43 environment variable are overridden and the job's region is used. 44 45 Plan will return one of the following exit codes: 46 47 - 0: No allocations created or destroyed. 48 - 1: Allocations created or destroyed. 49 - 255: Error determining plan results. 50 51 The plan command will set the `vault_token` of the job based on the following 52 precedence, going from highest to lowest: the `-vault-token` flag, the 53 `$VAULT_TOKEN` environment variable and finally the value in the job file. 54 55 When ACLs are enabled, this command requires a token with the `submit-job` 56 capability for the job's namespace. 57 58 ## General Options 59 60 @include 'general_options.mdx' 61 62 ## Plan Options 63 64 - `-diff`: Determines whether the diff between the remote job and planned job is 65 shown. Defaults to true. 66 67 - `-policy-override`: Sets the flag to force override any soft mandatory 68 Sentinel policies. 69 70 - `-json`: Parses the job file as JSON. If the outer object has a Job field, 71 such as from "nomad job inspect" or "nomad run -output", the value of the 72 field is used as the job. 73 74 - `-hcl1`: If set, HCL1 parser is used for parsing the job spec. Takes 75 precedence over `-hcl2-strict`. 76 77 - `-hcl2-strict`: Whether an error should be produced from the HCL2 parser where 78 a variable has been supplied which is not defined within the root variables. 79 Defaults to true, but ignored if `-hcl1` is defined. 80 81 - `-vault-token`: Used to validate if the user submitting the job has 82 permission to run the job according to its Vault policies. A Vault token must 83 be supplied if the [`vault` stanza `allow_unauthenticated`] is disabled in 84 the Nomad server configuration. If the `-vault-token` flag is set, the passed 85 Vault token is added to the jobspec before sending to the Nomad servers. This 86 allows passing the Vault token without storing it in the job file. This 87 overrides the token found in the `$VAULT_TOKEN` environment variable and the 88 [`vault_token`] field in the job file. This token is cleared from the job 89 after planning and cannot be used within the job executing environment. Use 90 the `vault` stanza when templating in a job with a Vault token. 91 92 - `-vault-namespace`: If set, the passed Vault namespace is stored in the job 93 before sending to the Nomad servers. 94 95 - `-var=<key=value>`: Variable for template, can be used multiple times. 96 97 - `-var-file=<path>`: Path to HCL2 file containing user variables. 98 99 - `-verbose`: Increase diff verbosity. 100 101 ## Examples 102 103 Plan a new job that has not been previously submitted: 104 105 ```shell-session 106 $ nomad job plan job1.nomad 107 nomad job plan example.nomad 108 + Job: "example" 109 + Task Group: "cache" (1 create) 110 + Task: "redis" (forces create) 111 112 Scheduler dry-run: 113 - All tasks successfully allocated. 114 115 Job Modify Index: 0 116 To submit the job with version verification run: 117 118 nomad job run -check-index 0 example.nomad 119 120 When running the job with the check-index flag, the job will only be run if the 121 job modify index given matches the server-side version. If the index has 122 changed, another user has modified the job and the plan's results are 123 potentially invalid. 124 ``` 125 126 Increase the count of an existing without sufficient cluster capacity: 127 128 ```shell-session 129 $ nomad job plan example.nomad 130 +/- Job: "example" 131 +/- Task Group: "cache" (7 create, 1 in-place update) 132 +/- Count: "1" => "8" (forces create) 133 Task: "redis" 134 135 Scheduler dry-run: 136 - WARNING: Failed to place all allocations. 137 Task Group "cache" (failed to place 3 allocations): 138 * Resources exhausted on 1 nodes 139 * Dimension "cpu" exhausted on 1 nodes 140 141 Job Modify Index: 15 142 To submit the job with version verification run: 143 144 nomad job run -check-index 15 example.nomad 145 146 When running the job with the check-index flag, the job will only be run if the 147 job modify index given matches the server-side version. If the index has 148 changed, another user has modified the job and the plan's results are 149 potentially invalid. 150 ``` 151 152 Update an existing job such that it would cause a rolling update: 153 154 ```shell-session 155 $ nomad job plan example.nomad 156 +/- Job: "example" 157 +/- Task Group: "cache" (3 create/destroy update) 158 +/- Task: "redis" (forces create/destroy update) 159 +/- Config { 160 +/- image: "redis:2.8" => "redis:7" 161 port_map[0][db]: "6379" 162 } 163 164 Scheduler dry-run: 165 - All tasks successfully allocated. 166 - Rolling update, next evaluation will be in 10s. 167 168 Job Modify Index: 7 169 To submit the job with version verification run: 170 171 nomad job run -check-index 7 example.nomad 172 173 When running the job with the check-index flag, the job will only be run if the 174 job modify index given matches the server-side version. If the index has 175 changed, another user has modified the job and the plan's results are 176 potentially invalid. 177 ``` 178 179 Add a task to the task group using verbose mode: 180 181 ```shell-session 182 $ nomad job plan -verbose example.nomad 183 +/- Job: "example" 184 +/- Task Group: "cache" (3 create/destroy update) 185 + Task: "my-website" (forces create/destroy update) 186 + Driver: "docker" 187 + KillTimeout: "5000000000" 188 + Config { 189 + image: "node:6.2" 190 + port_map[0][web]: "80" 191 } 192 + Resources { 193 + CPU: "500" 194 + DiskMB: "300" 195 + MemoryMB: "256" 196 + Network { 197 + MBits: "10" 198 + Dynamic Port { 199 + Label: "web" 200 } 201 } 202 } 203 + LogConfig { 204 + MaxFileSizeMB: "10" 205 + MaxFiles: "10" 206 } 207 + Service { 208 + Name: "website" 209 + PortLabel: "web" 210 + Check { 211 Command: "" 212 + Interval: "10000000000" 213 + Name: "alive" 214 Path: "" 215 Protocol: "" 216 + Timeout: "2000000000" 217 + Type: "tcp" 218 } 219 } 220 Task: "redis" 221 222 Scheduler dry-run: 223 - All tasks successfully allocated. 224 - Rolling update, next evaluation will be in 10s. 225 226 Job Modify Index: 7 227 To submit the job with version verification run: 228 229 nomad job run -check-index 7 example.nomad 230 231 When running the job with the check-index flag, the job will only be run if the 232 job modify index given matches the server-side version. If the index has 233 changed, another user has modified the job and the plan's results are 234 potentially invalid. 235 ``` 236 237 When using the `nomad job plan` command in automated environments, such as 238 in CI/CD pipelines, it is useful to output the plan result for manual 239 validation and also store the check index on disk so it can be used later to 240 guarantee that a job deployment will match the expected changes described in 241 the plan result. 242 243 This can be done by parsing the command output and redirecting the index to a 244 file. For example, in Linux environments the [`tee`] command can be used for 245 this purpose: 246 247 ```console 248 $ nomad job plan -no-color example.nomad | tee /dev/stderr | grep 'Job Modify Index:' | awk -F': ' '{ print $2 }' > check-index || true 249 ``` 250 251 The [`-no-color`](#no-color) flag prevents style characters from impacting 252 parsing. Colored output may be helpful when analyzing the plan result, so the 253 [`-force-color`](#force-color) flag can be used. This will affect how parsing 254 is done to avoid hidden control characters. Adding `|| true` at the end 255 prevents undesired failures since `nomad job plan` returns a non-zero exit code 256 if a change is detected. 257 258 [job specification]: /docs/job-specification 259 [hcl job specification]: /docs/job-specification 260 [`go-getter`]: https://github.com/hashicorp/go-getter 261 [`nomad job run -check-index`]: /docs/commands/job/run#check-index 262 [`tee`]: https://man7.org/linux/man-pages/man1/tee.1.html 263 [`vault` stanza `allow_unauthenticated`]: /docs/configuration/vault#allow_unauthenticated 264 [`vault_token`]: /docs/job-specification/job#vault_token