open-nomad/website/content/docs/commands/job/allocs.mdx
Luiz Aoqui 1aceff7806
cli: remove hard requirement on list-jobs (#16380)
Most job subcommands allow for job ID prefix match as a convenience
functionality so users don't have to type the full job ID.

But this introduces a hard ACL requirement that the token used to run
these commands have the `list-jobs` permission, even if the token has
enough permission to execute the basic command action and the user
passed an exact job ID.

This change softens this requirement by not failing the prefix match in
case the request results in a permission denied error and instead using
the information passed by the user directly.
2023-03-09 15:00:04 -05:00

78 lines
2.7 KiB
Plaintext

---
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] <job>
```
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`
capability for the job's namespace. The `list-jobs` capability is required to
run the command with a job prefix instead of the exact job ID.
## General Options
@include 'general_options.mdx'
## Allocs Options
- `-all`: Display all allocations matching the job ID, even those from an
older instance of the job.
- `-json`: Output the allocations in JSON format.
- `-t`: Format and display the allocations using a Go template.
- `-verbose`: Show full information.
## 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][format_tutorial]
tutorial for more examples of using Go templates to format Nomad CLI output.
[format_tutorial]: /nomad/tutorials/templates/format-output-with-templates