Skip to content

Commit 9d75308

Browse files
aimeeuboruszak
andauthored
Docs: Add manage Nomad variables page (#27003)
* Add manage Nomad variables page * fix include name * fix links in background section * fix content check * Apply suggestion from @boruszak Co-authored-by: Jeff Boruszak <[email protected]> * Apply suggestion from @boruszak Co-authored-by: Jeff Boruszak <[email protected]> * Apply suggestion from @boruszak Co-authored-by: Jeff Boruszak <[email protected]> * Apply suggestion from @boruszak Co-authored-by: Jeff Boruszak <[email protected]> * Revert file name back to variables.mdx --------- Co-authored-by: Jeff Boruszak <[email protected]>
1 parent e1c576d commit 9d75308

File tree

16 files changed

+335
-173
lines changed

16 files changed

+335
-173
lines changed

website/content/commands/var/get.mdx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,7 @@ documentation for details.
3939

4040
## Examples
4141

42-
Retrieve the variable stored at path "secret/creds":
43-
44-
```shell-session
45-
$ nomad var get secret/creds
46-
Namespace = default
47-
Path = secret/creds
48-
Create Time = 2022-08-23T11:14:37-04:00
49-
Check Index = 116
50-
51-
Items
52-
passcode = my-long-passcode
53-
```
54-
55-
Return only the "passcode" item from the variable stored at "secret/creds":
56-
57-
```shell-session
58-
$ nomad var get -item=passcode secret/creds
59-
my-long-passcode
60-
```
42+
@include 'variables/get-example.mdx'
6143

6244
## General options
6345

website/content/commands/var/init.mdx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,4 @@ When no filename is supplied, a default filename of "spec.nv.hcl" or
2828

2929
## Examples
3030

31-
Create an example variable specification:
32-
33-
```shell-session
34-
$ nomad var init
35-
Example variable specification written to spec.nv.hcl
36-
```
31+
@include 'variables/init-example.mdx'

website/content/commands/var/list.mdx

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -52,88 +52,7 @@ documentation for details.
5252

5353
## Examples
5454

55-
List values under the key "nomad/jobs":
56-
57-
```shell-session
58-
$ nomad var list nomad/jobs
59-
Namespace Path Last Updated
60-
default nomad/jobs/example 2022-08-23T10:35:47-04:00
61-
default nomad/jobs/variable 2022-08-23T10:24:45-04:00
62-
default nomad/jobs/variable/www 2022-08-23T10:24:45-04:00
63-
default nomad/jobs/variable/www/nginx 2022-08-23T10:24:46-04:00
64-
```
65-
66-
List values under the key "nomad/jobs/variable/www" in JSON format:
67-
68-
```shell-session
69-
$ nomad var list -out=json -namespace="*" nomad/jobs/variable/www
70-
[
71-
{
72-
"Namespace": "default",
73-
"Path": "nomad/jobs/variable/www",
74-
"CreateIndex": 1457,
75-
"ModifyIndex": 1457,
76-
"CreateTime": 1662061225600373000,
77-
"ModifyTime": 1662061225600373000
78-
},
79-
{
80-
"Namespace": "default",
81-
"Path": "nomad/jobs/variable/www/nginx",
82-
"CreateIndex": 800,
83-
"ModifyIndex": 1000,
84-
"CreateTime": 1662061717905426000,
85-
"ModifyTime": 1662062162982630000
86-
}
87-
]
88-
```
89-
90-
Perform a paginated query:
91-
92-
```shell-session
93-
$ nomad var list -per-page=3
94-
Namespace Path Last Updated
95-
default nomad/jobs/example 2022-08-23T10:35:47-04:00
96-
default nomad/jobs/variable 2022-08-23T10:24:45-04:00
97-
default nomad/jobs/variable/www 2022-08-23T10:24:45-04:00
98-
Next page token: default.nomad/jobs/variable/www/nginx
99-
```
100-
101-
To fetch the next page :
102-
103-
```shell-session
104-
$ nomad var list -per-page=3 \
105-
-page-token=default.nomad/jobs/variable/www/nginx
106-
Namespace Path Last Updated
107-
default nomad/jobs/variable/www/nginx 2022-08-23T10:24:46-04:00
108-
```
109-
110-
Perform a paginated query with JSON formatting:
111-
112-
```shell-session
113-
$ nomad var list -out=json -namespace="*" -per-page=1 nomad/jobs/variable/www
114-
{
115-
"Data": [
116-
{
117-
"Namespace": "default",
118-
"Path": "nomad/jobs/variable/www",
119-
"CreateIndex": 1457,
120-
"ModifyIndex": 1457,
121-
"CreateTime": 1662061225600373000,
122-
"ModifyTime": 1662061225600373000
123-
}
124-
],
125-
"QueryMeta": {
126-
"KnownLeader": true,
127-
"LastContact": 0,
128-
"LastIndex": 43,
129-
"NextToken": "default.nomad/jobs/variable/www/nginx",
130-
"RequestTime": 875792
131-
}
132-
}
133-
```
134-
135-
As with the tabular version, provide the `QueryMeta.NextToken` value as the
136-
`-page-token` value to fetch the next page.
55+
@include 'variables/list-example.mdx'
13756

13857
## General options
13958

website/content/commands/var/lock.mdx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,7 @@ taking the sum of the length in bytes of all of the unencrypted keys and values.
7474

7575
## Examples
7676

77-
Attempts to acquire a lock over the variable at path "secret/creds" for a time of
78-
15s and executes `nomad job run webapp.nomad.hcl` if it succeeds:
79-
80-
```shell-session
81-
$ nomad var lock -ttl=15s secret/creds "nomad job run webapp.nomad.hcl"
82-
```
83-
84-
The data can also be consumed from a file on disk by prefixing with the "@"
85-
symbol. For example, you can store a variable using a specification created with
86-
the `nomad var init` command.
87-
88-
```shell-session
89-
$ nomad var lock secret/foo @spec.nv.json `nomad job run webapp.nomad.hcl`
90-
```
77+
@include 'variables/lock-example.mdx'
9178

9279
## General options
9380

website/content/commands/var/purge.mdx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ documentation for details.
3333

3434
## Examples
3535

36-
Purge the variable at the "secret/creds" path.
37-
38-
```shell-session
39-
$ nomad var purge -y secret/creds
40-
Successfully purged variable "secret/creds"!
41-
```
36+
@include 'variables/purge-example.mdx'
4237

4338
## General options
4439

website/content/commands/var/put.mdx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,7 @@ taking the sum of the length in bytes of all of the unencrypted keys and values.
8383

8484
## Examples
8585

86-
Writes the data to the path "secret/creds":
87-
88-
```shell-session
89-
$ nomad var put secret/creds passcode=my-long-passcode
90-
```
91-
92-
The data can also be consumed from a file on disk by prefixing with the "@"
93-
symbol. For example, you can store a variable using a specification created with
94-
the `nomad var init` command.
95-
96-
```shell-session
97-
$ nomad var put secret/foo @spec.nv.json
98-
```
99-
100-
Or it can be read from standard input using the "-" symbol:
101-
102-
```shell-session
103-
$ echo "abcd1234" | nomad var put secret/foo bar=-
104-
```
86+
@include 'variables/put-example.mdx'
10587

10688
## General options
10789

website/content/docs/concepts/variables.mdx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
---
22
layout: docs
3-
page_title: Nomad Variables
3+
page_title: Nomad variables
44
description: Nomad's variables feature lets you store and use encrypted configuration data in your job specifications. Learn how Access Control List (ACL) policies restrict access to variables within a namespace, how a job task's workload identity grants access to variables, and how locking a variable blocks access to that variable.
55
---
66

7-
# Nomad Variables
7+
# Nomad variables
88

99
This page contains conceptual information about the Nomad variables feature,
1010
which lets you store and use encrypted configuration data in your job
1111
specifications. Learn how Access Control List (ACL) policies restrict access to variables within a namespace, how a job task's workload identity grants access to variables, and how locking a variable blocks access to that variable.
1212

13-
Most Nomad workloads need access to config values or secrets. Nomad has a
14-
`template` block to [provide such configuration to tasks](/nomad/docs/job-specification/template#nomad-variables),
15-
but prior to Nomad 1.4 has left the role of storing that configuration to
16-
external services such as [HashiCorp Consul] and [HashiCorp Vault].
13+
## Introduction
1714

18-
Nomad variables provide the option to store configuration at file-like paths
19-
directly in Nomad's state store. [Access these variables](/nomad/docs/job-specification/template#nomad-variables) directly from
20-
your task templates. The contents of these variables are encrypted
21-
and replicated between servers via raft. Access to variables is controlled by
15+
Most Nomad workloads need access to configuration values or secrets. Nomad has a
16+
`template` block to [provide these values to
17+
tasks](/nomad/docs/job-specification/template#nomad-variables). Nomad variables
18+
provide the option to store configuration at file-like paths
19+
directly in Nomad's state store so that you can access these variables directly from
20+
your task templates. Nomad encrypts and replicates the contents of these variables between servers with Raft communication. Access to variables is controlled by
2221
ACL policies, and tasks have implicit ACL policies that allow them to access
2322
their own variables. You can create, read, update, or delete variables via the
2423
command line, the Nomad API, or in the Nomad web UI.
2524

2625
Note that the variables feature is intended for small pieces of configuration
2726
data needed by workloads. Because writing to the Nomad state store uses
2827
resources needed by Nomad, it is not well-suited for large or fast-changing
29-
data. For example, do not store batch job results as variables - these should be
28+
data. For example, do not store batch job results as variables. These should be
3029
stored in an external database. Variables are also not intended to be a full
3130
replacement for HashiCorp Vault. Unlike Vault, Nomad stores the root encryption
32-
key on the servers. See [Key Management][] for details.
31+
key on the servers. Refer to [Key Management][] for details.
3332

34-
## ACL for Variables
33+
## Policies
3534

3635
Every variable belongs to a specific Nomad namespace. ACL policies can restrict
3736
access to variables within a namespace on a per-path basis, using a list of
38-
`path` blocks, located under `namespace.variables`. See the [ACL policy
39-
specification] docs for details about the syntax and structure of an ACL policy.
37+
`path` blocks, located under `namespace.variables`. Refer to the [ACL policy
38+
specification] for details about the syntax and structure of an ACL policy.
4039

41-
Path definitions may also include wildcard symbols, also called globs, allowing
40+
Path definitions may also include a wildcard symbol that allows
4241
a single path policy definition to apply to a set of paths within that
43-
namespace. For example, the policy below allows full access to variables at all
44-
paths in the "dev" namespace that are prefixed with "project/" (including child
45-
paths) but only read access to paths prefixed with "system/". Note that the glob
42+
namespace.
43+
44+
In the following example, the policy allows full access to variables at all
45+
paths in the `dev` namespace that are prefixed with `project/`, including child
46+
paths, but only read access to paths prefixed with `system/`. Note that the wildcard
4647
can match an empty string and all other characters. This policy grants read
47-
access to paths prefixed with "system/" but not a path named "system" (without a
48+
access to paths prefixed with `system/` but not a path named `system` (without a
4849
trailing slash).
4950

5051
```hcl
@@ -76,7 +77,7 @@ The available capabilities for variables are as follows:
7677
| list | List the metadata but not contents of variables at this path. |
7778
| destroy | Delete variables at this path. |
7879

79-
## Task Access to Variables
80+
## Task access to variables
8081

8182
Tasks can access variables with the [`template`] block or using the [Task API].
8283
The [workload identity] for each task grants it automatic read and list access to
@@ -210,7 +211,7 @@ and no renew or release calls were made, the variable will remain locked for at
210211
least the lock delay duration, to avoid a possible split-brain situation, where
211212
there are two holders at the same time.
212213

213-
### Leader election backed by Nomad Variable Locks
214+
### Leader election backed by Nomad variable locks
214215

215216
For some applications, like HDFS or the Nomad Autoscaler, it is necessary to
216217
have multiple instances running to ensure redundancy in case of a failure, but
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
layout: docs
3+
page_title: Create and update Nomad variables
4+
description: |-
5+
Use the Nomad CLI or API to create, store, and update Nomad variables.
6+
---
7+
8+
# Create and update Nomad variables
9+
10+
This page describes the processes for interacting with Nomad variables. Use the
11+
[`nomad var` command reference](/nomad/commands/var) or the [Vars HTTP
12+
API](/nomad/api-docs/variables) to manage Nomad variables.
13+
14+
## Background
15+
16+
Nomad variables provide the option to securely store configuration at
17+
file-like paths directly in Nomad's state store. For complete documentation on
18+
the Nomad variables feature and related concepts, refer to the following:
19+
20+
- [Nomad variables concepts](/nomad/docs/concepts/variables)
21+
- [Nomad variable specification](/nomad/docs/other-specifications/variables)
22+
- [Key management](/nomad/docs/manage/key-management)
23+
- [Workload identity](/nomad/docs/concepts/workload-identity)
24+
25+
Nomad scopes a Nomad variable to a namespace and allows access to Nomad
26+
variables according to ACL policies.
27+
28+
## Generate a Nomad variable specification
29+
30+
Use the [`nomad var init` command](/nomad/commands/var/init) to generate a Nomad
31+
variable specification that you can customize.
32+
33+
@include 'variables/init-example.mdx'
34+
35+
## Add and update Nomad variables
36+
37+
Use the [`nomad var put` command](/nomad/commands/var/put) to create and update
38+
Nomad variables. Supply variable items by including a Nomad variable
39+
specification file, a series of key-value pairs, or both. Refer to the [`nomad
40+
var put` command reference](/nomad/commands/var/put) for details on formatting
41+
keys and values. Values that you supply as command line arguments supersede
42+
values provided in any variable specification piped into the command or loaded
43+
from file.
44+
45+
You may also use the `nomad var put` command to overwrite all items in a
46+
variable. To avoid conflicting with other writes that may have happened since
47+
you last read the variable, you must use the `-check-index` flag and set it to
48+
the last modified index.
49+
50+
@include 'variables/put-example.mdx'
51+
52+
## Delete Nomad variables
53+
54+
Use the [`nomad var purge` command](/nomad/commands/var/purge) to permanently
55+
delete an existing variable.
56+
57+
@include 'variables/purge-example.mdx'
58+
59+
## Query Nomad variables
60+
61+
### Get
62+
63+
Use the [`nomad var get` command](/nomad/commands/var/get) to fetch the contents of an existing variable.
64+
65+
@include 'variables/get-example.mdx'
66+
67+
### List
68+
69+
Use the [`nomad var list` command](/nomad/commands/var/list) to fetch a list of
70+
variable paths accessible to you.
71+
72+
@include 'variables/list-example.mdx'
73+
74+
## Lock access to a Nomad variable
75+
76+
The [`nomad var lock` command](/nomad/commands/var/lock) provides a mechanism
77+
for distributed locking. Nomad creates a lock in the given variable, and only
78+
when held, invokes the specified child process.
79+
80+
@include 'variables/lock-example.mdx'
81+
82+
## Next steps
83+
84+
Refer to the following Nomad variables tutorials for in-depth learning:
85+
86+
- [Create and update Nomad
87+
variables](/nomad/tutorials/variables/variables-create) contains advanced
88+
examples for updating Nomad variables.
89+
- [Configure access control for Nomad
90+
variables](/nomad/tutorials/variables/variables-acls) shows how to configure
91+
ACL policies for Nomad variables.
92+
93+
To learn how to access Nomad variables in your job specification, refer to [Use Nomad variables in tasks](/nomad/docs/job-declare/nomad-variables).

website/content/docs/other-specifications/variables.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ description: |-
99

1010
[Nomad variables][nv] let you store and use encrypted configuration data in your
1111
job specifications. Specify variables as HCL files and submit them with the
12-
[`nomad var put` command][var-put. Unlike [job specifications][jobspecs], Nomad
13-
Variables specifications do not support HCL2 features like functions.
12+
[`nomad var put` command][var-put]. Unlike [job specifications][jobspecs], Nomad
13+
variables specifications do not support HCL2 features like functions.
1414

1515
This example is a variable specification generated by [`nomad var init` command][var-init].
1616

@@ -59,8 +59,7 @@ $ nomad var put -in hcl some/path @spec.nv.hcl
5959
- `items` `(object: <required>)` - Object of keys and values to set. Must be
6060
strings.
6161

62-
Refer to the [Restrictions section][var-restrict] in the command reference for
63-
details on `path` and `items` name restrictions.
62+
Refer to the [`nomad var put` restrictions section][var-restrict] for details on `path` and `items` name restrictions.
6463

6564
## Resources
6665

0 commit comments

Comments
 (0)