diff --git a/website/content/docs/commands/job/allocs.mdx b/website/content/docs/commands/job/allocs.mdx new file mode 100644 index 00000000000..97c73f20c37 --- /dev/null +++ b/website/content/docs/commands/job/allocs.mdx @@ -0,0 +1,73 @@ +--- +layout: docs +page_title: 'Commands: job allocs' +description: | + The allocs command is used to list allocations for a job. +--- + +# Command: job allocs + +The `job allocs` command is used to display the allocations for a +particular job. + +## Usage + +```plaintext +nomad job allocs [options] +``` + +The `job allocs` command requires a single argument, the job ID or an ID +prefix of a job to display the list of allocations for. + +When ACLs are enabled, this command requires a token with the `read-job` and +`list-jobs` capabilities for the job's namespace. + +## General Options + +@include 'general_options.mdx' + +## Deployment Options + +- `-json` : Output the allocations in JSON format. + +- `-t` : Format and display the allocations using a Go template. + +- `-verbose`: Show full information. + +- `-all`: Display all allocations matching the job ID, even those from an + older instance of the job. + +## Examples + +List the allocations for a particular job: + +```shell-session +$ nomad job allocs example +ID Node ID Task Group Version Desired Status Created Modified +c2b4606d 35085106 cache 2 run running 21s ago 10s ago +c413424b 35085106 cache 2 run pending 1m8s ago 11s ago +``` + +Verbose listing of allocations for a particular job: + +```shell-session +$ nomad job allocs -verbose example +ID Eval ID Node ID Node Name Task Group Version Desired Status Created Modified +c2b4606d-1b02-0d8d-5fdd-031167cd4c91 5e2badb6-b7cf-5177-8281-8fe14f7193d2 35085106-9480-b465-a348-deb745024394 ubuntu cache 2 run running 2021-09-23T14:45:09-04:00 2021-09-23T14:45:19-04:00 +c413424b-d80e-9bc6-ea92-a02b336eaaf5 5e2badb6-b7cf-5177-8281-8fe14f7193d2 35085106-9480-b465-a348-deb745024394 ubuntu cache 2 run pending 2021-09-23T14:44:22-04:00 2021-09-23T14:45:19-04:00 +``` + +Format job allocations using a Go template: +```shell-session +$ nomad job allocs -t '{{ range . }}{{ println .ID }}{{ end }}' example +c2b4606d-1b02-0d8d-5fdd-031167cd4c91 +c413424b-d80e-9bc6-ea92-a02b336eaaf5 +``` + +Use a Go template to filter only allocations which are running +```shell-session +$ nomad job allocs -t '{{ range . }}{{ if eq .ClientStatus "running" }}{{ println .ID }}{{ end }}{{ end }}' example +c2b4606d-1b02-0d8d-5fdd-031167cd4c91 +``` + +Refer to the [Format Nomad Command Output With Templates](https://learn.hashicorp.com/tutorials/nomad/format-output-with-templates)] tutorial for more examples of using Go templates to format Nomad CLI output.